2018 Advent of Code

Anyone else doing the 2018 Advent of Code?

If you don’t know, the advent of code is:

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other.

https://adventofcode.com/

In general I hate speed contests, interviews, companies, universities, practicing and being challenged, but I’m giving it a go this year!

4 Likes

I did end up finishing day 1 on time, the first part was e-z, the second part definitely tripped me up. I’m trying to specifically use functional programming, so not looping through it in a traditional manner took some… understanding?

1 Like

Here is my answer to Day 1 part 2 , I tried to do it obscurely for fun

<?php

$changes = array_map("intval",array_filter(explode("\n", file_get_contents("freqlist.dat"))));

$sum = 0;
$found = [];
$answer = false;

while($answer === false) {
    array_map(function($a) use (&$sum, &$found, &$answer) { 
        return ($answer === false && isset($found[$sum += $a]) && $answer = $sum) || $found[$sum] = false; 
    }, $changes);
}

print "Answer: $answer\n";

1 Like

Just finished day 2! Second one tripped me up. @Draco when you do it there’s a really nice PHP function that’ll help :slight_smile:

1 Like

Yup, there sure is … I don’t use that function often enough.
Looking through all the php functions, there are alot I don’t use.

Day 2 complete… working on Day 3

Completed Day 3 … getting more complex …

I thought about using some sort of image functions doing this one.

Yes, I’m doing mine in Ruby. Can anyone DM me their input for Day 2 Part 1?

My code works for the example, but for my input I’m getting the wrong checksum. I’d like to run your input through my script and report back what checksum I get. Thanks!

The input is downloadable on the site … it is just a text file.

So burned up from programming all day at work, I literally cannot focus enough to finish todays… :\

Damn.