REMEMBER!
It is VERY important NOT to write any public spoilers
ALWAYS keep spoiler stuff hidden inside one of these
Summary
This text will be hidden
which you can obtain by clicking on the gear icon
Good luck
FYI one of the features of Advent of Code is that we all get given different inputs so our answers will be different.
The examples are all the same but each of us gets different inputs for us to solve
Finally managed to do Part 1 but had to do it in sections as it crashes about every 40 - 90 iterations
Because it took so long I replaced one line with some JavaScript - this sped it up but did nothing to prevent the crashes
So I did it in sections and totalled all the sections up in a spreadsheet and I got the right answer
I re-ran the first section (1-80) without the JS and it gave the same answer as the JS code so I'm treating that as "proof" that my Snap! code would do the same for all the other sections
I was intrigued by the line possible = product("*+", repeat=len(num) - 1)
and searched for what product did with the repeat parameter and worked out it would produce all the combinations of + and *
Replaced the append block from part 1's definition of generate candidates with:
(different from + and *, join is not a hyperblock)
Run time: about 30 sec. on my system (a rather basic windows PC ) ... No wonder it takes more run time than part 1: the longest input line has 20 numbers now to be combined in 319 = 1,162,261,467 fashions, versus 219 = 524,888: larger by a factor 2217.
... no JavaScript required, nor Python: just plain old recursion within Snap!
Having looked at your elegant code for Part 1 (and working out how it worked using single-stepping) I realised that my 1st solution (that took forever and crashed) was just overly complicated
So I simplified it and it runs in <10 seconds and doesn't crash