Puzzle | Heads or Tails
50 coins are lined up on a table (initially all heads facing upwards). 50 people pass from the coins one by one in the following manner:
The first person comes and visits the coins numbered 1, 2, 3, 4, …. and flips the coins until an opposite face comes(For ex-if it was head initially, he/she flips it until the tail comes and vice versa.)
The second person comes and visits the coins numbered 2, 4, 6, 8….. and flips the coins.
Similarly, the third person comes and visits (3, 6, 9, 12, ……) and does the same.
The task is to find the final states of all the coins after 50th person passes i.e. whether a coin is facing heads or tails upwards?
Solution: The trick is to identify if a coin is being visited by people even or an odd number of times.
Pay attention to the coin number.
Only perfect squares have odd no. of factors, and every other number has even number of factors.
For all those coins which have an odd number of factors will be facing tails upwards and for all those coins which have even no. of factors will be facing heads upwards.
So, coins numbered 1, 4, 9, 16, 25…. will have tails and 2, 3, 5, 6, 7, 10, 11, … will have heads facing upwards.
from math import floor, sqrt def getTails(n): return floor(sqrt(n)) if __name__ == "__main__": n = 50 print(getTails(50)) |
7
Recommended Posts:
- Puzzle 43 | Muddy Heads
- Puzzle | Can 2 persons be with same number of hairs on their heads?
- Expected number of coin flips to get two heads in a row?
- Puzzle 51| Cheryl’s Birthday Puzzle and Solution
- Puzzle 34 | (Prisoner and Policeman Puzzle)
- Puzzle | 3 Priests and 3 devils Puzzle
- Puzzle 85 | Chain Link Puzzle
- Puzzle 15 | (Camel and Banana Puzzle)
- Puzzle 81 | 100 people in a circle with gun puzzle
- Puzzle 39 | (100 coins puzzle)
- Puzzle 27 | (Hourglasses Puzzle)
- Puzzle 28 | (Newspaper Puzzle)
- Puzzle 29 | (Car Wheel Puzzle)
- Puzzle 31 | (Minimum cut Puzzle)
- Puzzle 33 | ( Rs 500 Note Puzzle )
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : unknownboy



