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.")

View file

@ -6,3 +6,14 @@ class Hofstadter {
return @!c[$i];
}
}
# Testing:
my Hofstadter $Q .= new();
say "first ten: $Q[^10]";
say "1000th: $Q[999]";
my $count = 0;
$count++ if $Q[$_ +1 ] < $Q[$_] for ^99_999;
say "In the first 100_000 terms, $count terms are less than their preceding terms";

View file

@ -1,8 +1,12 @@
my Hofstadter $Q .= new();
my @Q = 1, 1, -> $a, $b {
(state $n = 1)++;
@Q[$n - $a] + @Q[$n - $b]
} ... *;
say "first ten: $Q[^10]";
say "1000th: $Q[999]";
# Testing:
my $count = 0;
$count++ if $Q[$_ +1 ] < $Q[$_] for ^99_999;
say "In the first 100_000 terms, $count terms are less than their preceding terms";
say "first ten: ", @Q[^10];
say "1000th: ", @Q[999];
say "In the first 100_000 terms, ",
[+](@Q[1..100000] Z< @Q[0..99999]),
" terms are less than their preceding terms";