6
A few hours earlier, I got this puzzle:
Suppose, you toss a coin n times, then what is the probability of getting m number of heads? ( where m belongs to the set of all prime numbers)
For instance, take n = 2, then
SS = { HH, HT, TH, TT }
So, output is 1/4 (for HH case)
Then, for n = 3,
SS = { HHH, HHT, HTH, THH, HTT, THT, TTH, TTT }
So, output is (1 + 3)/8 (for 3 H's case and 2 H's cases respectively)
Input: n ( an integer, 0 <= n <= 1000 )
Output: The probability (in any distinguishable form, i.e., decimal, exponential, fraction, etc)
This is a code-golf, so fewest bytes would win!
When you say n<1000 you mean that we should get results or the code can run forever? – J42161217 – 2019-04-25T14:11:01.907
@J42161217, it depends on you. n < 1000 is just a range of input for n (0 <= n < 1000). – Rahul Verma – 2019-04-25T16:45:12.270
1...the wording "where m is the set of all prime numbers" is a bit confusing, since you can't exactly have a number of heads equal to the set of all prime numbers (unless you're using an encoding of natural numbers into sets, in which case you should probably supply it!). I assume you actually mean that m is any prime number, although that wording suggests that you can pick a single one--it would be clearest to just not name it as a variable at all, and ask "in n flips of a fair coin, how likely are you to get a prime number of heads?" – Unrelated String – 2019-04-25T18:17:41.353