Closeup of neatly stacked AA batteries, one of them pokes out

Day 3: Lobby

Note: If you’re attempting to read this as a Fediverse post, you might find it rather confusing. I recommend using a web browser to read it properly, following this link.

The challenge

Today we were given a list of integer numbers, like 19874, 20001, 89089, …

The task was to pick out two digits of each number and combine them, preserving their order forming the largest possible 2-digit number and to add them all up. Here, this would be 98, 21, 99, …

The idea

Remember that you can’t use the number’s last digit for picking the result’s first. So, we pick the first occurrence of the largest digit, store it and then take the largest digit from its position position forward, combine the two, and we’re done.

Perl code
https://codeberg.org/M1na/AOC25/src/branch/main/aoc2503a.pl

The updated challenge

Do the same, but picking 12 digits instead of 2.

The updated idea

Basically the same as before, but 12 times.

The nice thing about Perl is that you can use integer arithmetics and string operations on the same data.

Perl code
https://codeberg.org/M1na/AOC25/src/branch/main/aoc2503b.pl
Fediverse Reactions

Comments

2 responses to “Day 3: Lobby”

  1. @AdventOfCode The `for (-11 .. 0)` bit is really nice!

    1. @chris_evelyn

      Actually, at first, I fiddled a bit with the indices in the string.

      This has been a problem of mine forever.

      @AdventOfCode

Leave a Reply

Your email address will not be published. Required fields are marked *