RogerBW's Blog

Everybody Codes 2026 week 1 14 November 2026

Everybody Codes is now in its third year, and I've been doing it again, though I started a little late.

All of my code is on Codeberg.

Day 1

As one would expect, a nice easy start. My approach overall is to generate a list of valid target numbers, until the highest equals or exceeds the highest input number; then for each input number, find the lowest target that equals or exceeds that input, and add the difference between target and input to the total.

Part A: this is perfect squares, and since I feel like it I use the double-addition progression (initial value = 1, initial delta = 3, delta goes up by 2 each step). (Or calculate n².)

Part B: value = 4 × n.

Part C: this is mostly perfect squares, but missing out half of them. Basically the same code as part A, but initial value = 8, delta = 16, delta goes up by 8 each step. (Or calculate n²-1 and increment n by 2 of course.)

Day 2

Well now. This is a case in which recognising the nature of the problem solved it for me.

And the reason I was familiar with it comes from 2020, when for a few months I was doing the shopping, with a list supplied to me by my wife. Because, well, because I am me, I wanted to optimise the order in which I passed through the shop; I was fairly sure there must be a standard way of taking a set of information about how to order pairs of members of a set and turning that into an overall order. Sure enough, it's called topological sorting, and I implemented it in Perl to put my shopping lists into the most efficient order.

So I've done that before, and here I use the topological-sort module for Rust rather than doing it again. But that solves the entire problem all the way down to part 3; the only reason I changed my code at all was that I started with 32-bit integers, and that wasn't large enough for a checksum number for part 2.

As for parsing, I did it the lazy way: split each measurement on "<" or ">", parse the numbers on either side, and if it's "<" reverse them.

(I was expecting to discover in later parts that one measurement in the set was inconsistent, and I'd have to exclude each one in turn to find out which it was.)

Day 3

Ah, now that's an enjoyable three-parter!

The core of it is in part 1: parse the line, extract the digit sequences, and convert them to a final value. I use regular expressions, then split the captured strings to characters, convert those to digits, and reverse them (because I assume that standard number and number of digits won't always be the same length, and this way all the numbers at index 0 in the sequences are the ones dealing with position 0 (rightmost) in the input).

Then combine them. I borrow some standard integer exponentiation code, which as it turns out does the right thing for 0 to the power 0.

For part 2, rather than worry about wrapping the pointer into the standard, I simply double the standard's length until it is no shorter than the count. (Also go up to u64 integers from my initial u32.)

For part 3, there's probably a means of calculating the minimal representation, but I used a brute-force method. Build a sequence of digits of length equal to the count, then run through it, 0000, 0001, 0002, etc., checking for each one whether I have a value equal to the decoded count value. If I do, and the sequence is not the same as the count sequence, this number is invalid.

Day 4

Three quite distinct problems here, and the id value only ever got used as a key, not in the output.

Part 1: just extract id and time, and I can safely assume no duplicates.

Part 2: now I'm counting by parts, but again assuming no duplicates I don't actually have to parse them, just count them. Then a two-stage sort.

Part 3: a bit more chunky here, not to mention that I have to write a "places" function that caters for ties, such that I can for example assign [100, 100, 101] the place values [1, 1, 3]. Broadly:

Filter by quest and part.

Take each time, add it to previous times within this quest.

Assign points only to those who completed this part (not to everyone who has previously participated in this quest).

Rank those scores and assign points (based on the place value).

Next part, next quest.

Finally, rank the total points.

Day 5

I like to see problems that are like a well-known problem, but different. So if I had a high-level library for solving the well known thing, it wouldn't help; but knowing how that solution works does help.

In this case it's basically cellular automata and my main error was to use a vec of vecs as my grid structure. Better, as I've done before and as I did in part 3, to use a hashmap of i32 coordinate pairs.

Part 1: single growth loop, putting out land where (existing land + map shade) indicates it until it reaches stability.

Part 2: add a second growth loop, putting out sand.

Part 3: add an initial tree placement loop, and then two growth passes on that.

For each part I'm counting a different sort of cell value to get the final result.

The part 3 final layout is quite attractive:

Add A Comment

Your Name
Your Email
Your Comment

Note that I will only approve comments that relate to the blog post itself, not ones that relate only to previous comments. This is to ensure that the blog remains outside the scope of the UK's Online Safety Act (2023).

Your submission will be ignored if any field is left blank, but your email address will not be displayed. Comments will be processed through markdown.

Search
Archive
Tags 1920s 1930s 1940s 1950s 1960s 1970s 1980s 1990s 2000s 2010s 2300ad 3d printing action advent of code adventure aeronautics aikakirja anecdote animation anime army astronomy audio audio tech aviation base commerce battletech bayern beer boardgaming book of the week bookmonth chain of command children chris chronicle church of no redeeming virtues cold war comedy computing contemporary cornish smuggler cosmic encounter coup covid-19 crime crystal cthulhu eternal cycling dead of winter disaster doctor who documentary drama driving drone ecchi economics en garde espionage essen 2015 essen 2016 essen 2017 essen 2018 essen 2019 essen 2022 essen 2023 essen 2024 essen 2025 essen 2026 existential risk falklands war fandom fanfic fantasy feminism filk film firefly first world war flash point flight simulation food garmin drive gazebo genesys geocaching geodata gin gkp gurps gurps 101 gus harpoon historical history horror horrorm science fiction hugo 2014 hugo 2015 hugo 2016 hugo 2017 hugo 2018 hugo 2019 hugo 2020 hugo 2021 hugo 2022 hugo 2023 hugo 2024 hugo 2025 hugo 2026 hugo-nebula reread humour in brief avoid instrumented life javascript julian simpson julie enfield kickstarter kotlin learn to play leaving earth linux liquor lovecraftiana lua mecha men with beards mpd museum music mystery naval noir non-fiction one for the brow openscad opera parody paul temple perl perl weekly challenge photography podcast poetry politics postscript powers prediction privacy project woolsack pyracantha python quantum rail raku ranting raspberry pi reading reading boardgames social real life restaurant review reviews romance rpg a day rpgs ruby rust scala science fiction scythe second world war security shipwreck simutrans smartphone south atlantic war squaddies stationery steampunk stuarts suburbia superheroes suspense talon television the resistance the weekly challenge thirsty meeples thriller tin soldier torg toys trailers travel traveller type 26 type 31 type 45 typst vietnam war war wargaming weather wives and sweethearts writing about writing x-wing young adult
Special All book reviews, All film reviews
Produced by aikakirja v0.1