GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Find all numbers up to 8.1 mil with every digit in it adds up to 10 with few previous and/or next digits.

Hi everybody, I would appreciate some help with an exercise. Here it is:

There are sequences in some numbers, which adds up to 10. For example, number 3523014 you can find 4 such sequences:





We can find some 'wonderful' numbers, in which each digit is in at least one of such sequences.

For example, 3523014 is 'wonderful' number, but 28546 - is not (there is such sequence, which adds up to 10 and includes 5 at the same time).

I need to find number of such 'wonderful' numbers in interval [1, 8100000] (1 and 8100000 inclusively).

I've tried to solve it on my own using Python, but I'm quite new to programming and cannot think of algorithm, which will not give me wrong numbers among the right ones.

I don't want to mess up question, so I put actual code on pastebin:

‚ÄčIt returns wrong answers like 91846, 91855, etc.

Thanks in advance for help!

asked Sep 18, 2016 by Woohoolista
edited Sep 18, 2016 by Woohoolista