a blog about research communication & higher education & open culture & technology & making & librarianship & stuff

Fractal Art — Python — #adventofcode Day 21

Today’s challenge asks us to assist an artist building fractal patterns from a rulebook. → Full code on GitHub !!! commentary Another fairly straightforward algorithm: the really tricky part was breaking the pattern up into chunks and rejoining it again. I could probably have done that more efficiently, and would have needed to if I had to go for a few more iterations and the grid grows with every iteration and gets big fast.

Read more...

Series: Advent of Code 2017

Particle Swarm — Python — #adventofcode Day 20

Today’s challenge finds us simulating the movements of particles in space. → Full code on GitHub !!! commentary Back to Python for this one, another relatively straightforward simulation, although it’s easier to calculate the answer to part 1 than to simulate. import fileinput as fi import numpy as np import re First we parse the input into 3 2D arrays: using numpy enables us to do efficient arithmetic across the whole set of particles in one go.

Read more...

Series: Advent of Code 2017

A Series of Tubes — Rust — #adventofcode Day 19

Today’s challenge asks us to help a network packet find its way. → Full code on GitHub !!! commentary Today’s challenge was fairly straightforward, following an ASCII art path, so I thought I’d give Rust another try. I’m a bit behind on the blog posts, so I’m presenting the code below without any further commentary. I’m not really convinced this is good idiomatic Rust, and it was interesting turning a set of strings into a 2D array of characters because there are both u8 (byte) and char types to deal with.

Read more...

Series: Advent of Code 2017

Duet — Haskell — #adventofcode Day 18

Today’s challenge introduces a type of simplified assembly language that includes instructions for message-passing. First we have to simulate a single program (after humorously misinterpreting the snd and rcv instructions as “sound” and “recover”), but then we have to simulate two concurrent processes and the message passing between them. → Full code on GitHub !!! commentary Well, I really learned a lot from this one! I wanted to get to grips with more complex stuff in Haskell and this challenge seemed like an excellent opportunity to figure out a) parsing with the parsec library and b) using the State monad to keep the state of the simulator.

Read more...

Series: Advent of Code 2017

Spinlock — Rust/Python — #adventofcode Day 17

In today’s challenge we deal with a monstrous whirlwind of a program, eating up CPU and memory in equal measure. → Full code on GitHub (and Python driver script) !!! commentary One of the things I wanted from AoC was an opportunity to try out some popular languages that I don’t currently know, including the memory-safe, strongly-typed compiled languages Go and Rust. Realistically though, I’m likely to continue doing most of my programming in Python, and use one of these other languages when it has better tools or I need the extra speed.

Read more...

Series: Advent of Code 2017

Permutation Promenade — Julia — #adventofcode Day 16

Today’s challenge rather appeals to me as a folk dancer, because it describes a set of instructions for a dance and asks us to work out the positions of the dancing programs after each run through the dance. → Full code on GitHub !!! commentary So, part 1 is pretty straight forward: parse the set of instructions, interpret them and keep track of the dancer positions as you go. One time through the dance.

Read more...

Series: Advent of Code 2017

Dueling Generators — Rust — #adventofcode Day 15

Today’s challenge introduces two pseudo-random number generators which are trying to agree on a series of numbers. We play the part of the “judge”, counting the number of times their numbers agree in the lowest 16 bits. → Full code on GitHub Ever since I used Go to solve day 3, I’ve had a hankering to try the other new kid on the memory-safe compiled language block, Rust. I found it a bit intimidating at first because the syntax wasn’t as close to the C/C++ I’m familiar with and there are quite a few concepts unique to Rust, like the use of traits.

Read more...

Series: Advent of Code 2017

Disk Defragmentation — Haskell — #adventofcode Day 14

Today’s challenge has us helping a disk defragmentation program by identifying contiguous regions of used sectors on a 2D disk. → Full code on GitHub !!! commentary Wow, today’s challenge had a pretty steep learning curve. Day 14 was the first to directly reuse code from a previous day: the “knot hash” from day 10. I solved day 10 in Haskell, so I thought it would be easier to stick with Haskell for today as well.

Read more...

Series: Advent of Code 2017

Packet Scanners — Haskell — #adventofcode Day 13

Today’s challenge requires us to sneak past a firewall made up of a series of scanners. → Full code on GitHub !!! commentary I wasn’t really thinking straight when I solved this challenge. I got a solution without too much trouble, but I ended up simulating the step-by-step movement of the scanners. I finally realised that I could calculate whether or not a given scanner was safe at a given time directly with modular arithmetic, and it bugged me so much that I reimplemented the solution.

Read more...

Series: Advent of Code 2017

Digital Plumber — Python — #adventofcode Day 12

Today’s challenge has us helping a village of programs who are unable to communicate. We have a list of the the communication channels between their houses, and need to sort them out into groups such that we know that each program can communicate with others in its own group but not any others. Then we have to calculate the size of the group containing program 0 and the total number of groups.

Read more...

Series: Advent of Code 2017