Skip to content

Instantly share code, notes, and snippets.

@MaherSaif
Forked from notahat/kata.rb
Created October 15, 2010 19:56
Show Gist options
  • Save MaherSaif/628840 to your computer and use it in GitHub Desktop.
Save MaherSaif/628840 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