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

Hex Ed — Python — #adventofcode Day 11

Today’s challenge is to help a program find its child process, which has become lost on a hexagonal grid. We need to follow the path taken by the child (given as input) and calculate the distance it is from home along with the furthest distance it has been at any point along the path. → Full code on GitHub !!! commentary I found this one quite interesting in that it was very quick to solve.

Read more...

Series: Advent of Code 2017

Knot Hash — Haskell — #adventofcode Day 10

Today’s challenge asks us to help a group of programs implement a (highly questionable) hashing algorithm that involves repeatedly reversing parts of a list of numbers. → Full code on GitHub !!! commentary I went with Haskell again today, because it’s the weekend so I have a bit more time, and I really enjoyed yesterday’s Haskell implementation. Today gave me the opportunity to explore the standard library a bit more, as well as lending itself nicely to being decomposed into smaller parts to be combined using higher-order functions.

Read more...

Series: Advent of Code 2017

Stream Processing — Haskell — #adventofcode Day 9

In today’s challenge we come across a stream that we need to cross. But of course, because we’re stuck inside a computer, it’s not water but data flowing past. The stream is too dangerous to cross until we’ve removed all the garbage, and to prove we can do that we have to calculate a score for the valid data “groups” and the number of garbage characters to remove. → Full code on GitHub

Read more...

Series: Advent of Code 2017

I Heard You Like Registers — Python — #adventofcode Day 8

Today’s challenge describes a simple instruction set for a CPU, incrementing and decrementing values in registers according to simple conditions. We have to interpret a stream of these instructions, and to prove that we’ve done so, give the highest value of any register, both at the end of the program and throughout the whole program. → Full code on GitHub !!! commentary This turned out to be a nice straightforward one to implement, as the instruction format was easily parsed by regular expression, and Python provides the eval function which made evaluating the conditions a doddle.

Read more...

Series: Advent of Code 2017

Recursive Circus — Ruby — #adventofcode Day 7

Today’s challenge introduces a set of processes balancing precariously on top of each other. We find them stuck and unable to get down because one of the processes is the wrong size, unbalancing the whole circus. Our job is to figure out the root from the input and then find the correct weight for the single incorrect process. → Full code on GitHub !!! commentary So I didn’t really intend to take a full polyglot approach to Advent of Code, but it turns out to have been quite fun, so I made a shortlist of languages to try.

Read more...

Series: Advent of Code 2017

Memory Reallocation — Python — #adventofcode Day 6

Today’s challenge asks us to follow a recipe for redistributing objects in memory that bears a striking resemblance to the rules of the African game Mancala. → Full code on GitHub !!! commentary When I was doing my MSci, one of our programming exercises was to write (in Haskell, IIRC) a program to play a Mancala variant called Oware, so this had a nice ring of nostalgia. Back to Python today: it's already become clear that it's by far my most fluent language, which makes sense as it's the only one I've used consistently since my schooldays.

Read more...

Series: Advent of Code 2017

A Maze of Twisty Trampolines — C++ — #adventofcode Day 5

Today’s challenge has us attempting to help the CPU escape from a maze of instructions. It’s not quite a Turing Machine, but it has that feeling of moving a read/write head up and down a tape acting on and changing the data found there. → Full code on GitHub !!! commentary I haven’t written anything in C++ for over a decade. It sounds like there have been lots of interesting developments in the language since then, with C++11, C++14 and the freshly finalised C++17 standards (built-in parallelism in the STL!

Read more...

Series: Advent of Code 2017

High Entropy Passphrases — Python — #adventofcode Day 4

Today’s challenge describes some simple rules supposedly intended to enforce the use of secure passwords. All we have to do is test a list of passphrase and identify which ones meet the rules. → Full code on GitHub !!! commentary Fearing that today might be as time-consuming as yesterday, I returned to Python and it’s hugely powerful “batteries-included” standard library. Thankfully this challenge was more straightforward, and I actually finished this before finishing day 3.

Read more...

Series: Advent of Code 2017

Spiral Memory — Go — #adventofcode Day 3

Today’s challenge requires us to perform some calculations on an “experimental memory layout”, with cells moving outwards from the centre of a square spiral (squiral?). → Full code on GitHub !!! commentary I’ve been wanting to try my hand at Go, the memory-safe, statically typed compiled language from Google for a while. Today’s challenge seemed a bit more mathematical in nature, meaning that I wouldn’t need too many advanced language features or knowledge of a standard library, so I thought I’d give it a “go”.

Read more...

Series: Advent of Code 2017

Corruption Checksum — Python — #adventofcode Day 2

Today’s challenge is to calculate a rather contrived “checksum” over a grid of numbers. → Full code on GitHub !!! commentary Today I went back to plain Python, and I didn’t do formal tests because only one test case was given for each part of the problem. I just got stuck in. I did write part 2 out in as nested `for` loops as an intermediate step to working out the generator expression.

Read more...

Series: Advent of Code 2017