59. Plus one

EasyProgramFree10 points

A natural number is given as the list of its decimal digits, most significant first: [1, 2, 3] is 123. Write plusOne digits, the digits of the number plus one.

Carries can run through every digit: [9, 9] becomes [1, 0, 0].

Examples

  1. Input: plusOne [1, 2, 3]Output: [1, 2, 4]
  2. Input: plusOne [4, 3, 2, 1]Output: [4, 3, 2, 2]
  3. Input: plusOne [9]Output: [1, 0]
  4. Input: plusOne [9, 9]Output: [1, 0, 0]

Submitting also runs 5 hidden tests.

Constraints

  • The list is not empty, every element is a digit from 0 to 9, and there are no leading zeros except in [0].
Solution.lean
Loading editor…

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