RosettaCodeData/Task/Hofstadter-Q-sequence/Sidef/hofstadter-q-sequence-1.sidef
2023-07-01 13:44:08 -04:00

8 lines
244 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.

func Q(n) is cached {
n <= 2 ? 1
 : Q(n - Q(n-1))+Q(n-Q(n-2))
}
 
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)}}"