Skip to content

Instantly share code, notes, and snippets.

@Tonkpils
Last active April 8, 2016 15:57
Show Gist options
  • Save Tonkpils/21dd6e0628cfafd531ce7a8fc5809a26 to your computer and use it in GitHub Desktop.
Save Tonkpils/21dd6e0628cfafd531ce7a8fc5809a26 to your computer and use it in GitHub Desktop.
Snake Case Challenge

Snake Case Challenge

$ time ruby snake_case.rb
184756
ruby snake_case.rb  0.05s user 0.01s system 94% cpu 0.061 total
Grid = Struct.new(:n, :m) do
# Finds the number of ways `n` and `m` positions
# we can choose from `n * m` available paths
def unique_paths
factorial(self.n + self.m)/(factorial(self.n) * factorial(self.m))
end
private
def factorial(n)
(1..n).inject(:*)
end
end
puts Grid.new(10, 10).unique_paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment