You are given n
fair coins, and you flip all at the same time. Every time a coin
comes up 'tails', it is removed from play. The ones that come up 'heads', you will flip
again on the next round. Write a function that, given n
, returns the number of rounds
you'd expect to play until only one coin remains.
- Each coin is fair, meaning it is equally likely to come up as either side on any given round.
- Your answer should be rounded to the nearest whole number, since it is impossible to play part of a round.
- Extra Challenge: What is the most time-efficient solution you can devise?
- Extra Challenge: Can you implement this game for dice, instead of coins?
count_coin_rounds(2) // 1
count_coin_rounds(128) // 7
count_coin_rounds(1000) // 10
- Make sure you've got the required software on your machine: A JDK 11+
- If you haven't already, fork the CodingDojo repository (INSTRUCTIONS).
- Checkout a new branch using
git checkout -b yourgithubusername-wip
. - Execute the
run_tests
script once to set up Gradle for this challenge (use./run_tests
from the challenge root directory). - Add your code to the 'src/main/kotlin/Solution.kt' file to solve the puzzle.
- Confirm your solution by running tests. Execute the
run_tests
script to run the tests. - If you've passed all the tests, submit your solution to the repo using this solutions guide in our wiki.
- Navigate to GitHub, and submit your pull request.
- One of the CodingDojo maintainers will help you get your PR merged.
- JDK 11+