10
Write a program that, given a small positive even integer from standard input, calculates the probability that flipping that many coins will result in half as many heads.
For example, given 2 coins the possible outcomes are:
HH HT TH TT
where H and T are heads and tails. There are 2 outcomes (HT
and TH
) that are half as many heads as the number of coins. There are a total of 4 outcomes, so the probability is 2/4 = 0.5.
This is simpler than it looks.
Test cases:
2 -> 0.5
4 -> 0.375
6 -> 0.3125
8 -> 0.2734375
1We can assume the coins are perfect and there's an even chance of getting heads or tails? – Juan – 2011-02-27T17:18:36.313
Do we need to print the output to stdout? – Wile E. Coyote – 2011-02-27T18:24:49.303
@Juan yes. @Dogbert yes. – david4dev – 2011-02-27T18:37:16.063
Could we get some more test cases to verify our solutions? – Wile E. Coyote – 2011-02-27T19:44:35.257
@Dogbert - done – david4dev – 2011-02-27T20:02:35.753
Does the output have to be actually printed out or is computing enough? I've got a couple of answers I could shave characters from if I migrated from complete program to interactive session. – J B – 2011-03-02T08:29:10.117