Advent of Code 2019

Advent of Code is a very well designed coding challenge that has been released every year since 2015 at the start of December. The goal is simple: one coding problem a day from the 1st to the 25th of December. And if you make it to the end you save Santa Claus!

This year I decided to take part in the challenge and brush up on some coding. Initially things were going quite well: I was keeping up on a daily basis. I never got into the competition aspect of the challenge given my time zone (except one day) and the problems were all very enjoyable. For those who are up at midnight GMT and are fast coders, you can get on the leaderboard and show off your speed coding skills as a plus. In the end I only made it just past halfway through, all excercises from the first to the 14th included, before I gave up due to lack of time:

Advent of Code 2019

Each day is divided into two parts and for each part you gain a star. The experience is also designed such that half of the problems are self contained, while the other half require you to have succesfully completed the previous problems allowing anyone to pick up mid way and have some fun while not giving an unfair advantage.

Each time you complete a problem you get given a star and a rank and you can see your progress and timing compared to the other players. Note my (not so good) 922nd place on day 10 part one! I never scored a single point though...

Ranks

As far as I'm aware I'm also the only person who used PHP as their programming language of choice. And with that I shall leave you with my solution for day one part one below...

// Run with php part1.php [input]
// If no input file is specified defaults to input.txt in local directory

$file = "input.txt";
if(isset($argv[1])) {
    $file = $argv[1];
}

if(file_exists($file)) {
    $handle = fopen($file, "r");
    $fuel = 0;
    while(($mass = fgets($handle)) !== false) {
        $fuel += (floor(floatval($mass) / 3) - 2);
    }
    fclose($handle);
    echo $fuel;
} else {
    exit("file does not exist.");
}

You can find part two and the other 13 days on my Github profile. Maybe one day I will finish the rest... and yes, PHP works fine.