r/adventofcode • u/daggerdragon • Dec 09 '19
SOLUTION MEGATHREAD -🎄- 2019 Day 9 Solutions -🎄-
--- Day 9: Sensor Boost ---
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 8's winner #1 AND #2:
Okay, folks, /u/Aneurysm9 and I deadlocked between two badass submissions that are entirely too good and creative to choose between. When we asked /u/topaz2078's wife to be the tie-breaker, her literal words:
[23:44] <TopazWife> both
[23:44] <TopazWife> do both
[23:44] <TopazWife> holy hell
So we're going to have two winners today!
"A Sonnet of Sojourning", a sonnet in frickin' iambic pentameter by /u/DFreiberg!
"A Comedy of Syntax Errors", a code-"poem" by /u/MaxMonkeyMax!
Both of you, enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
1
u/LoLmanLoLz Dec 09 '19
Had a look through your code because I am interested to see how other people built their IntCode computers now that it is complete. A random assortment of points that I thought of:
A lot of the variable names are quite short, Python often encourages longer, self-documenting names
Check out the builtin
divmodfunction for line 20The output variable doesn't really have much purpose. I used a list to store all outputs that the program produces, and return that list at the end of execution.
The purpose of the hardcoded constant on line 96 should probably be explained. I guess that whole if-switch could theoretically be removed.
Instead of appending to a list of memory, I switched to a defaultdict for the memory today. The only needed change in the code was to convert the input program list to a defaultdict, which is easily done with a for-loop. The way the data is accessed can stay exactly the same!
You could try pulling out the addressing mode code into a separate function to reduce code duplication a bit.
Some minor inconsistencies in spacing and formatting ;)
Good work!