Project Euler 166 - Criss Cross
Official link: https://projecteuler.net/problem=166
Thought Process
Honestly, I did nothing special here. Same as basically everyone else, denote the values
a b c d
e f g h
i j k l
m n o p
Then I let:
s = a + b + c + d
Then notice the following few equations
s - a - e - i = m
s - b - f - j = n
s - c - g - k = o
s - e - f - g = h
s - i - j - k = l
s - a - f - k = p
and we can notice g = s - d - j - m
This brings us to only needing 9 variables
After each variable creation, just check that it's between 0 and 9 as a quick stopper and its done. There are many ways to make this much faster, Nayuki shows how to do it using 8 variables, some people on thread managed 7, Stephane used some tricks to make his code much faster, but these type of problems don't bring me much joy so I left it as is!
Interactive Code
No interactive code, my code is given below