Skip to content

Instantly share code, notes, and snippets.

@kballenegger
Created August 15, 2013 08:07
Show Gist options
  • Select an option

  • Save kballenegger/6239126 to your computer and use it in GitHub Desktop.

Select an option

Save kballenegger/6239126 to your computer and use it in GitHub Desktop.
Project Euler, problem #31.
Cs = [1, 2, 5, 10, 20, 50, 100, 200]
def left(n, s)
Cs.select do |c|
c <= s
end.map do |c|
x = n-c
x > 1 ? left(x, c) : (x < 0 ? 0 : 1)
end.reduce(&:+)
end
check = ARGV[0].to_i
puts left(check, check)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment