Today's Challenge
One concept, three rungs. Reaching rung 1 is the goal, so climb as far as you can.
Taking Numbers Apart
loops + digits
Add up the digits
Write a function called digit_sum
You get a whole number that is 0 or bigger. Add up its digits and return the total, so 123 gives 1 + 2 + 3 = 6. The number 0 gives 0.
Examples
| Input | Output |
|---|---|
| 123 | 6 |
| 0 | 0 |
| 7 | 7 |
| 405 | 9 |
There are extra hidden tests, so make it work in general, not just for these.
Solution unlocks when today's challenge closes.
How many are even
Write a function called count_even_digits
Count how many of the digits are even. A digit is even when dividing it by 2 leaves no remainder, so 0, 2, 4, 6 and 8 are even. The number 0 has one digit and it is even, so 0 gives 1.
Examples
| Input | Output |
|---|---|
| 1234 | 2 |
| 1357 | 0 |
| 0 | 1 |
| 24 | 2 |
There are extra hidden tests, so make it work in general, not just for these.
Solution unlocks when today's challenge closes.
Squash it to one digit
Write a function called single_digit
Add up the digits, and if the answer still has more than one digit, add its digits up again. Keep going until only one digit is left. 38 becomes 3 + 8 = 11, then 1 + 1 = 2, so the answer is 2.
Examples
| Input | Output |
|---|---|
| 38 | 2 |
| 0 | 0 |
| 9 | 9 |
| 12345 | 6 |
There are extra hidden tests, so make it work in general, not just for these.
Solution unlocks when today's challenge closes.
Finish Rung 1 and today counts. Rungs 2 and 3 are there if you want to push further.