Project Euler 303 - Multiples with small digits
Official link: https://projecteuler.net/problem=303
Thought Process
Nice to have a simpler problem every now and then.
I made a function, build_next_stack(curr_round), that builds a list of possibilities. I memoize because I will need to call it a lot of times
if curr_round = 0, returns ['1', '2']
if curr_round = 1, returns ['10', '11', '12', '20', '21', '22'] -> etc
I made a function, construct_sequence(n), thats takes a number n and then goes through the first list, checks if its divisible, then builds the next list of possibilities using build_next_stack
Then I just go through each n and add construct_sequence(n) to a total.
It goes very quickly except for 9,999 where construct_sequence(9,999) = 11,112,222,222,222,222,222, which is really large and memory intensive.
Like everyone else I noticed
construct_sequence(9) = 12,222
construct_sequence(99) = 1,122,222,222
construct_sequence(999) = 111,222,222,222,222
And I found the pattern!
Interactive Code
Input an integer (yourinput)
Code will output ∑ f(n)/n where 1 ≤ n ≤ yourinput