RosettaCodeData/Task/Hofstadter-Q-sequence/Sidef/hofstadter-q-sequence-2.sidef
2017-09-25 22:28:19 +02:00

8 lines
220 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var Q = [0, 1, 1]
100_000.times {
Q << (Q[-Q[-1]] + Q[-Q[-2]])
}
 
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]}}"