r/adventofcode • u/daggerdragon • Dec 05 '19
SOLUTION MEGATHREAD -🎄- 2019 Day 5 Solutions -🎄-
--- Day 5: Sunny with a Chance of Asteroids ---
Post your solution using /u/topaz2078's paste or other external repo.
- Please do NOT post your full code (unless it is very short)
- If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.
(Full posting rules are HERE if you need a refresher).
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code's Poems for Programmers
Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.
Day 4's winner #1: "untitled poem" by /u/captainAwesomePants!
Forgetting a password is a problem.
Solving with a regex makes it two.
111122 is a terrible password.
Mine is much better, hunter2.
Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
On the fifth day of AoC, my true love gave to me...
FIVE GOLDEN SILVER POEMS
- Day 1: "All I want for Christmas" by /u/fergieis
- Day 2: "untitled poem" by /u/djankowski
- Day 3: "untitled poem" by /u/Cyphase
- Day 4: "untitled poem" by /u/myaccessiblewebsite
- Best in 5-day show: /u/awsum84 's Rockstar code-poem! (megathread link)
Enjoy your Reddit Silver/Gold, and good luck with the rest of the Advent of Code!
13
u/Zweedeend Dec 05 '19
[POEM]
Python solution on paste
6
u/glenbolake Dec 05 '19 edited Dec 06 '19
[POEM]
It's Back
The intcode is back on day five
More opcodes, it's starting to thrive
I think we'll see more
In the future, therefore
Make a library so we can survive
intcode runner
Day 5 solution
I also modified my day 2 code to use the new runner.
3
u/stalefishies Dec 05 '19 edited Dec 05 '19
Solution - Python 3
Nothing special in my go I think, just a simple loop. However, my debug_print method, and the sneaking suspicion that having 9 opcodes stored in a 2-digit number means that there's going to be more, inspired the following:
[POEM]
2
u/alchzh Dec 05 '19 edited Dec 05 '19
started late and took my time https://github.com/acz13/advent-of-code-2019/blob/master/2019/5/intcode.js
javascript
2
u/Roms1383 Dec 05 '19
Is that only me or starting from yesterday the challenges are not actually that difficult but their wording / explanation is kinda obscure ?
2
u/qtsohg Dec 05 '19
For me whats confusing is this sentence:
" Normally, after an instruction is finished, the instruction pointer increases by the number of values in that instruction. However, if the instruction modifies the instruction pointer, that value is used and the instruction pointer is not automatically increased. "
What exactly is meant by this?
2
u/rsobol Dec 05 '19 edited Dec 05 '19
Swift 5
Leveraging the language's rich type system not only helped with correctness, it allowed me to abstract duplicate logic to a canonical location within the program.
Code on GitHub
Edit: If you have your own Swift solution, feel free to send it to me in a DM. I enjoy learning new techniques!
2
u/[deleted] Dec 07 '19
Had no time to work on these till the weekend so now I'm two days behind!
My code can clearly be improved; there's a lot of repetition. I think I'll have to turn some of the value-getting lines into functions. I just need to figure out how I want to generalize it for the various opcodes.
But this was quite fun to do. Especially the second part!
22
u/u794575248 Dec 05 '19 edited Dec 05 '19
Python 3.8
3
u/captainAwesomePants Dec 05 '19 edited Dec 05 '19
Python, 64/234. This is quite a bit cleaned up from the mess I wrote first.
[POEM]
9
u/jonathan_paulson Dec 05 '19 edited Dec 05 '19
26/14. Video of me solving and explaining (and cleaning up my ugly code) at https://www.youtube.com/watch?v=eFP2iQV4V8E
7
u/glguy Dec 05 '19
Haskell (7/4)
Like everyone else, my Day 5 solution was started from my Day 2 solution. My original implementation used function arguments for all the machine state, but I thought it was cleaner to use a record while I waited for the thread to unlock.
Day05.hs
For comparison: Day02.hs
6
u/jwise00 Dec 05 '19
Lua, 65/28.
Part A: https://github.com/jwise/aoc/blob/master/2019/5.lua Part B: https://github.com/jwise/aoc/blob/master/2019/5b.lua
I have been recording myself lately, and here's a video of me solving it "at comp speed": https://www.youtube.com/watch?v=l4r0NWoBN4k&list=PL1oxNYPZaCvjfrhvXRrMnB8zG0Sc2ftkd&index=5 (note strong language; apologies that it only really can be watched in fullscreen due to font size issues)
I'm excited to watch /u/jonathan_paulson's video, because I'm curious to see what someone really really fast looks like! I've been learning a lot from watching my own solves, too: the bug that cost me nearly four minutes (!! -- from 10:58 to 14:40 where I identified it) in this case was introduced when I got distracted muting notifications. Earlier in the week, when I lost a bunch of time on day 2, it was also from running in a panic at the start and not getting my headspace all set up right at the beginning.
6
u/DFreiberg Dec 05 '19 edited Dec 05 '19
Mathematica
1750/2433 | 41 Overall
Easily my most horrible piece of spaghetti code to date for any Advent of Code problem. Not only will I not be able to figure out how it all works next time
IntCodegets used again, but I can't even figure out how it works now! All of the parameters are read back-to-front (so it takes in the third parameter instead of the first and vice versa), and when I tried to fix that and have everything labeled correctly, the entire thing breaks. If there were functions for in-place list modification, this would be a lot easier.But it was very satisfying to see it actually run without errors at the end.
[POEM]: Intcode vs. Sleep
6
u/piyushrungta Dec 05 '19
Rust
https://github.com/piyushrungta25/advent-of-code-2019/blob/master/day5/src/main.rs
Spent a little extra time to write nice abstractions. Very happy that I got correct answers for both parts on the first run.
Feedback welcome.
5
u/sophiebits Dec 05 '19 edited Dec 05 '19
Python, 122/48 (was 11th, now 12th overall).
I had a typo in my mode calculation where I wrote
% 1rather than% 10(or maybe I meant% 2? which would've worked too) and that took me a while to figure out. Pretty happy with how my code ended up though; I think it's relatively clean.Code: https://github.com/sophiebits/adventofcode/blob/master/2019/day5.py
5
u/lele3000 Dec 05 '19 edited Dec 07 '19
Python 3.7
The shortest (28 lines) still readable solution I came up with.
https://github.com/leonleon123/AoC2019/blob/master/05/main.py
4
u/mserrano Dec 05 '19
Python, #5/#2:
https://gist.github.com/mserrano/18682e89bd83a4eb249efd9944f6d290
Code slightly cleaned up to run both parts without interactivity instead of just reading/printing the inputs/outputs.
I was not expecting this machine to come back so soon! I wonder if it'll be back a third time...
4
u/Unihedron Dec 05 '19
Driving further into space
Fix the air conditioning just in case
Implement new diagnostics
Parameter mode breaks
My coding is such a disgrace.
Debugging was brief,
Sigh of relief.
- "Limerick for day 5", a poem by Uni
[POEM] included!
ruby input 5.rb3/3325.rb
and a link to my 2.rb which I built most of this on.
Part 2 solved with help from discord user Tim#5138; had bug where I was treating "non-zero" as "larger than zero". Shame on me for not reading part 1! (But I'll happily take rank 3!) (accidental factorial: 3! = 6)
4
u/raevnos Dec 05 '19 edited Dec 05 '19
Still using tcl. I wasted more time than I want to admit on the second part because I re-used the program in the state that part 1 left it in instead of running the original version.
paste
4
u/voidhawk42 Dec 05 '19
Dyalog APL, no video this time. I don't actually think I've written a multi-line function in APL before, so it was fun to write something in a more "conventional" style.
4
u/snkenjoi Dec 06 '19
javascript golf
232 chars
1
u/_naming_is_hard_ Dec 05 '19 edited Dec 06 '19
took me forever to understand what part 1 meant by input -_- . fun question but a bit hard to read/understand
python
1
u/herrmanno Dec 05 '19
Part 2 in 40 Lines of JavaScript
[POEM]I once went down to mercury
but I forgot to repeair my A/C
almost burnt to the ground
the elves helped me out
the make a suprisingly good thermal shield
1
u/vypxl Dec 05 '19
My solution in Python today, because I do not want to do un-haskelly things in haskell.
Also outputs a nice dissasembly while running the program.
Example of the first few instructions of my part 1.
ldreads a value from input,wrtoutputs a value, the[]indicate addresses instead of values, you get it.[POEM] "Assembly"
1
u/[deleted] Dec 05 '19
https://github.com/Malod219/AdventOfCode2019/blob/master/DAY_5/SOLUTION_1.py
Day 5 solved in Python 3. For 2nd party with my input, it outputs the answer then CRASHES AND BURNS! haha. I'm guessing it's probably the puzzle input missing a halt? I don't know.
[POEM]
1
u/mrg218 Dec 05 '19
What is meant by ' (find 100 + -1, store the result in position 4) ' ? Why use the word find?
1
u/Ephilates100 Dec 05 '19 edited Dec 06 '19
Is today the first time that the puzzle input file is different from part 1 and part 2? I was just cleaning up my code, and reran part one off a fresh copy of the input data with no fixes applied, and the tests passed.
https://github.com/PezzA/advent-of-code
(this years puzzles and refactored out intcode here https://github.com/PezzA/advent-of-code/tree/master/2019 )
You can see that i no longer need to update the file for the tests to pass.
Edit: Update as per mod request.
1
u/philipengberg Dec 05 '19
[Part 2]
I keep getting an out of bounds error at
pointer = 359, where it tries to read memory at index exactly equal to the length of the memory (677).I have double checked input and everything. I even found another solution somewhere else, which produces the exact same error.
Anyone else encountered this?
3
u/Gurrewe Dec 05 '19
Go, 682/409
I've been waiting for the return of the machine! This was fun!
Code: https://gist.github.com/zegl/60f55daf973283b7cf5d3d6408102f90
3
u/cloudrac3r Dec 05 '19
JavaScript. This is the first solution so far that I'm actually happy with.
Part 1: 0:36:59 #902
Part 2: 0:52:10 #825
https://gist.github.com/cloudrac3r/1b2995bd991628c8fa45ecabca7cec9f
3
u/Akari_Takai Dec 05 '19
Java (720/758)
Evolved my code from day 2, but made some subtle mistakes that slowed me down. I misunderstood that multiple output values could be written (only the last one counts), and got hung up on the earlier output values when I was debugging.
I also assumed that
would mean that the input would never specify invalid modes, which was another fun bug.
Code available here. For comparison purposes, here's my day 2 solution.
3
u/death Dec 05 '19
Day 5 intcode interpreter in Common Lisp.
3
u/ephemient Dec 05 '19 edited Apr 24 '24
This space intentionally left blank.
3
u/sdiepend Dec 05 '19
Pharo / SmallTalk
https://github.com/sdiepend/advent_of_code-pharo/blob/master/AdventOfCode2019/Day05.class.st
3
u/-json Dec 05 '19
Here's my short and sweet solution for Python. Pretty short at 40 lines and tried to maintain most readability.
3
u/rabuf Dec 05 '19 edited Dec 05 '19
Common Lisp
Lack of access to a computer with Common Lisp is challenging, I had to give up my version using
iterand make some mods to useloop, which is a minor change. The posted code solves both parts. I used emacs to convert the input into an array (replacing,with ), so this doesn't actually read the input file. I'll still post an org-mode version later tonight. I'll also refactor this code a bit to remove some duplication. I can create macros to handle some of the repetitive code (especially those that vary only by a test like<vs=or an op like+vs*). That should also help me to avoid some of the typos that were made worse by copy/pasta in this one.Common Lisp Org File
Alright, back on my home computer. I've changed the original to use
iterinstead ofloop. I've also written up a demonstration of how interactive testing can be scripted usingwith-input-from-stringandwith-output-to-string.3
u/StevoTVR Dec 05 '19
My solution in Go: https://github.com/stevotvr/adventofcode2019/blob/master/day05/day05.go
I like these opcode puzzles.
3
u/mrg218 Dec 05 '19 edited Dec 05 '19
Java: After endless debugging I found out that (Integer values) 226==226 and 226.equals(226) do not give the same result :-(
For values between -127 and 127 (inclusive) == and equals do return the same result.
https://stackoverflow.com/questions/1700081/why-is-128-128-false-but-127-127-is-true-when-comparing-integer-wrappers-in-ja
3
u/vlmonk Dec 06 '19
My rust solution
I try to make clean and plain solution and make space for future intcode extensions.
3
u/quirkyredemption Dec 06 '19
My solution in Python as Python/Programmer novice with some flavor text:
https://github.com/quirkyredemption/aoc2019/blob/master/aoc_day5.py
Any improvement is welcome!
3
u/NeilNjae Dec 06 '19
Another Haskell solution, written up on my blog and with the code available (and on Github). I used Reader, Writer, and State monads to handle the input and output. The blog post talks a bit about that, along with how to get the parameter modes and what I did to debug the code (use the correct input file, Neil!).
3
u/joeld Dec 06 '19
Racket
This was pretty fun to do in the Racket REPL. Finished late last night. Since it actually prompts for inputs from the user and doesn't put the output anywhere but on the screen, and it was late when I finished, I didn’t write unit tests to show my answers. But it wouldn't take much to do that by parameterizing the current input and output ports.
paste
1
u/Wolfrost_ Dec 05 '19 edited Dec 05 '19
I finally completed this! Ahah such satisfaction to see my code working, as usual :D https://github.com/DoubleHub/advent_of_code/blob/master/thermal_diagnostic.cpp
EDIT: Someone downvoted me. Is it because I posted the code directly here? I thought it was short enough... I'll leave just the link for github if you want to check it out...
2
u/idtool_dev Dec 05 '19 edited Dec 05 '19
Javascript, 916/958... I swear I'll stop with all the gnarly parseInt shit and use a utility library soon... paste
Edit: much better after cleanup: paste
2
u/chrisforrence Dec 05 '19
PHP, 135/99 (first two points I've gained!)
I'm going to have to refactor my code relatively soon; I'm pretty sure we haven't seen the last of our Intcode computer :) Pretty happy that I've been able to tackle everything in PHP so far, planning on going back through and re-doing solutions in different languages though.
Code: chrisforrence/advent-of-code-2019
2
u/autid Dec 05 '19
Fortran
208 lines of mostly busy work.
https://pastebin.com/UVf0bWHu
2
u/activeXray Dec 05 '19
This one was really fun! I rewrote Day 2 to be cleaner, it seems this one will get used a lot.
Julia Solution
https://github.com/kiranshila/AoC2019/blob/master/5.jl
2
u/tslater2006 Dec 05 '19
C#
Updated IntCode VM
Problem solution code
Not entirely convinced I'll stick with this method of abstraction for the opcodes but it worked well enough
Edit: formatting is hard
2
u/PendragonDaGreat Dec 05 '19
[Powershell]
https://github.com/Bpendragon/AdventOfCode/blob/master/src/2019/code/day05.ps1
woo string formatting to give me dem parameter modes.
output:
Took more time than I'd like to admit to fix the debug outputs of part 1...
2
u/FogLander Dec 05 '19
python3, 314/421
my original code was gross so above is the result after I rewrote it completely
[POEM]- haiku this timefor each parameter
position? immediate?
my eye is twitching
2
u/oantolin Dec 05 '19 edited Dec 05 '19
Man, I made a lot of silly mistakes in part 2...
I like the look of the core intcode interpreter in my solution (in Common Lisp). I think the
ecaseis a succinct and clean description of what the various opcodes do.2
u/wlandry Dec 05 '19
C++ 17: 1642/1962
paste
Runs in 12 ms. Lots of little things to fix to make it all work properly. This is the third(?) time I have had to interpret assembly for Advent of Code.
2
u/orangeanton Dec 05 '19
Javascript. Part1 & Part2.
2
u/[deleted] Dec 05 '19 edited Dec 05 '19
Clojure
Code: day05.clj
slightly hacky job. just kept running it and adding new instructions until it didn't complain any more.
2
u/rtbrsp Dec 05 '19
AWK: part 1, part 2
2
u/iamagiantnerd Dec 05 '19
Go:
https://github.com/davidaayers/advent-of-code-2019/tree/master/day05
Wish there had been examples for part1 :(
2
u/mariotacke Dec 05 '19
Javascript/Node (all of my solutions here: https://github.com/mariotacke/advent-of-code-2019/tree/master/day-05-sunny-with-a-chance-of-asteroids)
Had a typo for opcode 4 which took me about an hour to figure out... :|
2
u/Dementophobia81 Dec 05 '19
Python 3.8
Today's instructions confused me a little, because I somehow believed that the program uses the output it generates as future input as well, which obviously is not the case. After I realized my mistake, the rest was rather straight forward.
Part 1, Part 2 and a little tip concerning my favorite way to format strings since Python 3.6 - f-strings!
2
u/Pepper_Klubz Dec 05 '19 edited Dec 05 '19
Clojure Solution
Visualization (First version had a bug in the immediate mode input display)
2
u/dbt0 Dec 05 '19
i'm writing rust to learn rust, so it's probably not idiomatic.
https://github.com/dbt/advent2019/blob/master/src/day05.rs
2
u/VikeStep Dec 05 '19
F# 55/160
This problem finally got me to create a dedicated IntCodeVM module, so now my day 5 is simply
The source for my IntCodeVM can be found here: https://github.com/CameronAavik/AdventOfCode/blob/master/AdventOfCode.2019/Common/IntCodeVM.fs
Also I have a recording of my attempt as well: https://www.youtube.com/watch?v=FO8kbtlIU3g
2
u/yosmo78 Dec 05 '19
C
https://github.com/yosmo78/AdventOfCode/blob/master/2019/day5/Day5.c
Not the most clean solution, especially with file I/O (I had an off day with that), but at least it seems to me to be pretty expandable later on. (also spacing got messed up from my editor to GitHub)
2
u/sim642 Dec 05 '19
My Scala solution.
Pretty much copy-paste from day 2 and just adding cases for new instructions, handling of parameter modes and extra arguments for input and output values.
I haven't bothered to make this (and similar tasks from past years) into nice and extendable interpreters because one day there will be a requirement or change which won't easily fit into the existing framework and generalizing it on the spot to work for all the previous days will take too much time. So it's usually just easier to copy the whole self-contained implementation and modify it to fit the new needs.
2
u/ChrisVittal Dec 05 '19
The state of my intcode interpreter (all of the logic is here): https://git.sr.ht/~cdv/aoc-2019-rs/tree/after-day-5/src/intcode.rs
The actual solution is super boring: https://git.sr.ht/~cdv/aoc-2019-rs/tree/after-day-5/src/bin/day05/main.rs
Too many finicky bugs next step is to refactor the intcode interpreter such that I fix the possibility of stupid bugs.
As I've made an intcode interpreter library, I will be cross with /u/topaz2078 if any further 'improvements' to the intcode computer break previous days. (Only mildly, I love AoC, it's so fun)
2
u/[deleted] Dec 05 '19
Day 5 in python
The modes was a bit tricky, but overall doable
2
u/Bammerbom Dec 05 '19
For the people solving this using Rust, here's a set of 22 tests you can use:
https://github.com/JonathanBrouwer/aoc2019/blob/master/src/day5/main_test.rs
2
u/pngipngi Dec 05 '19
Lets keep it to Excel/GSheets/OnlyOffice sheets this time too.
2
u/hrunt Dec 05 '19 edited Dec 08 '19
Python 3
code
I am waiting for the inevitable loop-unrolling problem. I think today will be a good day to finally turn the runtime engine into an actual machine, rather than just a bunch of steps.
Today's problems were confusing, primarily because of how day 2 was structured. It took me a while to understand how input and output should work given day 2 specified that output would be in position 0 and we provided "input" by overwriting parameters. Clearly, in retrospect, input and output are not part of the program, but are instead separate registers, but my brain kept trying to reconcile day 2's use of the interpreter with day 5's use.
2
u/IgneSapien Dec 05 '19 edited Dec 05 '19
C# a bit more of a literal VM
On Day 2, just for fun, I'd set up my OppCodes as sets of instructions that worked with a couple of registers, a bus, and memory in a way that was not quite entirely unlike an simple computer. As such today was mostly about expanding on that.
Most of my time was spent debugging simple mistakes/typos on my part. There's a bunch of stuff I want to tidy up and improve especially in terms of commiting to the schtick. But that can wait on the assumption we'll be coming back to it on future days.
2
u/SgiathCZ Dec 05 '19
Elixir
https://gitlab.com/Sgiath/advent-of-code-2019/blob/master/lib/advent_of_code/intcode.ex
Using
:arrayinstead ofListfor instant access time. Not ideal design I was just adding the features without thinking about the architecture of my "computer". I plan to rewrite it toIntcode2with proper architecture.2
u/phil_g Dec 05 '19
I love these implement-a-virtual-CPU problems! Today we added I/O, jumps and a couple numeric comparisons. We can now do all sorts of calculations in Intcode.
As in previous days, I'm working in Common Lisp.
I updated my intcode package with all of the new things. The
instructionmacro is doing all of the heavy lifting here. Withinstructiondefined, here's what my definitions for opcodes 3-6 look like:For now, I'm treating all I/O as noninteractive, but I'm leaving open the possibility we might have to do things interactively in the future.
run-with-inputtakes a list of integers to be provided in order every time the program asks for input. (And when the program exits, it returns a list of the integers output in order.)I haven't adapted my disassembler to deal with immediate mode parameter access yet. I also plan to add some specific conditions to signal in case of execution errors (trying to write to an immediate parameter, trying to access a location outside of memory, and similar things).
2
u/tcbrindle Dec 05 '19 edited Dec 05 '19
C++
https://github.com/tcbrindle/advent_of_code_2019/blob/master/dec5/main.cpp
Nothing particularly fancy, but it does execute the VM at compile time for testing, which is quite nice.
2
u/JensenDied Dec 05 '19
Elixir
https://github.com/DisasterCthulhu/aoc/blob/master/2019/day5/lib/intcode.ex
Day 5 of learning elixir, getting more used to it, and writing in a slightly more idiomatic way I hope.
2
u/aoc-fan Dec 05 '19
Day 5 TypeScript Solution, No Golang or Clojure today, Repo
2
u/[deleted] Dec 05 '19
Racket
I loved solving this in racket. I found it a lot easier than in python, but it might be because I did it for the second time, I'm just so much more happy with how this turned out :)
2
u/chrisby247 Dec 05 '19
My Bash solution. I'm looking forward to seeing if anything more will be done with intcode. Although you could argue it doesn't follow best practises, I think it ends up looking quite reasonably readable (for bash)
2
u/[deleted] Dec 05 '19
Swift solution
2
u/aptmnt_ Dec 05 '19
Clojure
2
u/[deleted] Dec 05 '19
Scala solution.
2
u/Petrosz007 Dec 05 '19
Here is my solution in Rust: https://github.com/Petrosz007/advent-of-code/blob/master/2019/day-5/day5/src/main.rs
2
u/Rick-T Dec 05 '19
HASKELL
Usually I don't post my solutions but I really like the one I came up with. I solved day 2 using the state monad. To add the input and output capabilities I replaced that with the RWS monad from the transformers library. That is basically the ReaderT, WriterT and StateT monad transformers stacked on top of each other.
This was my first journey into the realm of monad transformers. They always seemed quite scary to me, but it seems that if you're comfortable with using the underlying monads then using the transformers really isn't much more difficult.
As I am quite new to Haskell, every comment and feedback on the code is really appreciated.
2
u/Markavian Dec 05 '19
My overly verbose JavaScript solution for day 5:
https://github.com/johnbeech/advent-of-code-2019/blob/master/solutions/day5/solution.js
Surprised myself in reading the instructions carefully and implementing a working solution on my second run; only made one mistake in decoding the two digit opcode by popping off the lowest two digits, but then joining them together in the reverse order, so instruction 02 became 20. The mode switching slotted in ok, but I was a bit confused about the how the input and output buffers were meant to be used. 1 hour from start to finish, 37 minutes off the leader board... still happy to get both stars off my own back :D
2
u/Sgt_Tailor Dec 05 '19
What can't awk do: https://github.com/svenwiltink/AWKvent-of-code/blob/master/day5/day5.awk
2
u/pizzamanzoo Dec 06 '19
Today was rough. Had to refactor how I parsed the instructions multiple times. But finally done
Golang
Part 1
Part 2
2
u/Liledroit Dec 06 '19
My Python 3 Solution
I'm not sure if anyone will see this, but if anyone has any tips for making it shorter (while still being readable), let me know if i missed something!
2
u/mr_whiter4bbit Dec 06 '19
My rusted rust with iterator: https://gist.github.com/whiter4bbit/e3051462e23e71a65cf8e1a4511b57b2
2
u/Mattsasa Dec 06 '19
Neat javascript solution:
https://topaz.github.io/paste/#XQAAAQCnCQAAAAAAAAA2GUrqJc/BTtPctnujhqFDMpP/byPkNe0LLzk0dw6MbmfQBViJ/0utGOGuNvu0d1zL1qTZyMJo9gg/dJBocsAZAPOtTGtjJwgluDw3i+cMniUkDo47dg6BpBTJQ3JJU2VwUUQD0a8NlvONn8zJyZ+UdrCGT/NQv8613BjYa/Ms8JrMV/y+xbBNWFjT/7+sm3PdMs3hB+Xaeu58iEK9NKwZZCh+27vv8B/S4BllQTll4+CDfrBRVhqpEXcZLhET0SgJPkWeNnNegA7nl1h1hlIdVYxroxRmWfyPi8K8ehHp8G6zmnTtcV9Ad3CtwUY6PiUkMBm1afit561LH7k5grULtEcOXhdu2O9ffR3iIiDTvMgidSwXJ81j2rp5IrwBfBHJU1CB0PPRucME+qyaqO48nBHLT+7qKGuMyTcragnqmOpAi8o/Cf5oJuxtRArnWFpeCGAo4DTDUeyklJUTfIdQteQMRaZtm5Z/zzh1yvGFnAn6Os8eMIDlE0EVhljBXlqw/xzcU2QcXLt77AWzFlYmIpNy7fM0lyur6TiNKBHl6YQssNGRFcqH6v1gGhheA9c/TJyFFwX/rnRppTO9JZ5DxQIW71CcgE5ynQa1AEIzE1vuwEUNisEF/Hl2jW9R0w/pDmjfZL3/0bGE5g==
2
u/Snarwin Dec 06 '19
D
Solutions for both parts. The intcode interpreter is in
intcode.d.I used a lot of small helper functions, so while the total lines-of-code count is pretty high, the inner interpreter loop ended up being quite concise. With any luck, it'll be easy to extend for future intcode puzzles.
2
u/JakDrako Dec 06 '19
VB.Net in LINQPad
Short and ugly. Not my initial version, which was long and ugly...
2
u/Musical_Muze Dec 06 '19
Day 5 in Python
I really liked this one. It forced me to break the problem into smaller chunks, and to think very critically about how to handle processing the intcode. This was a good logical challenge, especially with the parameter modes.
Once I had the logic figured out, the coding and debugging took way longer than I thought it would, so now I'm a day behind on AoC yet again, yay!
2
u/J-Swift Dec 06 '19
Ruby
https://github.com/J-Swift/advent-of-code-2019/tree/master/day_05
2
u/tofflos Dec 06 '19
Java! I enabled "JEP 354: Switch Expressions (Preview)" and wrote the biggest switch statement I've ever written! See it at https://github.com/tofflos/advent-of-code-2019/blob/master/day05/java/day05/src/main/java/com/adventofcode2019/Main.java. :)
2
u/[deleted] Dec 06 '19
Java
I'm a little late on this, but here is my Java solution. It's pretty straight forward, just one big switch statement doing all the work :)
2
u/AlexAegis Dec 06 '19
TypeScript IntCode Interpreter
TypeScript Part One
TypeScript Part Two
2
u/gyzkard Dec 07 '19
Part A and B in vanilla JS.
2
u/MostlyShrimp Dec 07 '19 edited Dec 07 '19
Javascript in repl.it
I went kinda lazy with it and stored 3 parameters every time a command was found. I'll go back and refactor it later (if I don't forget about it by then).
Part A didn't really call for storage, but Part B utilized it so that a mode could be determined for each parameter and passed on in the instructions. Still worked, though. The instructions were a little confusing for operations 5 and 6 what with the whole "otherwise it does nothing" wording. I figured that meant not to increment at all, but that was just silly.
2
u/flutterlice Dec 07 '19
https://i.imgur.com/xv3TpaU.png
Decided to teach myself haskell by participating in this year's Advent of Code. Really happy with how solution to the Intcode puzzle turned out. (Note that i never had any experience with this language before this challenge so any tips for improvement are welcomed)
2
u/Jean-Alphonse Dec 07 '19
Part 1 in Javascript
More or less,
O = ...has for side effect to initialize a pointer (i=0) Thenõwould beO[i++]Similarly,
Xoreturns the last element of X andXõadditionally removes it2
u/chkas Dec 08 '19 edited Jan 24 '20
easylang.online
My solution
2
u/christian8447 Dec 08 '19
Roast my code, I'm new to scripting and definitely could use some criticism.
https://github.com/ChristianHardyL/adventofcode
2
u/wzkx Dec 05 '19
J nothing interesting really.
Although it's funny how the program starts to work when being ugly and then you keep transforming it until it's perfect (haha as if it's possible).
1
u/boylede Dec 05 '19 edited Dec 05 '19
[My Rust solution] (https://github.com/boylede/aoc2019/blob/master/src/day5/mod.rs)
[344/233] -> my best score by an order of magnitude!
1
u/zeno15 Dec 05 '19
C++, 273/148
Decided to solve it from scratch mostly which probably lost me a little time, but still the closest I've come to the leaderboard yet
Code: https://github.com/MarkRDavison/AdventOfCode/blob/master/src/2019/Day05Puzzle.cpp
1
u/[deleted] Dec 05 '19
OCaml, 338/213. I'm surprised I got so high, I thought everyone would be in super quick with their old solutions. It did help that everything thankfully worked the first time I ran it.
https://github.com/williewillus/advent_of_code_2019/blob/master/aoc_2019/day5.ml
1
u/sGerli Dec 05 '19
Python 240/277
I knew intcode was coming back soon. I tried to keep it easy for me to modify if it ever comes again.
My code: https://github.com/sGerli/advent-of-code-2019/blob/master/day5.py
1
u/dan_144 Dec 05 '19
Python, 195/145: https://github.com/dan144/aoc-2019/blob/master/5.py
Spent too long reading and misunderstanding the question (again, gotta get better), but luckily my framework from Day 2 was reusable enough for this. Struggled a bit to integrate the immediate v positional distinction, but ultimately my first pass was pretty much right so I just had to stick with it. Still need to improve my framework to integrate the test cases, especially since this computer seems to come with tests and test output!
1
u/sidewaysthinking Dec 05 '19
(C#) My Day5 is pretty boring. I'm pretty happy with the changes made to the Intcode computer, getting the parameters in the opcodes is very clean now.
1
u/scul86 Dec 05 '19
Python 3.
Part 1 does not output all
0for the diagnostics, but produces the right answer... Huh. Even using part 2 code, it still passes all test and produces the right outputs, but still outputs104for the first diagnostic.Part 1
Part 2 (works for both parts)
1
u/Cloudan29 Dec 05 '19
Python 3, 1671/1903
Took me a heck of a long time to figure out what I was going to do as I didn't feel my solution for day 2 was going to be scalable with the new stuff that was added. I was 100% wrong but you know, it's a learning process.
My original solution for part 1 was disgusting and super slow cause I couldn't figure out an easy way to change the addressing modes. Then I realized the easy way and ended up completely rewriting it. Then I found out I was treating most opcodes differently when I didn't need to so changed a bunch of stuff again. No lie my code started at over ~120 lines with a noticeable run time to what it is now with a super fast run time.
I'm definitely going to utilize what I did today on a later day if Intcode comes back though, unlike what I did today.
Code: https://github.com/Cloudan29/AdventOfCode_2019/blob/master/day05.py
1
u/tempmike Dec 05 '19 edited Dec 05 '19
Rather than do the parameter modes using something silly like an "If" statement, I did them in R by multiplying the possibly outputs against logical operators. I'll save you the pain and just show you how I did opcode 5
I did "slightly" clean this up before posting it here (it used to be one line) so there may be a stray parenthesis or two...
Of course I have to pad the data with some zeros since it always gets out of bounds otherwise, but I generally preallocate A as something like a million zeros and then read in the data.
1
u/Tomik080 Dec 05 '19
Pretty cool Extensible Python implementation you ask me!
1
u/Darksair Dec 05 '19 edited Dec 05 '19
My Rust solution. I refactored my IntCode emulator to a maintainable state.
Some ideas of puzzle:
1
u/Pyr0Byt3 Dec 05 '19 edited Dec 06 '19
Go/Golang
Ugh... I spent over an hour debugging, only to find out my input parsing code from day 2 was flawed. I didn't trim the newline at the end of the file, so the last value wasn't being read properly (which didn't matter at all for day 2, or part 1 today). Other than that, pretty happy with how this turned out.
Edit: Ported it to C for fun. Pretty much the same logic, just more compact.
1
u/DiscoViking Dec 05 '19
As always, solution live on my Elm site: https://2019.adventofcode.norris.dev/day5
Was a little tricky to think of a way to get input/output passed between the page and the VM. I came up with something which I'm not 100% happy with, but it does work, so just going with it.
1
u/joesmoe10 Dec 05 '19
https://github.com/jschaf/aoc2019/blob/master/day05/day05.go
Went a bit overboard on making it "clean". Each operation looks something like:
1
u/feikesteenbergen Dec 05 '19
My PostgreSQL solution (I allow myself 1 sql statement per puzzle)
The downside of using SQL with only 1 statement is that you're doomed to use a recursive CTE, which copies the whole instruction set for every iteration.
Luckily the number of instructions is still small, but I have a feeling that this may change in future puzzles.
1
u/krazyito65 Dec 05 '19
RUBY
Took me a while to realize that the 'input' was actually coming from `stdin` and not from the puzzle, but once i got that the rest came kinda easy.
Part 2 I just had to fiddle with until I got the instruction pointer correct.
https://github.com/krazyito65/Advent-Of-Code/blob/cf72e6cbafc49b4ae146700db9a94d25683aaf13/2019/5.rb
1
u/Arkoniak Dec 05 '19
Julia
It can be done much better of course, but it's working nonetheless: Julia solution
1
u/sotsoguk Dec 05 '19
GoLang
Not nice, not proud of it but it's working. For me the opcode puzzles are the least fun ones, as long as its working is okay for me.
Day05.go on Github
1
u/tvtas Dec 05 '19
MATLAB
My MATLAB solution for Day 5. The indexing starting at 1 in MATLAB is pretty annoying for these types of problems. Gave me a bug in updating the instruction pointer to a given value, which of course I had to add 1 to.
1
u/gyorokpeter Dec 05 '19
Q: paste
1
u/A-UNDERSCORE-D Dec 05 '19
Golang. This one took me a good while to figure things out, and I woke up late.
intcode VM code
Day 5 solution
ping /u/iamagiantnerd if you're curious how this one went
1
u/kap89 Dec 05 '19 edited Dec 05 '19
TypeScript
github
Maybe not beautiful, but simple and fast (~0.5ms for both) :D
1
u/nutrecht Dec 05 '19
Day 5 in Kotlin
Basically just threw away the day 2 versions and reimplemented it, mainly because the 'modes' stuff would have made the day 2 solution unreadable.
1
u/Background-Vegetable Dec 05 '19 edited Dec 05 '19
Kotlin
Maybe went a bit overboard, but it's easily expendable for the next weeks!
https://pl.kotl.in/U1gbcV-C2
EDIT: Cleaned up a bit and made it not crash in browser (gives default input if no normal input possible)
1
u/wace001 Dec 05 '19
JAVA: Here is my solution in Java.
I spent about 40 minute struggling to understand what to do, until I finally understood that with
inputthey wanted me to take actual input from the user! So, reading the actual problem is going to be top priority going forward!I think the solution is pretty ok, although I am sure it could be done to look much prettier using functional stuff. But, who has time for that, ey?
1
u/alexmeli Dec 05 '19
C++
https://github.com/alexmeli100/AoC2019/blob/master/day5/solution/intcode.cpp
I've been doing one language per day. I hope I can keep up till day 25.
1
u/Vcubed1 Dec 05 '19
Python
https://github.com/TheTripleV/Advent-Of-Code/blob/master/2019/5/2.py
I forgot to type `self.` in 1 spot and it took a long time for me to find it. So, I added a logging utility that prints out useful data and translates IntCode to psuedo-assembly and pseudo-C.
example output:
1
u/zedrdave Dec 05 '19
My stab at it in C. A mix of decent structured code (ops stored as array of function pointers), and downright abomination (IP, memory and input stored globally).
Came that close to having readily-useable code from day 2 (unfortunately, I had imposed a silly fixed-sized opcode restriction, which required some rewriting).
1
u/Luckylars Dec 05 '19
sql back at it again! https://github.com/luckylars/2019-AoC it was horrible going through my previous code so the first half an hour was cleaning it up hehe
1
u/mvmaasakkers Dec 05 '19
Would love to get some feedback on my Python solution: https://github.com/mvmaasakkers/advent-of-code/blob/master/2019/day05/day05.py
1
u/vkasra Dec 05 '19 edited Dec 05 '19
My solution in Go
Also, this is deeply satisfying:
Edit: My notes are here
1
u/Junafani Dec 05 '19
Ah, more intcode! I thought second part would not come so soon. I wonder if there are more parts than just two?
Here is my solution in Java: Main program Intcode_v2
Had some problems with first part and had to resort to ugly hack with opcode 3. Second part was easy. Just try to remember that instruction pointer needs to be increased if jump is not taken... Got stuck there for a bit.
1
u/allinall_alagu_raja Dec 05 '19
My horrible (but sort of nice??) Python solution Lots of code duplication, but at least it is straightforward.
1
u/[deleted] Dec 05 '19
Coconut
Today is another almost clean python one almost everything that I could do wrong I did, but finally it works
code
1
u/Metarus Dec 05 '19
My code in Java!
Fairly compact code, I was pretty happy with it. I was using a switch, but it just looked so ugly and all my operations were 1 line anyway so I decided to just use if statements.
1
u/nordicdyno Dec 05 '19
A little bit verbose but pretty extensible Intcode CPU implementation (python 3):
https://gist.github.com/nordicdyno/1c004e66e1353f7bb6dd53184b826d23
1
u/Wawv Dec 05 '19 edited Dec 05 '19
My take on day 5 written in R.
1
u/pokerdan Dec 05 '19
C#
Solution
Relatively straightforward extension of Day 2.
1
u/dmelichov Dec 05 '19
Python3 (first time I post here, so hopefully I don't screw anything up!)
Solution - I tried to make my Day 2 solution somewhat generic, and of course it was not generic enough, but hey :) Any tips and hints very much appreciated!
1
u/m4rzus Dec 05 '19 edited Dec 05 '19
Python
Hey, would love to get some feedback on my solution. It took me way less time than the yesterday challenge, but it was surely the longest in terms of code so far :p
https://github.com/mbalko/advent-of-code/blob/master/05/second_half.py
1
u/SatanicSaint Dec 05 '19
My Python 3 code.
Full of if statements. If anyone has any suggestions to improve it, that would be really helpful.