Well, I tackled today the problem 2. It took me a long long time to get it right (about 3:30 hours), and it is quite interesting cause in essence the program is very simple. It’s less than 20 lines.
This shows how hard it is sometimes to think (Especially after a tiring day of work!), but at the same time, how powerful technology can be in helping solve a problem. If problems are looked in the right way, they can actually be solved in fairly simple ways thanks to iteration.
What was the hardest part?
Honestly, the hardest part was to understand how can I easily substitute numbers like this. Imagine you have 3 slots (a,b,c), and you want to test ALL the different combinations of numbers that can be put in those 3 positions, knowing that a,b,c can be any integer from 0 to 100, and use each one of those combinations to do some calculation.
At the end I realized I could just use 3 “for” loops and that solved it. First calculates all possibilities with 0.0.x, then 0.1.x, then 0.2.x etc… until… 0.100.100, then it does 1.0.x , 1.1.x etc… until it reaches 100.100.100
You can easily test this by executing the following code:
for a in range (0,20): for b in range (0,20): for c in range (0,20): print " ({0} ,{1}, {2})".format(a,b,c)