My idea for this problem was to create a hash map. I will explain how below.
First thing to do is to create the all the triangle, square, pentagonal, hexagonal, heptagonal, octagonal, then I create one list all_shapes which is all the shape numbers
Note: along with generating the shape number I generate them as a tuple containing their number and shape, for example (1035, 'triangle'), (1081, 'triangle'), (1128, 'triangle'). etc
Next, I initialise a dictionary, then I go through the list all_shapes with variable x
First I set mydict[x] = , then I go then I go through the list all_shapes with variable y
I check that x != y (That is the numbers are not the same number)
I check that x != y (That is the numbers are not the same shape)
Then I check that x and y are cyclic (Last 2 numbers of x are equal to the first to y
If all of these conditions are true, I add y to mydict[x]
Now mydict basically contains a map, where mydict[x] is a list containing where all elements are cyclic to x
This next step is not very pretty, I go through all the octagonal numbers, and I start the pointing game. For each octogonal number I will check every number it points to, and every number that number points to and so on
I will point 6 times, and now its begin to test if we have the 6 numbers we need
Make sure that the last number is cyclic with the first
and make sure there is one of every shape
The question statement says there is only one, so once we have found our 6 long cyclic path where each number is a different shape number, then we are done!
No interactive code for this problem, my code is given below