Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created August 8, 2010 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshluca/513999 to your computer and use it in GitHub Desktop.
Save marshluca/513999 to your computer and use it in GitHub Desktop.
pass ball in ruby
# 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