Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.78 KB

File metadata and controls

39 lines (30 loc) · 1.78 KB

Coin Counter

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.

Business Rules/Errata

  • 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?

Examples

count_coin_rounds(2)     // 1
count_coin_rounds(128)   // 7
count_coin_rounds(1000)  // 10

Tackling This Challenge

  1. Make sure you've got the required software on your machine: A JDK 11+
  2. If you haven't already, fork the CodingDojo repository (INSTRUCTIONS).
  3. Checkout a new branch using git checkout -b yourgithubusername-wip.
  4. Execute the run_tests script once to set up Gradle for this challenge (use ./run_tests from the challenge root directory).
  5. Add your code to the 'src/main/kotlin/Solution.kt' file to solve the puzzle.
  6. Confirm your solution by running tests. Execute the run_tests script to run the tests.
  7. If you've passed all the tests, submit your solution to the repo using this solutions guide in our wiki.
  8. Navigate to GitHub, and submit your pull request.
  9. One of the CodingDojo maintainers will help you get your PR merged.

Requirements

  • JDK 11+