Saturday, 2018-12-01

Advent of Code 2018

This blog post is a work in progress

Project website: Advent of Code 2018.

Previous years: 2015, 2016, 2017.

I use Perl for all the solutions.

Most assume the input data is in a file called input.txt in the same directory as the file.

A note on scoring

I score my problems to mark where I’ve finished a solution myself or given up and looked for hints. A score of 2 means I solved both the daily problems myself, a score of 1 means I looked up a hint for one of the problems, and a zero score means I didn’t solve any of the problems myself.

My goals for this year (in descending order of priority):

  • match or beat last year’s score of 49/50.
  • solve all problems within 24 hours of release

Link to Github repo.


This year’s todo list:

  • Day 12 - rewrite part 2 to find the answer programmatically.
  • General - implement blogging and listing publication using templates
  • Day 8 - clean up and publish solution
  • Day 11 - faster solution

Day 1 - Day 2 - Day 3 - Day 4 - Day 5 - Day 6 - Day 7 - Day 8 - Day 9 - Day 10 - Day 11 - Day 12 - Day 13 - Day 14

Day 1 - Chronal Calibration

Day 1 - complete solution

Capsule summary:

Investigate the properties of summing an infinite list of integers.

A nice start to this year’s puzzles.

I had planned on getting up at 6AM to start with this but I spent the night before playing Fallout 4 so that didn’t happen.

Score: 2.

Day 2 - Inventory Management System

Day 2 - complete solution

Capsule summary:

Investigate the properties of the strings given as input.

Another O(n^2) solution, but for the small sizes involved it barely matters.

Perl’s string munging is helpful as always.

Score: 2.

Day 3 - No Matter How You Slice It

Day 3 - complete solution

Capsule summary:

Investigate the properties of overlapping areas given as input.

Nice and clean. I was worried I’d have to do some complicated lookups to single out the correct swatch in part 2, but it turns out that there was only one possible solution in my input.

Score: 2.

Day 4 - Repose Record

Day 4 - complete solution

Capsule summary:

Given a list of activities, determine properties about the times these activities occur.

Getting the correct answer without resorting to an external run through sort -n was the hardest part of this problem!

There are some nice solutions using a Schwartzian transform out there but to be honest I’d rather have something straightforward and dumb that can understood later.

TODO: better variable naming.

Score: 2.

Day 5 - Alchemical Reduction

Day 5 - complete solution

Capsule summary:

Remove elements from a list, based on rules on which neighbors an element has.

A quick and simple problem.

Score: 2.

Day 6 - Chronal Coordinates

Day 6 - complete solution

Capsule summary:

Investigate areas on a grid, expressed in Manhattan coordinates.

Keywords: Voronoi diagram

This took some careful perusal of the text and example to figure out. I had a lot of problems with my solution when I tried to merge part 1 and part 2 into one solution. Unfortunately I had overwritten the code that actually gave me the first star, and I broke it.

I felt justified to check out other solutions and finally re-wrote using those (essentially using a representation of the board to keep track of the data). The day after I took the time to re-write it again into a version closer to my original idea.

Runtime is a dismal 16s.

Score: 2.

Day 7 - The Sum of Its Parts

Day 7 - part 1 Day 7 - part 2

Capsule summary:

Find a path through a graph, given that some steps must be done to proceed.

Keywords: DAG, directed acyclic graph, topological sort

I’m really happy with solving this. I’m graph-aphasic, as in I’ve never ever grokked them in code, and was dreading finding some random Perl module that I didn’t really understand. In the end I just found the “endpoints” and processed it using a queue.

This made part 2 reasonably easy to code.

Score: 2.

Day 8 - Memory Maneuver

Day 8 - complete solution

Capsule summary:

Investigate the properties of a tree structure given in the form of a string of integers.

Keywords: tree structure, recursive

I had a lot of trouble with this, which wasn’t helped by stuff like people coming over to visit, dinner to cook and eat, and wine to drink. After these distractions were done with I could revisit the problem with fresh eyes.

Score: 2.

Day 9 - Marble Mania

Day 9 - complete solution

Capsule summary:

A game is played by placing marbles in a circle. Investigate the end state given the puzzle input.

Keywords: double-ended circular list

This was a fun problem that was marred by some irritating off-by-one errors in the results. We were blessed with a wealth of example inputs, and I could make most of them work by taking the largest or the next largest value. This gave me my second star, but it was hardly repeatable.

Double-checking my logic against other solution revealed I was thinking correctly, but had a stupid overrun where I managed to take more marbles than were actually available…

Runtime for part 2 is 30s, but you need quite a lot of memory to run it. My wimpy VPS cannot run it natively.

Score: 2.

Day 10 - The Stars Align

Day 10 - complete solution

Capsule summary:

Given a number of points, their positions and velocities, investigate whether they form a coherent message when printed.

Keywords: visualization

A nice palate-cleanser after the horrors of the week-end.

Runtime: 4.6s.

Score: 2.

Day 11 - Chronal Charge

Day 11 - complete solution

Capsule summary:

Investigate the values of subsquares on a 300x300 grid.

Keywords: summed-area table

Trying to solve part 2 using brute force took 173 minutes. Implementing a summed-area table reduced it to 3s.

Score: 2.

Day 12 - Subterranean Sustainability

Day 12 - part 1 Day 12 - part 2

Capsule summary:

A number of plants grow in an infinite line of pots. The existance of a plant for the next generation depends on its neighbors. Investigate what plants remain after a number of generations.

Keywords: cellular automata

This was a fiddly one. I got bit by the shallow copying nature of Perl’s data structures, but implementing the Clone module took care of that.

Then is was just a question of dealing with the inevitable off-by-one errors.

Part 2 was found by reasoning that the pattern would stabilize, and after that is was just a matter of finding the pattern and identifying the offsets.

My Part 1 code can either give the answer to the question with no input, or output some useful metadata if given another argument.

Part 2 answers the question by default, and gives the value for an arbitrary input if that’s given as an argument.

Score: 2.

Day 13 - Mine Cart Madness

Day 13 - complete solution

Capsule summary:

Carts move along a track with turns and junctions. Determine whether they collide.

I’m both proud and ashamed of this one. Proud because my basic code determining how the carts move was correct from the get-go. Ashamed because it took me all day to figure out the collision detection.

Runtime: 0.4s

Score: 2.

Day 14 - Chocolate Charts

Day 14 - part 1 Day 14 - part 2

Capsule summary:

A list is generated programmatically. Investigate its properties as it grows.

Keywords: pattern matching, brute force

Not my favorite problem, not least because my brute-force solution is killed by my VPS.

Runtime for part 2: 2m14s.

Score: 2.

Friday, 2018-11-30


The Rocks (Argyle St.)

Blue Liks Mars (Garnisonen)

Nov 2016 | Nov 2016 | Nov 2015 | Nov 2014 | Nov 2013 | Nov 2012 | Nov 2011

Saturday, 2018-11-10

A Trilogy of Trilogies: re-reading William Gibson


NeuromancerCount ZeroMona Lisa Overdrive


Virtual LightIdoruAll Tomorrow’s Parties

Blue Ant

Pattern RecognitionSpook CountryZero History

It’s hard to overstate the effect Gibson’s fiction had on me as a young person. While I never went as far as dressing as a cyberpunk (like some people I hung out with), the ideas and images from Neuromancer were permanently burned into my brain.

Re-reading all of these books on a holiday was instructive. I’ve re-read some of them multiple times (probably Count Zero most often, but I’ve only read Zero History once) and that makes it pretty easy to re-read quickly.

One thing that stands out is that while the Sprawl and Bridge trilogies have protagonists who are from the underclass of society, Blue Ant makes a sharp swing into the upper middle class for its main characters. This, in conjunction with them being in the employ of the unimaginably wealthy Hubertus Bigend, lead to the books resembling some sort of technothriller Sex in the City (except there’s very little actual sex).

I think Gibson realized this and the next novel The Peripheral returns to the theme of the underclass confronting tech and society.

I like the second books in each trilogy better than the first or third. Idoru especially is good with its discussion of celebrity culture.

Technology - Gibson is credited with inventing “cyberspace”, but the “shared consensual hallucination” as depicted in the Sprawl books makes no goddamn sense from a user perspective. It’s a bit like the famous “I know Unix!” scene in Jurassic Park - great eye candy for someone who doesn’t know how a computer works, but not really productive.

But there’s so much else in the Sprawl books that’s just there, standard SF for the time. Orbital space platforms. Super-fast SST planes. No global warming. Sure, the US seems to have collapsed and the Eastern Seaboard is one vast shantytown, but the reasons for that are more because Blade Runner is cool, not really explained. And people still smoke, and read papers, even if it’s delivered by fax.

And a secondary plot point - the ability to virtually inhabit someone else’s entire sensorium - is so far away from anything we have now, it’s not even funny. Come to think of it, so are orbital space stations.

Sadly as Gibson nears the “real world” in the later books, the tech gets less gee-wiz and more dated. Sure, cyberspace is useless but it’s so goddamn cool. The later books are instantly anchored in time with specific Apple products and forum software versions.

That’s why the earlier books have aged better. Sure it’s funny to point and laugh at the things Gibson “got wrong” - but why not see them as an alternate future that diverged sometime in the 1970s? (This is explored in Gibson’s short story “The Gernsback Continuum”, so it’s a propos.)

In summary, I actually think the Bridge trilogy is where Gibson is at his best - lucid writing, telling stories about hard-luck characters trying to do good in a crapsack world, and a great mix of plausible and sensawunda SF.

Wednesday, 2018-10-31

Wednesday, 2018-10-17

Photography exhibits 17 Oct 2018

My buddy Eugene was in Stockholm for business so we had a brew or two and saw some photography.

Robert Doisneau - Kulturhuset

A bit of a bait-and-switch - the poster prominently featured La Baiser de l’Hôtel de Ville but I suspect the arranging agency doesn’t have the rights to that nor his other more famous pictures. Instead we get some gentle views of the outskirts of Paris, many taken in the early 1940s during the German occupation.


Noémie Goudal - Stations

Huge prints of photographic collages with a strong graphical aspect. Impressive work.

Paul Hansen/Åsa Sjöström - Hand to Hand

Earnest reportage about the need for clean water and effective antibiotics.

Fotografiska Talent 2018

A selection of young(ish) Swedish photographers. Some good work, but a lot of suburban introspection too.

Lars Tunbjörk - Tunbjörklandet – blicken från sidan

The highlight. Tunbjörk was Sweden’s Martin Parr and his garishly lit visions of the absurdities of Swedish life in the 90s are haunting, funny, and affecting.

Tuesday, 2018-10-16

351: Hexagonal orchards

Reused code from 577 to bruteforce a sequence that I could search for in Sloane.

Monday, 2018-10-15

407: Idempotents

Got a good way just by observing patterns. Could have used Sloane to find a sequence but forgot about it. Resolved to be more thorough in the future.

Sunday, 2018-10-14

323: Bitwise-OR operations on random integers

I suck at probalities so had to google for an answer.

Friday, 2018-10-12

297: Zeckendorf Representation

I learned some extra stuff about Fibonacci numbers, that’s always fun.

Thursday, 2018-10-11

577: Counting hexagons

I enjoyed this one. As before I confirmed the sequence using brute force and geometry, then tried to search OEIS (Sloane) for sequences.

The geometry was tricky, so I was glad to finally pull it off.