Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Hofstadter-Q-sequence/CLU/hofstadter-q-sequence.clu
Normal file
26
Task/Hofstadter-Q-sequence/CLU/hofstadter-q-sequence.clu
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
q_seq = proc (n: int) returns (sequence[int])
|
||||
q: array[int] := array[int]$[1,1]
|
||||
for i: int in int$from_to(3,n) do
|
||||
array[int]$addh(q, q[i-q[i-1]] + q[i-q[i-2]])
|
||||
end
|
||||
return(sequence[int]$a2s(q))
|
||||
end q_seq
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
q: sequence[int] := q_seq(100000)
|
||||
stream$puts(po, "First 10 terms:")
|
||||
for i: int in int$from_to(1,10) do
|
||||
stream$puts(po, " " || int$unparse(q[i]))
|
||||
end
|
||||
|
||||
stream$puts(po, "\n1000th term: " || int$unparse(q[1000]))
|
||||
|
||||
flips: int := 0
|
||||
for i: int in int$from_to(2, sequence[int]$size(q)) do
|
||||
if q[i-1]>q[i] then flips := flips + 1 end
|
||||
end
|
||||
|
||||
stream$putl(po, "\nflips: " || int$unparse(flips))
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue