I have not even attempted part 2 yet, but here’s what I can report from part 1 of day 3:

It’s a centered octagonal number, which thankfully Wikipedia had the formula for calculating sides provided: `(2n-1)^2`

So, I used that formula to push these values into an array, each index representing how many levels of the square there are. So `arr[0] = 1; arr[1] = 9; arr[2] = 25; arr[3] = 49`

etc…

I used a while loop that kept incrementing the index by one, and just kept running the formula. I breaked out of the loop once the val was higher than the term we were searching for.

Now, since I had an array with values, and the `index`

that represented what row we were on, I was able to use that information to calculate the size of the `square`

(`arr[index] - arr[index -1`

]), the size of the `side`

s (`square / 4`

), and the index of the `middle`

of a given side (`side / 2`

).

Storing the find number minus `arr[index - 1]`

gets the total offset relative to the start of the square (`FindIndex`

), but I need to isolate this offset relative to a side (any side). So I simply subtracted the size of a side from it until that offset was smaller than a side of the square at our level.

At this point all the data I have calculated results in the following:

`Find = 277678`

`Index: 264`

`Square: 2104`

`Side: 526`

`FindIndex: 475`

`Middle: 263`

`Offset: 212`

With all of this data we can then easily find the result. Index is off by one, so by combining `index + offset - 1`

then we can get our answer.

I’ve checked this method with a few other numbers, and they seem to hold. Hopefully I can use this information to my advantage on part 2 shortly.

Thanks!

Jimmy