Last active
April 1, 2023 10:02
-
-
Save kuredev/01acc8aebf8efb5b12caa62db50502b2 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
def toribonatti(number) | |
i1 = 0 | |
i2 = 0 | |
i3 = 1 | |
result = [] | |
result << i1 | |
result << i2 | |
result << i3 | |
number.times do | |
i4 = i1 + i2 + i3 | |
result << i4 | |
i1 = i2 | |
i2 = i3 | |
i3 = i4 | |
end | |
result | |
end | |
pp toribonatti(10) # [0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment