23
๐ฌ - 2026 DAY 3 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
Part1 solution: For each line I generated an array of tree pairs by encoding the position of the first tree and distance to another tree as a comma seperated string. Eg.
#...#would be encoded as{"1,5"}and##..#would be{"1,2", "1,5"}. Then for each pair of trees I check ifrow - widthcontains a matching string.Part 1
Coming from C to Lua is a bit annoying, because a lot of the data structure is abstracted from you, so things don't always work how I expect them to.
Edit: finally finished part 2. My approach was to identify all the trees (a) that are equidistant from two other trees (b,c) AND have a third tree (d) that corresponds to the sum of the vectors to the other two trees. Then I check that
|a->d| == |b->c|then I think it is a square...ngl I found that quite challenging. Good thing I quit my day job.
Elapsed CPU time: 0.682239 seconds
solution