Created
October 17, 2012 02:32
-
-
Save bil-bas/3903400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List all values in fibonacci series <= n | |
def fib_up_to(n) | |
return [] if n < 0 # Idiot-proofing. | |
vals, succ = [0], 1 | |
while succ <= n | |
vals << succ | |
succ = vals[-1] + vals[-2] | |
end | |
vals | |
end | |
(-1..25).each do |i| | |
puts "#{i}: #{fib_up_to i}" | |
end | |
=begin | |
-1: [] | |
0: [0] | |
1: [0, 1, 1] | |
2: [0, 1, 1, 2] | |
3: [0, 1, 1, 2, 3] | |
4: [0, 1, 1, 2, 3] | |
5: [0, 1, 1, 2, 3, 5] | |
6: [0, 1, 1, 2, 3, 5] | |
7: [0, 1, 1, 2, 3, 5] | |
8: [0, 1, 1, 2, 3, 5, 8] | |
9: [0, 1, 1, 2, 3, 5, 8] | |
10: [0, 1, 1, 2, 3, 5, 8] | |
11: [0, 1, 1, 2, 3, 5, 8] | |
12: [0, 1, 1, 2, 3, 5, 8] | |
13: [0, 1, 1, 2, 3, 5, 8, 13] | |
14: [0, 1, 1, 2, 3, 5, 8, 13] | |
15: [0, 1, 1, 2, 3, 5, 8, 13] | |
16: [0, 1, 1, 2, 3, 5, 8, 13] | |
17: [0, 1, 1, 2, 3, 5, 8, 13] | |
18: [0, 1, 1, 2, 3, 5, 8, 13] | |
19: [0, 1, 1, 2, 3, 5, 8, 13] | |
20: [0, 1, 1, 2, 3, 5, 8, 13] | |
21: [0, 1, 1, 2, 3, 5, 8, 13, 21] | |
22: [0, 1, 1, 2, 3, 5, 8, 13, 21] | |
23: [0, 1, 1, 2, 3, 5, 8, 13, 21] | |
24: [0, 1, 1, 2, 3, 5, 8, 13, 21] | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment