13
๐ฝ - 2026 DAY 2 SOLUTIONS - ๐ฝ
(programming.dev)
An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!
Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
Everybody Codes is another collection of programming puzzles with seasonal events.
Solution Threads
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 |
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
console.log('Hello World')
Lua
For part one I created a linked list of the colours, then pointed the "next" value of the last node to the first node, so that I could call
node.nextforever. Other people used mod which seems like a much more sensible solution. Oh well at least I learned about linked lists in lua!usage
lua robots.lua < inputPart1
For part 2 I just counted how many times each colour appeared, then printed them out in the correct order. I learned that iterating over a table in Lua using
pairs(table)is non-deterministic because it is a implemented using hashes, so I had to have another table to explicitly store the order.usage:
lua rearrange.lua < input | lua robot.luaPart2
I also learned a valuable lesson in version control when attempting to use
teeto debug and deleted my entire solution.Deleting your solution just means you get to rewrite it more optimally :)