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

Rung 1Daily goal5 points

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

InputOutput
1236
00
77
4059

There are extra hidden tests, so make it work in general, not just for these.

Solution unlocks when today's challenge closes.

Rung 2Bonus7 points

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

InputOutput
12342
13570
01
242

There are extra hidden tests, so make it work in general, not just for these.

Solution unlocks when today's challenge closes.

Rung 3Bonus10 points

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

InputOutput
382
00
99
123456

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.