Skip to content

Instantly share code, notes, and snippets.

@notahat
Created September 27, 2010 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save notahat/600069 to your computer and use it in GitHub Desktop.
Save notahat/600069 to your computer and use it in GitHub Desktop.
def kata(digits = [], sum = 0, has_pair = false)
if sum < 15
start = (digits.last || 0) + 1
(start..9).inject([]) do |result, digit|
result +
kata(digits + [digit], sum + digit, has_pair) +
kata(digits + [digit, digit], sum + digit + digit, true)
end
elsif sum == 15 && has_pair
[digits]
else
[]
end
end
p kata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment