Skip to main content
Submitted by manoj on 21 October 2023
coding-cability

Imagine there are 100 pieces of paper in a hat, labelled from 1-100. Two pieces of paper are chosen at random. The smaller number is subtracted from the larger number and the answer is written on a new piece of paper. This number is placed back in the hat and the two original numbers discarded. The process repeats until one number is left.

What can you say about the final number left in the hat? Would that be a "smaller number" or a "bigger number". Let's define if the number is smaller than mid-point (less than 50 in case of 1-100), then we call it a "smaller number" and if it's larger than the mid-point (more than 50 in case of 1-100), we call it a smaller number.

Your job is to write a simulator for this game. Write a function that takes two arguments: first one is the max number N and second argument is how many times the simulation must run. The output can be the winning number for each simulation run and at the end, what percentage of times a smaller number won and what percentage of time a larger number won.

Ideal Answer (5 star)