Skip to content

Instantly share code, notes, and snippets.

@karapetyan
Last active September 18, 2015 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karapetyan/c90c2613c09aaf063780 to your computer and use it in GitHub Desktop.
Save karapetyan/c90c2613c09aaf063780 to your computer and use it in GitHub Desktop.
class Rabbit
@@result = 0
def initialize(path = "./input")
File.open(path, "r") do |file|
file.each_line do |line|
line = line.split
combinations(line[0].to_i, line[1].to_i)
p @@result
end
end
end
private
def combinations(k, n, i = 0)
i += 1
@@result += combinations(k, n - i, i) if i < k
end
end
Rabbit.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment