It can be really uncomfortable to talk about your age when you get older. Sometimes you just want to be twenty again! Well, with some math magic that's totally possible - just select the correct number base. For example, if they are turning 32, that's 20 in base 16!
Translate the given age to the desired 20 or 21 years, and indicate the number base, in the format specified below.
Note: input will be always > 21
Examples:
32 --> "20, in base 16"
39 --> "21, in base 19"
Tests:
a, b; where a is the age of the person, b is the desired age.
50, 20
50, 21
43, 20
66, 21
This challenge comes from anter69 on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (4)
Here is the Python solution:
Are fractional bases allowed? Or should the function return something special for impossible situations.
Many of the tests are impossible with integral bases. For example, to write 50 as 21 in base n, 2n + 1 = 50, and there is no integer solution because 50 is even.
This function checks if given age can be translated to the given required age,
This function returns the translated age and the base if possible,