Solved first in Python then translated into Scratch (for fun) Left side is Part 1 (solves almost instantly) Right side is Part 2 (takes quite a long time to brute force)
I apologize if I crash your computer. Run at your own risk. That shouldn't happen, but in case it does, don't say I didn't warn you.