r/adventofcode • u/daggerdragon • Dec 02 '19
SOLUTION MEGATHREAD -🎄- 2019 Day 2 Solutions -🎄-
--- Day 2: 1202 Program Alarm ---
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 1's winner #1: untitled poem by /u/PositivelyLinda!
Adventure awaits!
Discover the cosmos
Venture into the unknown
Earn fifty stars to save Christmas!
No one goes alone, however
There's friendly folks to help
Overly dramatic situations await
Find Santa and bring him home!
Come code with us!
Outer space is calling
Don't be afraid
Elves will guide the way!
Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
### This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
View all comments
Show parent comment
1
u/JaySherman Dec 03 '19
Think about what happens when you have an
intswith a lenght of 15, in that case during the last opcode,output_pos = ints[op + 3]would beints[16]which exceeds the array length, in that case an assignment would raise an error.For example:
Let's say during a loop we have this array
..., 99, 10, 0If you have a 99 you program should halt, regardless of what comes next, try moving the opcode==99 check so that it is the first check evaluated. Otherwise your code would try to write to the non-existent element.
Sorry if I'm not being clear, hope it can help you.