Skip to content

Instantly share code, notes, and snippets.

@Denommus
Created April 28, 2012 03:51
Show Gist options
  • Save Denommus/2515548 to your computer and use it in GitHub Desktop.
Save Denommus/2515548 to your computer and use it in GitHub Desktop.
Heads or tails
# Shows all the possibilities of a set of coins throwing
# You could as well change "heads" and "tails" for true and false.
def possibilities(a)
results = []
if(a==1)
results << ["heads"]
results << ["tails"]
else
possibilities = possibilities(a-1)
possibilities.each do |possibility|
results << (possibility + ["heads"])
results << ( possibility + ["tails"])
end
end
return results
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment