Created
November 24, 2016 00:33
-
-
Save PandaWhisperer/cd5bf1ad50f8dcc886b89c1b16ea8b94 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 john(n) | |
john_and_ann(n)[:john] | |
end | |
def ann(n) | |
john_and_ann(n)[:ann] | |
end | |
def sum_john(n) | |
john(n).reduce(:+) | |
end | |
def sum_ann(n) | |
ann(n).reduce(:+) | |
end | |
def john_and_ann(n) | |
katas = { john: [0], ann: [1] } | |
for k in 1...n | |
katas[:john] << k - katas[:ann][katas[:john][k-1]] | |
katas[:ann] << k - katas[:john][katas[:ann][k-1]] | |
end | |
katas | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment