Skip to content

Instantly share code, notes, and snippets.

@notahat
Created September 27, 2010 23:06
Show Gist options
  • Save notahat/600039 to your computer and use it in GitHub Desktop.
Save notahat/600039 to your computer and use it in GitHub Desktop.
def kata(digits = [], has_pair = false)
if digits.inject {|sum, digit| sum + digit } == 15
has_pair ? [digits] : []
else
start = (digits.last || 0) + 1
(start..9).inject([]) do |result, digit|
result + kata(digits + [digit], has_pair) + kata(digits + [digit, digit], true)
end
end
end
p kata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment