$ time ruby snake_case.rb
184756
ruby snake_case.rb 0.05s user 0.01s system 94% cpu 0.061 total
Last active
April 8, 2016 15:57
-
-
Save Tonkpils/21dd6e0628cfafd531ce7a8fc5809a26 to your computer and use it in GitHub Desktop.
Snake Case Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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