13. Digit sum
Write digitSum n, the sum of the decimal digits of n. For example, the digits of 12345 add up to 15.
Dividing by 10 removes the last digit, but n / 10 is not a structural sub-term of n, so Lean has to be convinced that the recursion ends.
Examples
- Input
digitSum 12345Output15 - Input
digitSum 0Output0 - Input
digitSum 9Output9
Submitting also runs 5 hidden tests.
Loading editor…
Type
\to in the editor, or click:Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.
ReadyLn 1, Col 1Lean 4
Draft saved in this browser