June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,9 +1,13 @@
function Q(n)
N = maximum(n)
q = Array(Int, N)
q[1], q[2] = 1, 1
for i = 3:N
q[i] = q[i - q[i-1]] + q[i - q[i-2]]
end
return q[n]
function hofstQseq(n, typerst::Type=Int)
nmax = maximum(n)
r = Vector{typerst}(nmax)
r[1] = 1
if nmax ≥ 2 r[2] = 1 end
for i in 3:nmax
r[i] = r[i - r[i - 1]] + r[i - r[i - 2]]
end
return r[n]
end
println("First ten elements of sequence: ", join(hofstQseq(1:10), ", "))
println("1000-th element: ", hofstQseq(1000))

View file

@ -1,15 +1,3 @@
julia> Q(1:10)
10-element Array{Int64,1}:
1
1
2
3
3
4
5
5
6
6
julia> Q(1000)
502
seq = hofstQseq(1:100_000)
cnt = count(diff(seq) .< 0)
println("$cnt elements are less than the preceding one.")