digits made only of digits. Decide whether it can be cut into a sequence of numbers (keeping the digits in order and using each digit exactly once) such that:
- there are at least three numbers;
- every number from the third one on equals the sum of the two numbers right before it.
A number may not start with a zero unless it is 0 itself: pieces like 05 or 00 are not allowed, while 0 is fine.
Return True if such a cut exists and False otherwise.
The numbers in the chain can get very long; think about how you would cope in a language without big integers.digits='2810182846' → True
Cut it as 2, 8, 10, 18, 28, 46. From the third number on, each one is the sum of the two before it: 2 + 8 = 10, 8 + 10 = 18, 10 + 18 = 28, 18 + 28 = 46.
digits='1012' → False
The cut 1, 01, 2 would work, but "01" has a leading zero, which is not allowed. No other cut follows the sum rule.
digits='5050100' → True
50 + 50 = 100: a chain of three numbers is enough.
digits contains only the digits 0–9digits='2810182846'
True
Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.