Advent Of Code

980 readers
21 users here now

An unofficial home for the advent of code community on programming.dev!

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.

AoC 2024

Solution Threads

M T W T F S S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 1 year ago
MODERATORS
1
 
 

Day 21: Keypad Conundrum

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

2
 
 

Advent of Code is an annual Advent calendar of small programming puzzles that can be solved in any programming language you like.

Puzzles have a backstory and then a collection of different inputs with people getting a random input and needing to submit the corresponding output for the puzzle and their input to successfully complete it.

Puzzles start easy and get harder as the days go on. Every day has two different puzzles in increase in difficulty with you getting access to the second puzzle after solving the first.

Puzzles are released every day at midnight ET and can be completed anytime after they are released (but people who solve them quicker after they're been released get more points for the site leaderboard).

https://adventofcode.com


What can I post here?

Anything relating to the event! Whether that be a meme, asking for help, sharing solutions, etc.

Every day a megathread will be posted that solutions to that day should go into. In the megathread you can post code using code blocks or by linking to repositories or pastebins.

To make a code block make three backticks, make a new line and put the code on lines, then put a newline and do three backticks on that

e.g.

```
console.log('Hello World')
```

becomes

console.log('Hello World')  

If you want a spot to post code externally (e.g. if it is too large or you want to have a spot to store it) we have a forgejo instance and an opengist instance

you can find them at https://git.programming.dev and https://blocks.programming.dev


How should I format my post titles?

Try to keep titles in this general format:

[help, etc. category if applicable] [YEAR Day # (Part X)] [programming language if applicable] Post Title

For example:

[2023 Day #5 (Part 3)] [Rust] My attempt at a solution

Another example:

[Help] [2023 Day #2] What does this sentence mean

This helps people avoid spoilers and lets people use it as an archive by searching if they find out about the event in the middle and are starting from the beginning

3
45
Programming.Dev AoC Leaderboard (self.advent_of_code)
submitted 1 year ago* (last edited 1 year ago) by Ategon to c/advent_of_code
 
 

Hey everyone! I set up a private leaderboard for the programming.dev community so we can have one for the community in addition to the global one

The leaderboard code is 3316962-6587d422

Looking forward to seeing you guys there! Ill make a post at the end with the top people on the leaderboard and the version on the site will auto update as people complete challenges


Full instructions on Joining the Leaderboard

  • Log in on https://adventofcode.com/ using one of the methods such as through GitHub
  • Go to the leaderboard section in the navbar
  • Click the private leaderboard button on the page
  • Enter 3316962-6587d422 into the text box for entering a leaderboard join code
  • Click join

Update: Ive made a new leaderboard so that I could rename it to something that isnt just my username, the code there is updated to the new one that should be joined

4
 
 

I was unable to upload even the shortest video because it was too long for my instance. Therefore, please enjoy the following:

  1. Partial visualization of test data. I cut this short because it took 40 seconds to do just a few (out of 81) paths: https://youtube.com/shorts/7UvzgSsMQNA
  2. Partial visualization of full data. I cut this short because I didn't want to wait 40 minutes. It's sped up 2x by making it 60fps (each step is approximately one frame) https://youtu.be/cv9qSdrV2Z4
  3. Full visualization, but it only shows the end paths, not individual steps: https://youtube.com/shorts/ozQ77ikI7JI

Unfortunately youtube is forcing my videos to be shorts due to aspect ratio and length, I don't know if I can force them to a regular video

5
 
 

Day 20: Race Condition

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

6
 
 

Day 19 - Linen Layout

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

7
 
 

I thought about it for 15 mins, but couldn't think of any mathematical tricks. I thought of lots of minor tricks, like comparing the number to the result and not adding any more multiplications if it's over, things that would cut 10%-20% here and there, but nothing which fundamentally changes big O running time.

For reference, here's my solution for part 2 in smalltalk. I just generated every possible permutation and tested it. Part 1 is similar, mainly I just used bit magic to avoid generating permutations.

(even if you haven't used it, smalltalk is fairly readable, everything is left to right, except in parens)

day7p2: in
	| input | 
	
	input := in lines collect: [ :l | (l splitOn: '\:|\s' asRegex) reject: #isEmpty thenCollect: #asInteger ].
	
	^ (input select: [ :line |
		(#(1 2 3) permutationsWithRepetitionsOfSize: line size - 2) 
			anySatisfy: [ :num | (self d7addmulcat: line ops: num) = (line at: 1)]
	]) sum: #first.
d7addmulcat: nums ops: ops
	| final |
	
	final := nums at: 2.
	ops withIndexDo: [ :op :i |
		op = 1 ifTrue: [ final := final * (nums at: i + 2) ].
		op = 2 ifTrue: [ final := final + (nums at: i + 2) ].
		op = 3 ifTrue: [ final := (final asString, (nums at: i+2) asString) asInteger ]
	].

	^ final
8
23
submitted 2 days ago* (last edited 2 days ago) by [email protected] to c/advent_of_code
 
 

I wanted to get an idea of how the blocks were landing and here's some thoughts on what I came up with:

  • they were building a simple maze (duh I guess).
  • the final (blocking) block is highlighted as a tiny red dot for half a second or so (edit: now flashing!).
  • my generated path jumped about seemingly at random even when blocks landed elsewhere so I don't animate the dropping of the first 1000 blocks as it's more noise than data.
  • the ~500 blocks before the final one don't affect my path at all, so it's quite a boring end.
  • Lemmy doesn't like long animations, so I skip 10 blocks at a time.

If you want to toast your CPU for a few seconds, here's some terrible Uiua code.

Data  ← ≡◇(⊜⋕⊸≠@,)°/$"_\n_" &fras "AOC2024day18.txt"
End   ← 70_70
Count ← 1024

D₄      ← [1_0 ¯1_0 0_1 0_¯1]
Valid   ← ▽¬⊸∊:▽⊸(≡/××⊃(≤⊢End|≥0))+D₄¤
BestLen ← ⍣(-1⧻⊢path(Valid|≍End)0_0↙:Data|∞)
Chop!   ← ◌⍢(⨬(⊙◌+1|⊙⊙◌:):⟜^0⌊÷2+,,|>)

BadBlock ← -1Chop!(=∞BestLen)Count ⧻Data
Skip     ← 1000
Step     ← 10
Times    ← ⍜(-Skip|⁅⍜(÷Step|⇡⌊))+1BadBlock

# paths - will ruthlessly spawn new threads until your CPU burns.
∵(×1_1_0)wait≡spawn(°⊚°□⊢path(Valid|≍End)0_0↙:Data)Times

¤∵(×0_0_1)⬚0+↯+1End0°⊚↙Skip Data           # old blocks
+:∵(×0_1_1)≡(⬚0+↯+1End0°⊚↘Skip↙)Times¤Data # add new blocks
≡+                                         # superimpose
⊂:⍜(⊡|⋅1_0_0) ⊡BadBlock Data⊣.             # Add frame for final block.
⍥(⊂:↙¯2.)10                                # Freeze frame.
≡(▽⟜≡▽4)                                   # Scale up.
&fwa "AOC2024day18.gif"gif 60
9
 
 

Day 18: Ram Run

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

10
 
 

Full input link (it's kinda cool ngl): https://youtu.be/Jw3CXcaHZ0Q

11
 
 

I'll start with what I do not mean by this question. I know you need to know programming and data structures, but what I am asking about is specific algorithms and theorems.

The ones I can enumerate now (edited after some answers):

Mega guide link

12
13
 
 
14
 
 

Full input version here: https://youtu.be/itc7_HZmewQ

This poor guard must the fittest person in 1518. Man's doing a marathon every day

15
 
 

Day 17: Chronospatial Computer

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

16
17
 
 

I had to stop for finals, so I'm way behind

18
 
 

Day 16: Reindeer Maze

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

19
 
 

Day 15: Warehouse Woes

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

20
5
submitted 1 week ago* (last edited 1 week ago) by Hammerheart to c/advent_of_code
 
 

So this is really kind of tangential, I am just messing around with the data and trying to at least nail down some basics so I can do sanity checks in my actual code. I am running into an odd discrepancy when trying to determine the number of times "XMAS" occurs in the input. I am only concerned with the straight forward matches, the instances of the substring "XMAS" appearing in the raw data.

When i do "grep -c XMAS input" or "rg -c XMAS input" they both show 107. But when I use regex101.com and search for the pattern XMAS, it shows 191 matches. Please help, I am truly at a loss here. While writing this, it occurred to me to just try using string.count("XMAS") in python on the data as a raw string, and it also returns 191. So really this question is more about grep and rp than anything. why are they only returning 107?

21
15
submitted 1 week ago* (last edited 1 week ago) by CameronDev to c/advent_of_code
 
 

Day 14: Restroom Redoubt

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

22
 
 
23
 
 

Day 13: Claw Contraption

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

24
 
 

Day 12: Garden Groups

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

25
 
 
view more: next ›