September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,12 +0,0 @@
(let ((cc (make-array 3 :element-type 'integer
:initial-element 1
:adjustable t
:fill-pointer 3)))
(defun q (n)
(when (>= n (length cc))
(loop for i from (length cc) below n do (q i))
(vector-push-extend
(+ (aref cc (- n (aref cc (- n 1))))
(aref cc (- n (aref cc (- n 2)))))
cc))
(aref cc n)))

View file

@ -0,0 +1,13 @@
// version 1.1.4
fun main(args: Array<String>) {
val q = IntArray(100_001)
q[1] = 1
q[2] = 1
for (n in 3..100_000) q[n] = q[n - q[n - 1]] + q[n - q[n - 2]]
print("The first 10 terms are : ")
for (i in 1..10) print("${q[i]} ")
println("\n\nThe 1000th term is : ${q[1000]}")
val flips = (2..100_000).count { q[it] < q[it - 1] }
println("\nThe number of flips for the first 100,000 terms is : $flips")
}

View file

@ -1,47 +0,0 @@
(define qc '#(0 1 1))
(define filled 3)
(define len 3)
;; chicken scheme: vector-resize!
;; gambit: vector-append
(define (extend-qc)
(let* ((new-len (* 2 len))
(new-qc (make-vector new-len)))
(let copy ((n 0))
(if (< n len)
(begin
(vector-set! new-qc n (vector-ref qc n))
(copy (+ 1 n)))))
(set! len new-len)
(set! qc new-qc)))
(define (q n)
(let loop ()
(if (>= filled len) (extend-qc))
(if (>= n filled)
(begin
(vector-set! qc filled (+ (q (- filled (q (- filled 1))))
(q (- filled (q (- filled 2))))))
(set! filled (+ 1 filled))
(loop))
(vector-ref qc n))))
(display "Q(1 .. 10): ")
(let loop ((i 1))
;; (print) behave differently regarding newline across compilers
(display (q i))
(display " ")
(if (< i 10)
(loop (+ 1 i))
(newline)))
(display "Q(1000): ")
(display (q 1000))
(newline)
(display "bumps up to 100000: ")
(display
(let loop ((s 0) (i 1))
(if (>= i 100000) s
(loop (+ s (if (> (q i) (q (+ 1 i))) 1 0)) (+ 1 i)))))
(newline)

View file

@ -1,3 +0,0 @@
Q(1 .. 10): 1 1 2 3 3 4 5 5 6 6
Q(1000): 502
bumps up to 100000: 49798

View file

@ -1,8 +1,8 @@
func Q(n) is cached {
n <= 2 ? 1
: Q(n - Q(n-1))+Q(n-Q(n-2))
n <= 2 ? 1
 : Q(n - Q(n-1))+Q(n-Q(n-2))
}
say "First 10 terms: #{10.of {|n| Q(n) }.dump }"
 
say "First 10 terms: #{ {|n| Q(n) }.map(1..10) }"
say "Term 1000: #{Q(1000)}"
say "Terms less than preceding in first 100k: #{2..100000->count{|i|Q(i)<Q(i-1)}}"

View file

@ -1,8 +1,8 @@
var Q = [0, 1, 1];
var Q = [0, 1, 1]
100_000.times {
Q << (Q[-Q[-1]] + Q[-Q[-2]])
}
say "First 10 terms: #{Q.ft(1, 10).dump}"
 
say "First 10 terms: #{Q.ft(1, 10)}"
say "Term 1000: #{Q[1000]}"
say "Terms less than preceding in first 100k: #{2..100000->count{|i|Q[i]<Q[i-1]}}"

View file

@ -0,0 +1,12 @@
const n = 0d100_000;
q:=(n+1).pump(List.createLong(n+1).write); // (0,1,2,...,n) base 1
q[1] = q[2] = 1;
foreach i in ([3..n]) { q[i] = q[i - q[i - 1]] + q[i - q[i - 2]] }
q[1,10].concat(" ").println();
println(q[1000]);
flip := 0;
foreach i in (n){ flip += (q[i] > q[i + 1]) }
println("flips: ",flip);