Math and Geometry
157 / 170Math and GeometryLesson 2 of 5About 58 min
A process that must either stop or repeat, and two ways to tell which.
The transformation squares each digit and adds the results. The largest value it can produce from an input of a given length is worked out. Type the three lines it prints.
def digit_square_sum(n): total = 0 while n > 0: total += (n % 10) ** 2 n //= 10 return total print("largest from 3 digits:", digit_square_sum(999))print("largest from 4 digits:", digit_square_sum(9999))print("so anything above 999 shrinks:", digit_square_sum(9999) < 9999)Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.
Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.