Skip to content

Instantly share code, notes, and snippets.

@PandaWhisperer
Created November 24, 2016 00:33
Show Gist options
  • Save PandaWhisperer/cd5bf1ad50f8dcc886b89c1b16ea8b94 to your computer and use it in GitHub Desktop.
Save PandaWhisperer/cd5bf1ad50f8dcc886b89c1b16ea8b94 to your computer and use it in GitHub Desktop.
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