Six problems that look easy and each hide one trap. They are here for the method: before you submit, write down two or three tiny tests — a negative number, a zero, the biggest value allowed — work out their answers by hand, and check that your program agrees.
- Digit Sum: the numbers can be negative, zero or as big as 10¹⁸. What does your loop do with −45? With 0?
- Sum of Digits 2: the digit sum of the digit sum — one function, called twice. The number can be negative here too.
- Clamp (the second one): the same idea as on the first practice page, with
values up to 10¹⁸. Every variable and every parameter must be a
long long. - Manhattan Distance to Base: a single distance can reach 4·10⁹, and the total
of a thousand of them is far beyond an
int. - Euclid: the numbers can be negative, and gcd(0, 0) is 0. Euclid's loop wants numbers that are not negative.
- Normalize a Fraction: the denominator must end up positive, and 0/5 must become 0/1. Try 4/−6, −5/−10 and 0/−7 by hand before you run anything.