12
votes
Day 10: Cathode-Ray Tube
Today's problem description: https://adventofcode.com/2022/day/10
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
I initially found part 2's instructions a bit confusing, but this was a cute one.
Part 1
Part 2
Part 1, in Python-ish
Python code generated from the above
Part 2, in Python-ish
Python code generated from the above
the problem title appears to be missing from the tildes title today.
I usually edit it in once they get posted at midnight my time. I wasn't around though. It's done now.
ah! i assumed it was done automatically. thanks for doing this :)
No prob. My pleasure. :)
This was an alright one. I think most sheetheads™️ will have a similar set of formulas.
Part 1 and 2's inputs
This in G2 if you're playing along at home.
Part 1
Part 2
Merging a few columns, this will spit out the answer nicely, instead of spread out over a 6x40
Part 1
Part 2
At first I thought it was going to be a nightmare of off-by-ones, and decoding the timing, but it turned our to be really straightforward.
I wrote my own letter decoder which I use in my answer here, but of course I drew the screen as well to check the example given. Both are included.
Speedrun
Attempt 1: ~80% elapsed time
The obvious thing again is to calculate the cpu state once and use that to determine the screen and the signal strength.
Attempt 2: ~65-70% elapsed time
After a bit of thought, the signal strength can be calculated as the file is being read. This turned out to be conceptually simpler than I thought since the noop means we have to update the screen and potentially the signal strength, so always calculate those. If the instructions is an addx then update the screen and signal strength again for cycle + 1. I also changed the screen from a set of pixels co-ordinates to numbers since the cycle uniquely the co-ordinates.
Attempt 3: ~
20%33% elapsed timeI'm a dirty liar! I miscalculated the increase it's not 20% it's 33%.
Instead of keeping a set of on pixels, used a vector [240] and instead of using my slow-as-a-snail library to decode the string, use the vector to build up a full 40x6 string of pixels.
And here's my output:
Found this one pretty easy. I'm not a particularly fancy programmer, so my code tends to be pretty straightforward.
Parts 1 and 2
I just finished day 7 last night and figured I'd do 10 before 8 and 9 since it seemed fairly easy.
Well, part 1 was, but part 2's logic was confusing me for a bit... anyways.
nim (both parts)
Rust
Rust
Elixir
Fun with streams! First time I've used
Stream.transform/3
. A bit tricky, but it made my code to get the signal value at each cycle super concise.Both parts
This one I think I got a good handle on. I had some trouble with part 2 because I initially thought I would need to do something special to handle the order of events, but it turned out that didn't matter, but what did matter was me forgetting that upper bounds are non inclusive and also that formatting multiline strings can be hard.
Part 1 and 2, Python
I had black out from 9 Dec to 22 Dec, yeah. But Iʼll try to do something.
Python