Created
August 8, 2010 12:54
-
-
Save marshluca/513999 to your computer and use it in GitHub Desktop.
pass ball in ruby
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
# ruby | |
def compute(current,remain) | |
result = 0 | |
if remain == 0 | |
result = current == 'a' ? 1 : 0 | |
else | |
for n in ['a','b','c','d'] | |
result += compute(n,remain-1) if n != current | |
end | |
end | |
return result | |
end | |
puts compute('a',5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment