Advent of Code 2017

Check this out - fun coding challenges from December 1 to 25. I’ve done it for the past two years and it’s a cool way to learn new languages and solve puzzles.

https://adventofcode.com/

EDIT: Join the FCC private leaderboard! Sign up for an account, go here, and paste the following code in the box. 187009-54c73e82

Happy coding!

15 Likes

Looks cool - I will check it out more when the event starts.

This looks good. Did you start playing already? You should make a “private leaderboard” for FCC people.

I did today’s challenges in javascript and look forward to seeing how far I get with the rest of them.

1 Like

Awesome idea - private leaderboard created. Join it with this code: 187009-54c73e82.

Looking forward to this month!

This is really cool!

cool idea to learn coding .It’s awesome.

Just wanted to share this website I found, https://adventofcode.com/ . It has programming challenges for each day up until the 25th of December (a challenge is locked until we reach that day on the calendar). For anyone interested, good luck :slight_smile: .

This event was actually just posted a couple of days ago :slight_smile:

1 Like

Oops, thanks for the information :+1:
Edit: Link to other post: Advent of Code 2017

1 Like

If anyone’s craving more algorithm-solving goodness and didn’t do this in previous years, the 2016 and 2015 challenges are also still available. :wink:

Hi everyone,

How did you approach the second part of Day 3?

For Part 1, I found in some website some math formulas that from a given number would give me the coordinates of that point, considering the number 1 as the origin. This made it super easy to calculate the distance to the center.

However in the second part, the numbers will be filled up based on the numbers that are already there, so it seems to me that brute forcing the creation of the spiral until the number we are interested in is the only way to go. What are your thoughts?

I was thinking there could be a maths solution for this, but what I did is I listed the numbers on paper and their corresponding distances from the center. Patterns emerged, and I made my solution based on those. In the end I don’t fully know why my solution works :sweat_smile:

That’s what I did. I made a function that generates the spiral with the spiral’s “radius” as input, until the number of interest was in there.

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 sides (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