Will you get head?
Description:
Introduction
As you are taking a stroll through the newly opened carnival in your city, you are approached by a man dressed in a magician suit.
Welcome, good sir! Care to play a game?
Just guess our act right and ...
Sorry, wrong site.
Observe me as I throw this very special coin into the air.
After saying this, the man proceeds to flip the coin total
times, landing heads
heads out of those.
I've given you this information; now I ask you: Are you willing to bet
bet
dolars of your money for a chance to win the grand total ofprize
dolars, if the next throw lands heads again?
Knowing that the coin may be biased. You must make a decision as to whether you will take this bet or not.
Task
Given that a possibly biased coin landed heads
heads out of total
throws, determine whether you should take a bet of bet
dolars for a chance of getting prize
dolars back.
- heads: [0, 1000] (integer)
- total: [0, 1000] (integer)
Notes
A bet should be taken if and only if the expected value of the bet is greater than the prize.
Consider that, without any information, all the possible biases of the coin are equally likely. In other words, the coin is initially presumed to be fair.
heads
andtotal
will always be non negative integers withtotal
being greater or equal toheads
bet
andprize
will always be real numbers. A negativebet
should be interpreted as receiving money to play the bet, while a negativeprize
should be interpreted as paying money upon winning. Using expected value, still works in these cases.
Examples
prediction(0, 0, 1, 2) -> False
prediction(3, 3, 10, 14) -> True
prediction(0, 3, 1, 6) -> True
prediction(10, 12, 1, 1.2) -> False
prediction(100, 100, 1, .9) -> False
prediction(0, 0, -1, -1.99) -> True
prediction(0, 1_000, -1, 0) -> True
prediction(1_000, 1_000, 0, -.9) -> False
Similar Kata:
Stats:
Created | Oct 22, 2023 |
Warriors Trained | 100 |
Total Skips | 27 |
Total Code Submissions | 135 |
Total Times Completed | 16 |
Python Completions | 16 |
Total Stars | 1 |
% of votes with a positive feedback rating | 72% of 9 |
Total "Very Satisfied" Votes | 5 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 8 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |