Skip to content

Instantly share code, notes, and snippets.

@kuredev
Last active April 1, 2023 10:02
Show Gist options
  • Save kuredev/01acc8aebf8efb5b12caa62db50502b2 to your computer and use it in GitHub Desktop.
Save kuredev/01acc8aebf8efb5b12caa62db50502b2 to your computer and use it in GitHub Desktop.
トリボナッチ数列
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