Advent of Code 2018

12/01/2018 07:35 Cups#1
For all of the programmers that are celebrating the festive season, the Advent of Code is here! If you wish to talk about some of the challenges or participate, please visit the website at [Only registered and activated users can see links. Click Here To Register...]! The input (and hence answers) are different for everyone, but you can still share the code you used to solve them. There is no API for the site so you'll need to read your input from a file.

Best of luck to all! Let me know how you go! Please keep discussions to English only! If you post code on elitepvpers please make sure its in spoiler tags - click Hastebin / Github links at your own discretion knowing that it may contain spoilers!

My solutions - [Only registered and activated users can see links. Click Here To Register...]
12/01/2018 13:01 florian0#2
Wow ... Day 1 Part 2 really took a lot of cycles (142). I even considered my input to be broken.
12/01/2018 13:30 Cups#3
Quote:
Originally Posted by florian0 View Post
Wow ... Day 1 Part 2 really took a lot of cycles (142). I even considered my input to be broken.
I updated my post - feel free to post your solutions as long as they're in a spoiler tag (if it's a code block on the forum), or feel free to just post a link to your Github repository / Hastebin if you feel like sharing your answers! I've updated the main post to include a link to my solutions.

Glad you found the puzzles challenging, things like this keep the mind active!
12/01/2018 13:43 florian0#4
Quote:
Originally Posted by Cups View Post
Glad you found the puzzles challenging, things like this keep the mind active!
I chose std::list, which was not a good choice regarding speed. So finding the frequency initially took roughly 1:30min. Thats why I considered my set to be wrong ;D

I'm now using unordered_set, which is way faster in this case.
12/01/2018 13:50 Cups#5
Quote:
Originally Posted by florian0 View Post
I chose std::list, which was not a good choice regarding speed. So finding the frequency initially took roughly 1:30min. Thats why I considered my set to be wrong ;D

I'm now using unordered_set, which is way faster in this case.
You can make the code even simpler by using the return values of std::unordered_list#emplace - it returns a pair of <Iterator, bool>. The bool value will be false if a duplicate entry exists as a set only allows one of each element in its collection
12/01/2018 16:54 sk8land​#6

12/02/2018 14:35 Cups#7
Repository has been updated with solutions for day 2! No cheating now :P

[Only registered and activated users can see links. Click Here To Register...]
12/02/2018 20:45 sk8land​#8
Quote:
Originally Posted by Cups View Post
Repository has been updated with solutions for day 2! No cheating now :P

[Only registered and activated users can see links. Click Here To Register...]
I consider LINQ to be cheating.


12/03/2018 01:42 Cups#9
Quote:
Originally Posted by sk8land​ View Post
I consider LINQ to be cheating.


Then I'd go so far as to say you're being rather silly, especially in this scenario! Firstly, it's important to make the distinction that the Advent of Code is by no means a programming challenge, but a problem solving exercise.

Second, LINQ in this use case is not providing any functionality that any other language with high order functions like Map, Reduce, Fold and Zip would provide. Would you consider it cheating if I wrote my answers in Haskell? The code would be much more concise and be using the exact same functions that LINQ provides.

Edit: After writing that response I decided to try a functional language for the first time ever. Could probably be improved a lot and isn't totally idiomatic F# but it's my first program ever using the language. I don't fully understand the functional idioms just yet :P

[Only registered and activated users can see links. Click Here To Register...]
12/03/2018 14:51 sk8land​#10
Quote:
Originally Posted by Cups View Post
Then I'd go so far as to say you're being rather silly, especially in this scenario! Firstly, it's important to make the distinction that the Advent of Code is by no means a programming challenge, but a problem solving exercise.

Second, LINQ in this use case is not providing any functionality that any other language with high order functions like Map, Reduce, Fold and Zip would provide. Would you consider it cheating if I wrote my answers in Haskell? The code would be much more concise and be using the exact same functions that LINQ provides.

Edit: After writing that response I decided to try a functional language for the first time ever. Could probably be improved a lot and isn't totally idiomatic F# but it's my first program ever using the language. I don't fully understand the functional idioms just yet :P

[Only registered and activated users can see links. Click Here To Register...]
Calm down, kangaroo. It was just a joke.


Edit: I would like to solve one of those with Haskell as well, but it's been ages since I was exposed to Haskell in uni and I forgot the whole syntax. The last time I tried to get into Haskell again it gave me autism.
12/03/2018 16:59 florian0#11
Had to skip Day 2, got a bad headache.

Reading is definitely not one of my strengths. I didn't read day 3 to the end and "accidentally" build an algorithm to find the largest single rectangle of all overlapping claims. lol.
12/04/2018 02:33 0xFADED#12
My take on Day 3: [Only registered and activated users can see links. Click Here To Register...]

Probably overcomplicated af, but it works :kappa:
12/04/2018 10:17 Cups#13
Quote:
Originally Posted by 0xFADED View Post
My take on Day 3: [Only registered and activated users can see links. Click Here To Register...]

Probably overcomplicated af, but it works :kappa:
Hey what matters is that it works :P

Updated repository with solutions to day 4 - [Only registered and activated users can see links. Click Here To Register...]
12/04/2018 16:43 sk8land​#14

I would appreciate any tips on how to simplify this.

Day 5: