Project Euler 126 - Cuboid Layers
Official link: https://projecteuler.net/problem=126
Thought Process
My first thought is that there would be a recursive formula to solve this problem for the number of cubes needed per layer so I started doing some test cases in GeoGebra (Manually drawing out cubes and counting them) and I got the following results
Now Layer 1 is obvious, if we start with (a, b, c) we will require 2(ab + ac + bc) cubes to cover it. Now here are some patterns I saw
From layer 1 to 2 the difference was always 4*sum
From layer 2 to 3 the difference was always 4*sum + 8
From layer 3 to 4 the difference was always 4*sum + 8*2
Which is exactly the type of recursive structure I was hoping for, hence I made the following hypothesis:
From here I trusted blindly in my guess and just brute forced the answer.Â
Just generate all levels of all cubes such that each level has less than 20,000 cubes (This was arbitrarily chosen and increased till I got the correct answer), after generation return the first value that occurs 1,000 times.
Interactive Code
Input an Integer (yourinput)
Code will output the least value of n such that C(n) = yourinput (Subject to the 20,000 cubes constraint stated above)