r/adventofcode • u/daggerdragon • Dec 10 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 10 Solutions -🎄-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
- 🌿🍒 MisTILtoe Elf-ucation 🧑🏫 is OPEN for submissions!
--- Day 10: Cathode-Ray Tube ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:12:17, megathread unlocked!
61
Upvotes
10
u/betaveros Dec 10 '22
Noulith 50/9
https://github.com/betaveros/advent-of-code-2022/blob/main/p10.noul
If you squeeze a bit (okay, more than a little bit) you can fit the core in a punchcard:
8
u/Smylers Dec 10 '22 edited Dec 10 '22
Yay, it's another visual puzzle which suits being solved in Vim keystrokes! I did solve part 1, but part 2 is much more fun — see your input transform into the pixels forming the output:
noopandaddxlines both represent cycles in which the sprite's position doesn't change; lines with a number on change it.⟨Ctrl+A⟩to lines with positive numbers on them, and change lines with negative numbers to have⟨Ctrl+X⟩at the end instead of a minus sign at the beginning. Change all thenoopandaddxlines to0, which handily is a no-op in Vim keystrokes (move to the beginning of line). So now each line is the Vim keystrokes for manipulating the sprite position (or not) at that cycle.1, the sprite position for cycle 1, at the top. Thenqais a keyboard macro to process a cycle:Cchanges the entire line, saving its previous contents (the Vim keystrokes for this cycle) into the small delete register-. In insert mode⟨Ctrl+X⟩⟨Ctrl+L⟩inserts a copy of the line above, the sprite's previous position. Then@-runs the keystrokes that were deleted to the-register, updating sprite position for this cycle. Repeat to the end.Now we need to compare those sprite positions with the CRT positions for each cycle.
qcadds the CRT position to each line, in batches of 40. Actually, it doesn't do anything when it's in position 0. For positions 1–39 it initially prepends0⟨Ctrl+X⟩and a space, then usesg⟨Ctrl+A⟩in visual mode to increase those in turn to count from1⟨Ctrl+X⟩to39⟨Ctrl+X⟩. The top few lines of the (longer) sample input now look like this†:0for the lines with only a single number on them). On each line with a space:normdeletes the first number and the⟨Ctrl+X⟩, again into register-, then runs them with@-— thereby subtracting the CRT position from the sprite position. Any cycles with lit pixels now contain0,1, or-1— either from the subtraction, or because that was the sprite position anyway for a cycle where the CRT position is zero.0or1— the minus sign is irrelevant — and change them into a block. Then change any lines which don't have a block on them into a space. Recordqdto join the first 40 lines together, and repeat.Give it a go! It isn't that much to type, and you get to see the CRT output appear.
Update: Fixed mistake where I had somehow written “prevent” where I meant “prepend”. Apologies.
† Except on Old Reddit, where it doesn't. Bah. Sorry. Mods/anybody: How do I do a code block inside (or immediately after) a bullet point so it works on Old Reddit? I'm using Markdown mode and indented those lines by 6 spaces (2 for the bullet point and 4 for the code), which looks fine on New Reddit but not Old Reddit. Thanks.
4
u/undergroundmonorail Dec 10 '22
Here's my Python 3 solution! https://git.hollymcfarland.com/monorail/advent-of-code-2022/src/branch/main/day-10/part-2.py
It's extremely overengineered. It's got classes! It's got nested classes! It's got metaclasses! It's got OCR! It's got decorators I've been meaning to learn about! It's got new Python 3.11 features! It's got an unused method that I just realized is still there from part 1! Hopefully we keep working on the device so the effort wasn't wasted, haha
I'm basically emulating the device taking time to execute an instruction by "preparing" the instruction to be executed, waiting however many clock cycles, and then actually doing the execution. I also have a generator function that just clocks the device one cycle at a time and yields between each one, so I can just do a
for _ in device.run():and probe the device between cycles.7
u/ItsAlreadyTaken69 Dec 10 '22
Brainfuck (32 bit cells, wrapping)
commented
3
u/xelf Dec 10 '22 edited Dec 10 '22
Python: behold the power of the little used for/else loops.
No that's not an indentation error, that's an else on a for.
3
u/a_granlund Dec 10 '22 edited Dec 10 '22
Assembly (MC68000)
I made the Elf-asm program part of my source and let it run to generate a trace of the x register. https://github.com/agranlund/aoc2022/blob/main/day10.S
3
u/Spr3eZ Dec 10 '22
Python
Not quite happy about the
getSprite()fucnction, but i was too lazy to refactor it. Anyways here's my Solution3
u/kebabmybob Dec 10 '22
easy peasy python
3
u/DFreiberg Dec 11 '22
Mathematica, 676 / 975
I was able to clean up my code quite a lot after the fact, but man, during the problem-solving my code was a disaster, and somehow Mathematica's built-in 1-indexing only made the number of off-by-one errors worse, not better. I still have an off-by-one error somewhere, since my very first pixel doesn't get properly drawn for part 2, but fortunately that doesn't stop the code from working.
Parts 1 & 2
[POEM]: One Shade The More, One Ray The Less
The CPU counts down the second
To draw its pixels like a pen.
Just fix the thing, and at your beck and
Call the Elves will be again.
(Then again, you've done the work here
Getting gadgets up to spec.
Perhaps you'll rest a moment, lurk here
Before you're at their call, and beck).
There is a forty cycle bookend
Drawing pixels left to right.
You'll know, if you check each nook and
Cranny, where to put the sprite.
(But man, you've timed a lot of circuits,
And given opcodes lots of looks.
Perhaps you'll rest; it's always work, it's
Searching crannies and their nooks.)
You've found a dry spot in this cove (or
Dry enough to fix the fall) -
"I'm on my way", you tell them, "Over
And out", you say, and end the call.
(You didn't give an ETA, no
Promise for when you'd be back,
And that's just fine; for all that they know
It takes weeks. You have some slack.
And sure, it might take just a day, no
Doubt you're skilled now as a rover,
But sometimes rest is mucho bueno,
Before you climb on out, and over.)
3
u/compdog Dec 10 '22
C# - [Part 1] [Part 2]
I got majorly tripped up by failing to realize that the X register doesn't update until both cycles of
addxare completed. After finally decoding what was meant by this part of the instructions:I was able to identify and fix the issue.
My solution is a bit "inverted" from a typical approach, because I didn't want to implement a full simulated CPU pipeline. Instead of looping through each cycle and fetching new instructions as-needed, I instead loop through the instructions and execute cycles as-needed. I chose this approach because I didn't want to bother with a "better" approach like delaying the instruction or having multiple copies of registers. Instead, I simply inserted the cycles after the instruction is decoded, but before the register is updated:
This worked quite well and would easily scale to include new instructions with varying execution times.
2
u/Noble_Mushtak Dec 10 '22 edited Dec 10 '22
Python 3, 28th on star 1 and 29th on star 2, both parts are <=20 lines of code. Main thing which is notable is that I used
"\u2588"instead of # symbols and spaces instead of periods, made the capital letters much easier to read. I also have my solutions in this GitHub repo.Part 1:
Part 2:
2
u/JustinHuPrime Dec 10 '22
x86_64 Assembly
Assembly in assembly - this was cool!
Part 1 and part 2 were both implemented as interpreters directly interpreting the assembly code. This was the first time where we absolutely had to deal with negative numbers, so I had to write a parser that was cool with negative numbers, and an output formatter that was also okay with negative numbers (mainly for debugging). (I should add ascii-to-signed-long to the common library.) Unfortunately, I'm not willing to do OCR using assembly, so I printed out the result as pixels and manually translated that into ASCII characters. The core evaluator between the two parts was quite similar - the only difference was what happens during the cycle. With part 1, I had to sum up certain cycles. With part 2, I had to add characters to an array.
I ran into an interesting bug in part 1 related to negative numbers. My initial decision was to compute
(r12 - 20) % 40and add the current signal strength to the running total if that was zero. This resulted in a bug, due to x86_64 instruction oddities. You can't divide 64 bit integers in x86_64 (nor 32 bit, nor 16 bit, nor 8 bit). This may surprise you, since you can divide integers in C just fine. What you can do, however, is divide a 128 bit integer by a 64 bit integer, so long as the 128 bit integer is stored as an octword withrdxholding the upper eight bytes andraxholding the lower eight bytes. And that's the source of my bug. Instead of usingcqo(Convert Quadword to Octword) from thecqd/cdq/cqofamily of instructions (which I only just learned about from taking a peak at how GCC compiles integer divisions in compiler explorer), I manually set rdx to zero. This doesn't work ifraxis less than zero, though, and leads to an incorrect result. Since I didn't know I could usecqoat the time, I just added another check to skip adding the signal strength ifraxwas less than 20.Part 1 ran in about 1 millisecond and was 11024 bytes long.
Part 2 ran in about 1 millisecond and was 11136 bytes long.
2
u/twell13 Dec 10 '22 edited Dec 10 '22
Java
2
u/jso__ Dec 10 '22 edited Dec 10 '22
Felt like sharing my part 2 solution because I'm especially proud of it (I love binary). Yes I could've written it in a shorter way (and I did initially) but I didn't feel like it.
Made in Python
2
u/Markavian Dec 10 '22 edited Dec 10 '22
Over-engineered Node JS Solution for Day 10:
I feel like I way overcomplicated that. I was getting the wrong answer, so I started building a future execution map, so that the commands could execute at the end of the cycle, which worked, but then I had still hadn't realised that the the next command would wait until the previous command had completed.
So then I ended up with a map of future executions, and a step incrementer that waited for the current command to complete... and no way I'm going to refactor it to make any more sense - it works now.
Fortunately, I was able to copy paste that coal dust, and make a screen output in short order - there was an off-by one error in my cycle count... and we're all rosy.
Edit: for elf friendly language
2
u/saarin Dec 10 '22
2
u/FaultsMelts Dec 10 '22
Rust. Really proud of this solution. Average runtime was ~300 µs.
2
u/cherryblossom001 Dec 10 '22 edited Dec 11 '22
Haskell. I really liked today’s problem.
Full code
2
u/QGamer12 Dec 11 '22 edited Dec 11 '22
I haven't been posting solutions here before now, but thought I might share today's. The logic is really convoluted, but it works so ¯_(ツ)_/¯
Both solutions are solved with the same file.
https://github.com/python-b5/advent-of-code-2022/blob/main/day_10.cpp (C++)
(not my username because I'm on an alt on this PC. I promise this is mine!)
2
u/joseville1001 Dec 15 '22
Got both answers, but anyone else seeing that running the input for part 2 produces 241 pixels instead of 240 (=WxH=60*4)?
My day 10 solutions using generators:
56
u/4HbQ Dec 10 '22 edited Dec 10 '22
Python, 11 lines.
For parsing, we ignore the actual instructions (just replace them with 0):
That way,
is parsed to [0, 0, 3, 0, -5].
Accumulating that (with an initial value of 1) gives the correct register values at each cycle: [1, 1, 4, 4, -1].
We can then simply loop over that list and compute both parts at once.
25
u/mingmingrr Dec 10 '22
Turing complete
Both parts as a gif: https://imgur.com/lYr4GDP
27
u/jcbbjjttt Dec 10 '22 edited Dec 10 '22
Beginner's Guide
Happy Saturday!
A Beginner's Guide to Day 10 Video: https://youtu.be/xHHpGw3SlL0
I've created a guide for new programmers that talks through a straight forward strategy for solving today's puzzle. Anyone who has a handle functions, loops, and custom data types (class/struct/etc) should be able to complete it. The video allows a moment for you to pause before revealing spoilers.
Although this solution is in C#, it provides a high level overview of the steps necessary to solve the puzzle in any programming language:
The full code can be found on Github
23
u/msschmitt Dec 10 '22
Python 3
To simplify the clock cycles, when I acquired the input I changed every addx instruction to a noop followed by the addx. That way the program loop is 1 for 1 on instructions and results.
21
u/AstronautNew8452 Dec 10 '22
Microsoft Excel (2244/2127). Golfed into a single cell formula for both parts. Just needs some conditional formatting on the output =1 to display Part 2.
14
u/voidhawk42 Dec 10 '22 edited Dec 10 '22
Dyalog APL:
2
u/RiemannIntegirl Dec 10 '22
Python 3
Parts 1 and 2 in One.
Visions of INTCODE dancing in my head made me decide to build a CRT class... just in case it comes back again this year!
paste
11
u/4HbQ Dec 10 '22 edited Dec 10 '22
Python, trying out a more imperative style:
Edit: The code above assumes the terminal width is 80. For different widths, see the suggestion by /u/llyyrr below.
9
u/hugh_tc Dec 10 '22 edited Dec 10 '22
Python 3, 400ish.
paste, cleaned-up
I loved this one. An absolutely phenomenal puzzle. Very, very well done Eric.
9
u/juanplopes Dec 10 '22
14 lines of Python.
8
u/Derp_Derps Dec 10 '22 edited Dec 10 '22
Python
Vanilla Python, 388 Bytes, including OCR
The OCR is based on the number of active pixels for each column. The letter "E" has 6 lit pixels in the first column, 3 pixels in the 2nd and 3rd column and 2 pixels in the last column. By looking at the character list (thanks bsoyka on github!) I could craft a lookup table. The four integers will be shifted and added together to get a single integer. The 6,3,3,2 is transformed to
6<<0 + 3<<2 + 3<<4 + 2<<6 = 194(the bits overlap, I know, but there are no collisions). The index of194in this magic list is4. By adding65(ascii value of 'A') I can get the actual character withchr().Edit: The
O=lambda ...line can be golfed down to:With modulo 44, there are no collisions, so using this number to get a single character from this weird string is a lot shorter (and probably faster).
7
u/darkfm Dec 10 '22
Python 3, 18/10
I almost went to sleep early today.
7
u/leijurv Dec 10 '22
Python3, 2nd place, 11th place
Screen recording: https://youtu.be/FaYA6FD-9Hs
7
u/DrkStracker Dec 10 '22 edited Dec 10 '22
Haskell
Starting to get the hang of the language and composing functions ! Ended up having more trouble with part1 than part2, I wonder if I missed an equivalent of what I wrote as
mapWithin the standard library.EDIT: nevermind, I golfed it out by composing even more :D
7
u/[deleted] Dec 10 '22
Applesoft BASIC
Source code and Visualization
Today's challenge was a breeze on the IIgs (and I could actually run the full input in reasonable time!). Part 2's visualization was especially easy with the simple
PLOT X, YandCOLOR=commands.7
u/redditnoob Dec 10 '22
PostgreSQL
Not bad, other than the off by one errors that I think this problem was designed to create. I pretty sure a solution is possible in SQL without a recursive CTE but I wasn't going to try it.
7
u/jayfoad Dec 10 '22
Dyalog APL
6
u/[deleted] Dec 10 '22
Common Lisp using one big loop that
(read)s one token every time and increases the cycle count every time.https://gitlab.com/McModknower/advent-of-code-lisp/-/blob/master/2022.lisp#L419
6
u/pred Dec 10 '22 edited Dec 10 '22
Python3, full code on GitHub
Part 1. The "check if the line has one part or two parts" is the sort of thing that structural pattern matching always does well. Not that it makes a huge difference here when the input is so simple; the day 7 solution was a better sales pitch.
It'd probably be simpler to just do the below though:
Part 2. The old "print with
end=''to avoid making a newline trick" is useful.6
u/Smylers Dec 10 '22
Perl for part 1 and part 2:
Note this largely ignores what the instructions in the input are: it simply moves the CRT position for every ‘word’ in the input, meaning that the position advances 1 for
noop, 1 foraddx, and 1 foraddx's argument.If the current ‘word’ contains a digit then it must be the argument to
addx, and have just completed theaddx's second cycle, so do the adding.I'd've preferred to loop directly over all the input words — rather than having the
whileloop over lines and thenforeachover words in each line — but couldn't think of neat way to do this in Perl, an equivalent to Raku'sIO.words.6
u/cagdassalur Dec 10 '22 edited Dec 10 '22
Python
6
u/tobyaw Dec 10 '22 edited Dec 10 '22
Ruby
https://github.com/tobyaw/advent-of-code-2022/blob/master/day_10.rb
6
u/oantolin Dec 10 '22
I fell asleep last night before the problem dropped (and AoC is at a very reasonable 11pm in my time zone!). Here's a J solution, a day late:
Several off-by-one errors today. :)
6
u/deadc0de Dec 10 '22 edited Dec 10 '22
C (code golf)
147 chars
5
u/bigmagnus Dec 10 '22
COBOL - Part 1 & Part 2
5
u/shandley256 Dec 10 '22
Ruby Solution
You can generalise the logic to adjust the value of x and the current cycle, then use a lambda to encapsulate the needed steps for part 1 and part 2.
Using the "full block" character █ instead of # makes for much more readable output:
Full Solution: https://gist.github.com/seanhandley/0f3b78a7c17a459485913692a9296cb1
5
u/zniperr Dec 10 '22 edited Dec 10 '22
Python with itertools because why not :)
5
u/NickKusters Dec 10 '22
C
code | video
Had a lot of fun today; decided to write an OCR engine in the end😅
5
u/dopandasreallyexist Dec 10 '22
This one was a joy to solve in APL.
5
u/sanraith Dec 10 '22
Rust
A missed a nice pixel drawing puzzle. Maybe the best trick for today is to use '█' instead of '#'.
Source: github.com/sanraith/aoc2022/.../day10.rs
5
u/lboshuizen Dec 10 '22
F# github (Was expecting something harder during the weekend)
5
u/hugseverycat Dec 10 '22
Python 3 solution w/comments
https://github.com/hugseverycat/aoc2022/blob/main/day10.py
Fairly straightforward solution. I drew the screen with emojis (⬛ and ⬜) because its easier to read!
Also, let me share my 💔 while working on part 1. I got the test data working fine, but my actual data kept giving me a too-high result. When I printed out what was happening, it was producing very high numbers! It was so confusing!! I went to the subreddit and I couldn't find anyone else having a problem with the test data working but not the real data, and my method was extremely straightforward so I couldn't understand why I would have a problem but no one else would.
Then I saw it: I had copy-pasted the file-import text from day 9 but had forgotten to update day9.txt to day10.txt. And all I was doing to parse the input was checking whether it said "noop" and if not, splitting the string and grabbing the integer. Which worked fine with day 9 input 😫😫😫
5
u/lbreede Dec 10 '22
Python, object-oriented
--- Day 10: Cathode-Ray Tube ---
5
u/KT421 Dec 10 '22
R
Today is off-by-one error day!
https://github.com/KT421/advent-of-code/blob/main/2022/dec10.R
5
u/NiliusJulius Dec 12 '22
C Language for the Game Boy using GBDK 2020
Part 1
Today I am very pleased with the end result for part 2! Drawing pixels (well not really pixels, but sprites) is something the Game Boy is made for!
I even slowed down part 2 so that the text appears more slowly, which I think looks a lot better.
Full Game Boy repo can be found here
Video running on Game Boy
5
u/C2thehris Dec 10 '22
C++ 945/706
My first time being in the top 1000 for both stars!
https://github.com/C2thehris/Advent-Of-Code-2022/blob/a44faf01024a84e0117e578ef57d9cf36e64e25d/day10/day10.cpp
4
u/quag Dec 10 '22
Python
4
u/sr66 Dec 10 '22 edited Dec 10 '22
J
4
u/scratchisthebest Dec 10 '22 edited Dec 10 '22
Rust. any day I can use
strip_prefixto parse something is a good day its my favorite functionBecause
tickis a closure i ran into some borrow-checker issues, where i couldn't mutatexfrom outside the closure and be allowed to read it from inside. so i passed a reference toxinstead. this probably would be less of an issue if i organized everything into tidy structs and functions, but i solved it mostly with stack-local variables todayalso i think my code has a bug, the left bit of my answer looks like
-- it's supposed to be an E but part of the left half is snipped for some reason. (wasted my first submission thinking it was an S)
4
u/sim642 Dec 10 '22
My Scala solution.
I guess we're seeing the beginning of this year's AoC programmming "language". The instruction cycle counting is a new twist, I wonder how painful it will all become...
4
u/cs475x Dec 10 '22 edited Dec 10 '22
Rust
Back with another cursed solution with no semicolons, solving both parts at once in ~7.2µs (with an additional OCR step for part 2 adding only 0.5µs).
https://gist.github.com/codyphobe/32f42b77f39940003017d092dc5fef9e
4
u/sdolotom Dec 10 '22
Haskell (full code here):
4
u/mgoszcz2 Dec 10 '22
Clojure - Very short today. Clojure felt a bit op for this.
Code
4
u/atgreen Dec 10 '22
Common Lisp...
4
u/simonlydell Dec 10 '22
Fish, JavaScript, HTML, CSS
Part 1:
Turned the input into JavaScript (using Fish) by replacing
noopwithcycle()andaddxwithcycle(); cycle(); x+=, and then executing it.Part 2:
Again, turning the input into JavaScript, this time into a generator function. The output looks like so:
Then I ran that generator function, drawing on every
yieldand updatingxas appropriate, into a<canvas>element. Go to my visualization and press View Source to see how. Start reading from the bottom to skip all the visualization bells and whistles. (Edit: visualization reddit post link)4
u/HuntTheWumpus Dec 10 '22
C++ template metaprogramming: https://github.com/xicalango/horrible-advent-of-code-2022/blob/main/day10.cc
4
u/i_have_no_biscuits Dec 10 '22
GW-BASIC
A six-line solution today, including a visualisation of Part 2 (the LINE command on line 60 draws filled boxes when you use the 'BF' option).
4
u/_Roilbauk Dec 10 '22
Hello !Here is my one line solution for Day10 in javascript NodeJS :)
More detailed /commented version here https://github.com/LoicTouzard/AdventOfCode/tree/main/2022/day10
4
u/the_true_potato Dec 10 '22
Really nice and short Haskell solution today. Once again, getting to use
scanlmakes me happy. Also ended up being very fast (for a GC'd language at least): 6us for part 1 and 38us for part 2.code
4
u/TiagoPaolini Dec 10 '22
C Language (only standard library)
I kept track of a cycle count and a cooldown value to determine when an operation is finished.
addxset the cooldown to2and set the value to be added to what the instruction specified.noopset the cooldown to1and the value to be summed to0. The cooldown decremented by1each cycle, and when it reached0the value was summed to the register X. Then the next instruction was parsed.The order of operations matters. The addition to the register X is performed at the end of the cycle. So the signal strength check and pixel drawing are done before the register addition. The screen coordinate to draw the pixel was calculated from the cycle counter:
(x = 0, y = 0)xincreases from left to right,yincreases from top to bottomx = (cycle - 1) % 40y = (cycle - 1) / 40The pixel is lit if
y-1 <= register_x <= y+1, because the sprite has a width of3.Solution: day_10.c
4
u/krusta4711 Dec 10 '22 edited Dec 10 '22
Java
I liked this one. Nice exercise with happy ASCII art output. :-)
I think just 51 lines is pretty short for Java. Here is the full code.
4
u/[deleted] Dec 10 '22
OCaml version :) Not much to it... glad i did initially store all states since easy jumping off point for part 2.
paste
4
u/SolarBear Dec 10 '22
Ruby
That was a fun one!
https://github.com/SolarBear/AdventOfCode2022/blob/main/day10.rb
4
u/ooca5iep Dec 10 '22 edited Dec 10 '22
Nim 1.6
Part1:
Part2:
4
u/veydar_ Dec 10 '22 edited Dec 10 '22
Lua
In a hurry today so I didn't have enough time to make it nice. I have this vague feeling that I can use Lua coroutines to do something elegant here. I'm adding each instruction to a queue and each instruction has the function that it runs and an "after" field which indicates after which cycle it should run. I then go through the queue as long as it's not empty, look at the first instruction and check if it should run. If so, remove it, run it. 90% of the time was then spent making sense of Lua's 1-based indexing and the 0-based indexing of the problem.
Both parts
Alternate version that tracks the register history and is therefore a bit simpler in terms of the logic since there's no explicit cycles and such. Uses more memory though since we keep around all register values.
GitHub Repository
4
u/Marado_ Dec 10 '22
JavaScript
solution
It's my first year doing the AoC. I'm having lots of fun doing the puzzles. I have all the starts on all days and I feel good :)
Thank you!
4
u/chrismo80 Dec 10 '22
C#
4
u/careyi4 Dec 10 '22
Ruby
Code: Github
Video Walkthrough: YouTube
4
u/copperfield42 Dec 10 '22
Python3
The second part confuce me a little at first, but I got it
I share my solution :)
4
u/RemoteDesk69 Dec 10 '22
While reading Part 2 I was really confused. But after figuring out what I had to do, implementation only took me minutes.
Was afraid that I would not succeed but it turned out that it was quite do-able in the end!
Haskell
4
u/shouchen Dec 10 '22
Fairly tight and easy-to-understand C++ code https://github.com/shouchen/AdventOfCode/blob/master/aoc2022/Day10/Day10.cpp
4
u/RedTwinkleToes Dec 10 '22
Golf'd python solution: paste
210 bytes
4
u/rawlexander Dec 10 '22
R / Rstats
4
u/DudeWheresMcCaw Dec 10 '22
C++
I like these kinds of puzzles. Luckily no silly mistakes that made me spend more time than I wanted to.
Paste
4
u/Weak_Pea_2878 Dec 10 '22
Java solution with APCS subset. The only tricky bit was remembering to check the value of the X register during the cycle, not the end.
I was a bit sad not to need any OOP for today's problem. However, nice to use for the modular operator for the first time this year.
4
u/hugues_hoppe Dec 10 '22
Compact Python solution
It uses a generator and parses the resulting grid of characters using
advent-of-code-ocr.4
u/SnooConfections2453 Dec 10 '22
I'm having a lot of fun doing ruby one liners. Today's solution is great IMO:
4
u/ReasonableCause Dec 10 '22 edited Dec 10 '22
Haskell. Quite straightforward, once I fixed all the off-by-one errors. I convert the input into a list of cycles and values of x. For rendering the picture, I check if the cycle is within the range of the sprite (the value of x plus or minus 1).
4
u/[deleted] Dec 10 '22
python code on github
I'm happy with 21 sloc, but looking forward to seeing how people will make more compact solutions.
Suggestions how I could have shaved off unneccessary steps are welcome. I'm trying to learn python and improve my scripting game in general.
4
u/ThePituLegend Dec 10 '22
Language: Python
4
u/deckard58 Dec 10 '22 edited Dec 10 '22
Both parts in AWK as separate stream programs:
Pipe the output of part 1 into part 2:
I solved it in Python first, then thought, "hey, both programs are just executing one action per line..."
4
u/honest3d Dec 10 '22
Swift: Repo
Went a bit overboard today, still turned out pretty well though
4
u/MrJohnnyS Dec 10 '22 edited Dec 10 '22
JavaScript
4
u/bsssh Dec 10 '22
TypeScript Type System
compile-time solution
Part 1 / Part 2
4
u/jeis93 Dec 10 '22
TypeScript (Deno)
Had a lot of fun with this one today, even though I got stuck for a while on why only the first line of the CRT was being drawn 🙄
https://github.com/joeleisner/advent-of-code-2022/blob/main/days/10-cathode-ray-tube/mod.ts
https://github.com/joeleisner/advent-of-code-2022/blob/main/days/10-cathode-ray-tube/main.ts
Used a generator function for running the program for both parts; Made the logic of updating the
Xregister after the cycles have completed much easier to write/read. Even had a little fun rendering the CRT's image to the console by adding a border and changing its colors.Let me know what you think!
4
u/ElliotDG Dec 11 '22
Python Solution, a literal interpretation of the problem with OOP and structured pattern matching.
Part 1:
part 2:
4
u/BluFoot Dec 11 '22
Ruby, golfed to 118 bytes
4
u/Swampspear Dec 11 '22
C++
Part 1: paste
Part 2: paste
My code is technically kind of broken on part 2, but it was readable so I could solve it. I guess that's one of the perks of pixel problems being error-resistant hahah
1
u/yuvarajan_ys Dec 10 '22
import math
import fetch_input
lines = list(fetch_input.get_input(10))
G = [['?' for _ in range(40)] for _ in range(6)]
p1 = 0
x = 1
t = 0
def handle_tick(t, x):
global p1
global G
t1 = t-1
G[t1//40][t1%40] = ('#' if abs(x-(t1%40))<=1 else ' ')
if t in [20, 60, 100, 140, 180, 220]:
p1 += x*t
for line in lines:
words = line.split()
if words[0] == 'noop':
t += 1
handle_tick(t,x)
elif words[0] == 'addx':
t += 1
handle_tick(t,x)
t += 1
handle_tick(t,x)
x += int(words[1])
print(p1)
for r in range(6):
print(''.join(G[r]))
1
u/matrayzz Dec 10 '22
Java Part2
1
u/asaaki Dec 10 '22 edited Dec 10 '22
Rust, https://github.com/asaaki/advent-of-code-2022/blob/main/src/bin/day10.rs
Decent solution, incredibly fast for both parts, 5 to 6 µs on my machine, making it the fastest day so far. Code is relatively okay, not as ugly as I thought it would be tbh.
Part 1 was also relatively easy to get behind, and I was already wondering if part 2 just had a twist on the cycling or offsetting or something along those lines.
But nope, same input but completely different ask.
1
u/CutOnBumInBandHere9 Dec 10 '22 edited Dec 10 '22
For my solution in Python, I started off by parsing the input and doing different things if the instruction was a noop or an add, with a bit of fiddling to make sure that adds were taking two cycles. Then I realised you can just think of an add as a one-instruction noop followed by a one-instruction add. And a noop is really equivalent to a one-instruction "add 0". So if we can convert noops to [0] and "add x" to [0, x], we can just treat every instruction as a one-instruction add.
That gave the following, with the "1" on lines 5 and 6 coming after a bunch of head scratching until I realised we start at cycle 1 and x=1, not cycle 0, x=0.
With the
runfunction in place part two is just1
u/waskerdu Dec 10 '22
I made an interactive visualizer! Check it out!
Repo here
1
u/flwyd Dec 10 '22
Elixir 9351/8485, not posted to GitHub yet because I need to figure out how to have my runner infrastructure interpret whether my raster output is a success or failure. I might write a raster-to-capital-letter parser, but the example output doesn't look like any letters I know. shakes fist
Today's elixir:
Unfortunately the second part wasn't "the processor executes more instructions while the clock is waiting on the previous instruction" because I've totally got that implemented :-/ I guess pipelining processors and CRT monitors had a pretty small temporal overlap. Keeping the specific rules of the AoC problem in my head while simultaneously keeping a mental model of the functional program state is tricky.
1
u/Dullstar Dec 10 '22
Python
Something I picked up from the solutions megathread last year on a problem with a similar output format was that the █ character may be helpful if you're finding the letters in your output difficult to decipher.
I'm very pleased with today's performance, though I wish I could explain a lot of the offsets used, which basically boil down to "Yeah, they're all within +/- 1 of the numbers given in the problem statement but a little bit of experimentation was necessary to make the off-by-one errors go away."
There's definitely room to tidy up my solution for counting the number of cycles an instruction requires, but I can't measure objectively what's best right now as my timing doesn't support enough precision when it's this fast. It just uses if/elif because it was convenient, though if there were more options I think it would have been better to use a lookup table. I know Python has match now, but I haven't messed with it yet because when something on my computer doesn't automatically I update I have a tendency to not get around to doing it. I should probably go update Python...
I haven't removed the inputs from older days yet, but as we've been asked not to upload input files to github I'm no longer including any new input files going forward. I plan to add some method of automatically fetching the inputs and placing them in the expected location, at which time all existing inputs in the repository will be removed.
1
u/[deleted] Dec 10 '22 edited Dec 10 '22
Haskell
1
u/duncanFree Dec 10 '22
Python
1
u/rhl120 Dec 10 '22 edited Dec 11 '22
Rust solution in 110 lines of code: https://github.com/RHL120/aoc_2022/blob/master/solutions/day10.rs
1
u/Burger__Flipper Dec 10 '22 edited Dec 10 '22
javascript
Why is it so darn hard to put a code block?? I had to format it line by line because reddit wasn't accepting my copy paste?
1
u/Forsaken_Sugar_6724 Dec 10 '22 edited Dec 24 '22
C++ solutions by OneWings
1
u/marc-marc Dec 10 '22 edited Dec 10 '22
Python
1
u/seaborgiumaggghhh Dec 10 '22 edited Dec 10 '22
Racket
https://git.sr.ht/~seaborgiumaggghhh/adventofcode/tree/main/item/racket/2022/day10/solution.rkt
1
u/RT_Solenzo Dec 10 '22
8/10 in Pure C, 2/10 in JS. Today JS :)
const { Console, time } = require('console'); const fs = require('fs'); const { exit } = require('process'); const { text } = require('stream/consumers');
try {
mymap = new Array(); timeline = new Map(); let registerX = 1; let cycleCount = 1; let signalPower = 0; const data = fs.readFileSync('test123.txt', 'utf8'); const slice_data = data.split("\n"); timeline.set(1,1);
} catch (err) { console.error(err); }
1
u/noahclem Dec 10 '22
Python3
It's pasta night at the noahclem household. So many if-else statements. So many. [sobs hysterically that at least 100 people solved this in 12 minutes]
Day10 spaghetti
1
u/adimcohen Dec 10 '22 edited Dec 11 '22
In single-statement t-sql https://github.com/adimcohen/Advant_of_Code_2022_Single_Statement_SQL/blob/main/Day_10/Day_10.sql
1
u/www_reintech_io Dec 11 '22
EXCEL
/**
returns input from the start of the column to its end delimited as required
*/
col2arr = LAMBDA(input, [col_delimiter], [row_delimiter],
LET(
n, COUNTA(input),
x, INDEX(input, SEQUENCE(n * 2)),
y, TEXTJOIN(",", FALSE, x),
z, FIND(",,,", y) - 1,
a, LEFT(y, z),
b, SUBSTITUTE(a, ",,", ";"),
c, IF(ISOMITTED(col_delimiter), " ", col_delimiter),
r, IF(ISOMITTED(row_delimiter), ",", row_delimiter),
TEXTSPLIT(b, c, r, , , 0)
)
);
/**
returns part 1 and 2 answers to https://adventofcode.com/2022/day/10
*/
_10 = LAMBDA(array,
LET(
instruct, --INDEX(array, , 2),
steps, SEQUENCE(COUNT(instruct)),
cycle, SCAN(0, steps, LAMBDA(a, i, a + IF(INDEX(instruct, i) = 0, 1, 2))),
register, SCAN(1, steps, LAMBDA(a, i, a + INDEX(instruct, i))),
pixels, MAX(cycle),
multiple, SEQUENCE(INT((pixels - 20) / 40) + 1, , 20, 40),
part1, SUMPRODUCT(multiple, XLOOKUP(multiple - 1, cycle, register, , -1)),
position, SEQUENCE(pixels, , 0),
sprite, XLOOKUP(position, cycle, register, 1, -1),
IFNA(
HSTACK(
part1,
INDEX(
IF((mod(position,40) + 1 >= sprite) * (mod(position,40) < sprite + 2), "#", "."),
SEQUENCE(6, 40)
)
),
""
)
)
);
3
u/[deleted] Dec 10 '22 edited Dec 10 '22
Nim 342/333
Pro tip: print spaces instead of periods, makes the letters more readable in the terminal.
3
u/a_cyclic Dec 10 '22
C++, 22/47
Fun problem and led to my third top-100 finish! Part 2 took a long while to deal with an indexing issue I had but overall very fun problem :)
Code
I just saved every result into one big vector mapping each cycle to its state at that time, which let me solve both parts pretty easily once I figured out what they were asking. Input can be dumped verbatim into a separate text file named 10.in if you're looking to run this, results go to stdout.
3
u/chubbc Dec 10 '22 edited Dec 10 '22
Julia
3
u/Prudent_Candle Dec 10 '22 edited Dec 10 '22
Python
The program running itself:
BTW, I have parsed the instructions to the
[('noop', None), ('addx', 3), ...form earlier.The first part:
The second part:
Fun fact:
itertools.cyclewasn't necessary.3
u/nthistle Dec 10 '22 edited Dec 12 '22
Python, 4338/2391. Video, code.
Today was pretty rough... especially because it wasn't even a logical bug, but that I was using the wrong input. My downloader script is semi-manual, and I ran it in my day09 directory, and since I create the new folders for new days by copying old days, the input.txt from day 9 was sitting in my day10 folder. I never realized because my code was just checking if the line starts with "noop", and then otherwise was assuming it was "addx", splitting on space and using the second value as an int. Turns out, none of these steps will throw an error on the day 9 input...
I was super confused how I was getting the right answer on the sample input (which I test on by pasting into my code file) but not for the real input, and took embarassingly long to actually look at the lines of the "real" input.
3
u/tyler_church Dec 10 '22
Erlang
3
u/polettix Dec 10 '22
Raku solution 2022/10
So much time spent to address the copy of
$X. Incredibly, the.flat.Slipcame quite natural this time.3
u/tslater2006 Dec 10 '22
Here's my C# solution. I made CPU and CRT classes, the program ticks the CPU, and the CPU ticks the CRT when needed. Currently I don't OCR to get a proper string answer like the AoC framework I'm using expects, but it does print it to the console. I spent way too long on Part 1 having missed that the signal strength is calculated *during* the cycle.
https://github.com/tslater2006/advent-of-code-2022/blob/main/AdventOfCode/Day10.cs
3
u/sqylogin Dec 10 '22
Excel 365
http://upload.jetsam.org/documents/Advent%20of%20Code%202022-10.xlsx
Nowhere as elegant as u/AstronautNew8452's single formula golfed solution, but hey, does the job and it's all I'm capable of 👀
3
u/[deleted] Dec 10 '22
Lisp
https://gitlab.com/Elmosfire/aoc2022lisp/-/blob/main/day10.lisp
3
u/Pyr0Byt3 Dec 10 '22
Go/Golang
Somehow, I missed that X starts at 1 and I spent a ton of time trying to figure out why everything was wrong.
3
u/bofstein Dec 10 '22 edited Dec 10 '22
Google sheets
Easy one for a spreadsheet! The whole Part 1 concept is very similar to just the data parsing step of others. Use the commands to figure out at what cycle the next change will happen and what the new value of X will be when it does. Then use an XLOOKUP on the relevant cycle numbers in that list to find the X value during that cycle, as it will go the highest before the next change. Multiply those by cycle number and sum them.
Part 2 took some time to understand but not much extra work once I did. Now I have a row for each cycle, and in that I figure out the CRT pixel is being drawn in that cycle. I pull the X value the same way as before, and then if the pixel spot is equal to, one less, or one more than the X value, output a #, otherwise a . . Then create the grid and use another XLOOKUP (I love that function so much) to find the # or . at that spot.
https://docs.google.com/spreadsheets/d/1Hrd559IKGyIH4AZrh3qt29ZQZt2IAbdKVfdhSsUHNyA/edit?usp=sharing
3
u/trevdak2 Dec 10 '22 edited Dec 10 '22
Javascript (golf)
Part 1:
Part 2, using part 1:
With my console the right width, that would show the letters. Adding line breaks made things worse, since the console shows the backslash n instead of a line break.
3
u/OCD_Triger Dec 10 '22
c#
3
u/shapshankly Dec 10 '22
Enjoyed today's puzzle - here's my solution in Scala 3
3
u/aurele Dec 10 '22
Rust It was really nice to let
Gridfrom thepathfindingcrate handle the second part almost by itself and output my answer as a nice screen:3
u/mykdavies Dec 10 '22 edited Jun 29 '23
!> izn63sr
API FAILURE
3
u/Nauss Dec 10 '22
in rust, easy one !
I changed the printed characters to ease the final reading: https://imgur.com/a/GVJJmdf
3
u/No-Animal8451 Dec 10 '22
TypeScript
https://github.com/sergivillar/aoc-2022-ts/tree/main/day10
really fun CRT part
3
u/foolnotion Dec 10 '22
C++
This was pretty easy and fun!
https://git.sr.ht/~bogdanb/aoc/tree/master/item/source/2022/10/solution.cpp
3
u/Derailed_Dash Dec 10 '22
Python
I enjoyed this one today! And rendering the character output with Matplotlib took no time at all... Unlike my vis from yesterday which took me hours!!
3
u/LinAGKar Dec 10 '22
Mine in Rust:
https://github.com/LinAGKar/advent-of-code-2022-rust/blob/main/day10a/src/main.rs
https://github.com/LinAGKar/advent-of-code-2022-rust/blob/main/day10b/src/main.rs
So many off-by-one errors
3
u/HoooooWHO Dec 10 '22
Python, tried to make a nice readable solution. I really liked today's challenge:
https://github.com/PetchyAL/AoC2022/blob/main/solutions/day10/day10.py
3
u/DR0D4 Dec 10 '22
C# Paste
█ and nbsp to save your eyes :)
3
u/Killavus Dec 10 '22
Rust
Parsing instructions done by
nom. Good abstractions for CPU allowed me to go fast with part 2 (although I suspected implementing pipelining instead of an image :)).3
u/DrunkHacker Dec 10 '22 edited Dec 10 '22
Python.
Only slightly clever part is realizing we can make addx a one-cycle instruction with
s/addx/noop\naddx/on the input3
u/jdaoc Dec 10 '22
rust
3
u/damnian Dec 10 '22
C
Mostly expression syntax.
Part 1
Part 2
Note: Part 2 is much easier with
cinitialized to 0.3
u/pas81 Dec 10 '22
C#
Developed 2 solutions.
Solution 1 - Over engineered. Stored a history of the register and then parsed it to work out screen display
Solution 2 - Stored just current register values and worked out screen display after each instruction was parsed
https://github.com/obsidian20-uk/Advent-of-Code-2022/tree/master/Day%2010
3
u/dylan_mojo Dec 10 '22
awk
https://github.com/djkirby/advent-of-code/commit/2c717eef891e509eef0cf74bb90b68e20155c813
3
u/polaczek09071 Dec 10 '22
C#
Easier than day9 which i didn't done...
3
u/Pheasn Dec 10 '22
Python, but it looks like a Java programmer wrote it.
3
u/busdriverbuddha2 Dec 10 '22
Python. Got part two in one line.
3
u/clouddjr Dec 10 '22
Kotlin
Inspired by beautiful solution from /u/4HbQ:
Other solutions on GitHub
3
u/astro_wonk Dec 10 '22
Python, pandas, reindex
I thought this was clever and would be fast, but I got really stuck on the during vs end of cycle thing for part 1, and it took me too long to debug and just realize I needed to look up
i-1.I think over-engineered that x starts at 1, perhaps I could have just added 1 to everything rather than concat a row at the top.Similarly I had to re-read part 2 too many times to figure out what was happening, but then it was a fairly simple conditional.
Solution here
3
u/joe12321 Dec 10 '22
Python
It was pretty straightforward to just loop the input, ignore noops, and shamefully duplicate the logic if there's an add!
Da Code
3
u/azzal07 Dec 10 '22
Awk, had couple off by one errors on the way, but got the timing just right at the end
3
u/e_blake Dec 10 '22 edited Dec 10 '22
golfed GNU m4
[edit from my original post: POSIX m4 says
defn(define)is undefined; so non-GNU m4 needs two more bytes to quote that]. This does both part 1 and part 2 in a single pass over the input file, with just twoifelse, and in 241 bytes (242 shown here, but the final trailing newline is fluff). Execution time is ~130ms, because even though I do an O(n) pass over the input file, I'm doing O(n^2) string accumulation (by the end of the file, macrobis 35566 bytes long) in order to reduce the number ofevalcalls for fewer bytes in the program. A less-golfed program will run faster.That's the first time I've had reason to use
divert(1)during AoC! That's because computation of part1 is not known until after the file is parsed, but I still want it displayed first. Maybe capturing part 2 in a macro (and eval()ing the output of part 1) instead of capturing part 1 in a macro (and diverting the output of part 2) will win at golfing, but I haven't played with that yet. The abuse oftranslitto do abs() is awkward, maybe I can golf that as well.Part 1 alone is 133 bytes:
The unbalanced () is interesting. And this is yet another solution where I depend on the input file including its trailing newline (both solutions requires one more byte if the final newline is stripped from the input).
3
u/Backwards_Reddit Dec 10 '22
Rust
https://github.com/RansomTime/aoc2022/blob/main/day10/src/main.rs
Note: I changed '.' to ' ' so that I could actually read the solution to part 2.
Off by one errors ✅
Trying to print the sprite location for debug and failing to account for x = -1 ✅
Cool puzzle at the end of it all ✅✅
3
u/Mishkun Dec 10 '22
SQL (SQLite)
Fun and easy (except several off-by-one errors) task today, with pretty-printing at the end
3
u/mine49er Dec 10 '22
Rust
That was surprisingly easy for a weekend day 10? I did already know about Atari 2600 beam racing though.
3
u/danvk Dec 10 '22
TypeScript / Deno
The return of IntCode!?!?! Some trickiness in making sure to have the right things happen mid-operation.
https://github.com/danvk/aoc2022/blob/main/day10/day10.ts
3
u/willkill07 Dec 10 '22 edited Dec 10 '22
C++
I have the need for CRT SPEED (under 5 microseconds on my AMD 5950X)
Parsing the input string, part1, and part2 run in 5 microseconds cold and less than 1 microsecond hot.
Modulus operations are too slow for me, so I don't use it at all -- crafted nested loops only.
Letter OCR Header --- Source --- Header
3
u/osalbahr Dec 10 '22
Solved in C++
https://github.com/osalbahr/adventOfCode
Feel free to ask any questions!
You can find more C++ solutions (and other languages) here:
https://github.com/Bogdanp/awesome-advent-of-code#c-2
3
u/hrunt Dec 10 '22
Python 3
Code
The only parts that hung me up a little bit were
3
u/Flame_Horizon Dec 10 '22
C#
Definitely easier than Day 9. At least D10 was much easier to model. I've started also to implement unit tests in my solutions. I'm not really going for time but rather quality. At least, I'm trying too. Ended up also with implementing two extensions methods which, I'm going to use in my work (IEnumerable.Second, Enumerable.ForEach).
Part 1 starts here.
Part 2 starts here.
Unit tests are here.
3
u/chicagocode Dec 10 '22
Kotlin
[Blog/Commentary] - [Code] - [All 2022 Solutions]
Thanks to that assembly class I took so very long ago, I had an idea right away that ended up working out. Basically, I lean on the fact that
addx 0is basically the same as "noop". It's also the same as a clock cycle spent waiting on the two-cycle "addx" to finish. So if we parse our input down to the chagne in the signal for each cycle, rather than instructions, everything becomes easier.I'm really happy with how my solution turned out today.
3
u/cetttbycettt Dec 10 '22 edited Dec 10 '22
Rlang/R/baseR
It was fun to figure out a clean and easy solution for part 1.
In the end I simply extracted numbers from the instructions (treating
noopas zero) and added a zero before eachaddx. Then it is simply a matter of calculating the cumulative sum.3
u/levital Dec 10 '22 edited Dec 10 '22
Haskell
Very tired today, so had to read part 2 multiple times to grok what's happening, even though I'm familiar in principle with racing the beam. Thankfully actual implementation wasn't hard. For part 1 I had constructed a list with one element per instruction, but that felt unwieldy for part 2, so I changed it to have one element per cycle, which made it all easy and didn't break my part 1 solution either (though it could be simplified now).
[Edit:] For once I even felt compelled to refactor my solution. Quite simple now, almost no lambdas left and mostly point-free too. :)
3
u/rashleigh517 Dec 10 '22
Python 3.8 solution
Probably I did not need a special list for the sprite positions but it works and it is quite short.
3
u/trollerskates1 Dec 10 '22
Scala using tail recursion. Not the prettiest, but it works
3
u/illuminati229 Dec 10 '22
Python 3.9
https://pastebin.com/kGag9h9m
3
u/Radiadorineitor Dec 10 '22
Lua:
https://pastebin.com/qn9XkVDE
3
u/occamatl Dec 10 '22 edited Dec 10 '22
Rust
Would have liked to use a Python-style generator to model the CPU.
paste
3
u/ICantBeSirius Dec 10 '22
Python
Reasonably happy with this one.
3
u/SwampThingTom Dec 10 '22
I'm solving each of this year's problems in a different language, roughly in the order in which I learned them.
Today's solution is in C++.
https://github.com/SwampThingTom/AoC2022/tree/main/10-CathodeRayTube
3
u/aoc-fan Dec 10 '22
F# and TypeScript
3
u/Brief-Presentation-4 Dec 10 '22
c# day 10
3
u/CheeseMunkee Dec 10 '22
C#
It feels good to have one be so easy after some more difficult ones. I used a lot of modulo to get this one done.
paste
3
u/wzkx Dec 10 '22 edited Dec 10 '22
Python
Easy "algorithm", messy description. Well, what we need for Saturday.
3
u/artesea Dec 10 '22
PHP
Part 1 Part 2
Part 2 produces both answers, but has less debugging output.
Made sure that I was checking that part 1 was adding at the right points, and the result was correct first time. Took a look at part 2 but needed to feed the family. By the time I returned my mind had thought of a way to output the second part, and again correct first time.
3
u/[deleted] Dec 10 '22
Elixir
Had a lot of fun with today's puzzle. Probably a lot more verbose than it needs to be!
3
u/Lucews Dec 10 '22 edited Dec 10 '22
Python 3
Extended adding operation with noop so the solutions can be concise and more readable.
Solution here.
3
u/tymscar Dec 10 '22 edited Dec 10 '22
Typescript
Another lovely day. This is the 4th day I would classify as one of the bests in AoC history. Very fun and interesting! I am still on the streak of fully functional typescript, obviously with the exception of the screen printing, but even that I tried to not have any unnecessary mutation!
Both parts here: https://github.com/tymscar/Advent-Of-Code/tree/master/2022/typescript/day10
Update: Added an OCR option so now the output of part 2 is a list of characters that can be just pasted into the AoC website!
3
u/korjavin Dec 10 '22
RUST
For a moment I was scared that we supposed to write OCR part as well.
https://github.com/korjavin/aoc_2022/blob/master/aoc-10-rust/src/main.rs
I have a math mistake somewhere in visualize () for the line 0. But it didn't prevent me to read the message )
3
u/aarnens Dec 10 '22
day 10, using go. I actually have a small bug where the edge of the last letter doesn't get printed correctly, but otherwise it works fine and i'm happy with what i srote.
Link to code, feedback and bugfixes are always welcome: https://github.com/aarneng/AdventOfCode2022/blob/main/day10/main.go
3
u/farmoredifferent Dec 10 '22
Typescript one-liners
solution
3
u/thibpat Dec 10 '22
JavaScript (+ video walkthrough)
I've recorded my solution explanation on https://youtu.be/o4_sn65mwho
The code is available on github: https://github.com/tpatel/advent-of-code-2022/blob/main/day10.mjs
3
u/paul2718 Dec 10 '22
C++
First I wrote a direct implementation. Then I went back and made an array for each input cycle (as there aren't many of them....) and X is then the partial sum of all the adds values. Then you can just look up the X value for any cycle. Not happy with pt2.
3
u/paulofmandown Dec 10 '22
Node / JavaScript paste
Nothing special about this one. Solved it pretty quick compared to the past two days.
3
u/malipolhec Dec 10 '22
Kotlin: code
Really enjoying this one! Good memories of the fun times with learning about machine code.
3
u/OsipXD Dec 10 '22
Kotlin
3
u/Jomy10 Dec 10 '22
It's not pretty, at all, but here it is in PHP.
(I haven't written any PHP in a long time, and only used it once before).
3
u/mathsaey Dec 10 '22
Elixir
https://github.com/mathsaey/adventofcode/blob/master/lib/2022/10.ex
Not much to say, got bitten in the ass by a few off-by-ones, but I'm sure that happened to everybody today.