Done day 8
authorNeil Smith <neil.git@njae.me.uk>
Mon, 14 Dec 2020 17:24:54 +0000 (17:24 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Mon, 14 Dec 2020 17:24:54 +0000 (17:24 +0000)
advent08/package.yaml [new file with mode: 0644]
advent08/src/advent08.hs [new file with mode: 0644]
data/advent08.txt [new file with mode: 0644]
data/advent08a.txt [new file with mode: 0644]
problems/day08.html [new file with mode: 0644]
stack.yaml

diff --git a/advent08/package.yaml b/advent08/package.yaml
new file mode 100644 (file)
index 0000000..f0fd36c
--- /dev/null
@@ -0,0 +1,63 @@
+# This YAML file describes your package. Stack will automatically generate a
+# Cabal file when you run `stack build`. See the hpack website for help with
+# this file: <https://github.com/sol/hpack>.
+
+name: advent08
+synopsis: Advent of Code
+version: '0.0.1'
+
+default-extensions:
+- AllowAmbiguousTypes
+- ApplicativeDo
+- BangPatterns
+- BlockArguments
+- DataKinds
+- DeriveFoldable
+- DeriveFunctor
+- DeriveGeneric
+- DeriveTraversable
+- EmptyCase
+- FlexibleContexts
+- FlexibleInstances
+- FunctionalDependencies
+- GADTs
+- GeneralizedNewtypeDeriving
+- ImplicitParams
+- KindSignatures
+- LambdaCase
+- MonadComprehensions
+- MonoLocalBinds
+- MultiParamTypeClasses
+- MultiWayIf
+- NamedFieldPuns
+- NegativeLiterals
+- NumDecimals
+# - OverloadedLists
+- OverloadedStrings
+- PartialTypeSignatures
+- PatternGuards
+- PatternSynonyms
+- PolyKinds
+- RankNTypes
+- RecordWildCards
+- ScopedTypeVariables
+- TemplateHaskell
+- TransformListComp
+- TupleSections
+- TypeApplications
+- TypeFamilies
+- TypeInType
+- TypeOperators
+- ViewPatterns
+
+executables:
+  advent08:
+    main: advent08.hs
+    source-dirs: src
+    dependencies:
+    - base >= 2 && < 6
+    - text
+    - attoparsec
+    - containers
+    - vector
+    
\ No newline at end of file
diff --git a/advent08/src/advent08.hs b/advent08/src/advent08.hs
new file mode 100644 (file)
index 0000000..dab483e
--- /dev/null
@@ -0,0 +1,98 @@
+-- import Debug.Trace
+
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Text.IO as TIO
+
+import Data.Attoparsec.Text
+-- import Data.Attoparsec.Combinator
+import Control.Applicative
+
+import qualified Data.Set as S
+import qualified Data.Vector as V
+import Data.Vector ((!), (//))
+
+data Instruction = Acc Int | Jmp Int | Nop Int
+  deriving (Show, Eq)
+
+type Program = V.Vector Instruction
+
+data Machine = Machine 
+  { machineProgram :: Program
+  , machineIP :: Int
+  , machineAcc :: Int
+  }
+
+data MachineResult = Looped Int | Terminated Int | OutOfBounds Int Int
+  deriving (Show, Eq)
+
+
+main :: IO ()
+main = 
+  do  text <- TIO.readFile "data/advent08.txt"
+      let program = successfulParse text
+      -- print program
+      let machine = Machine program 0 0
+      print $ part1 machine
+      print $ part2 program
+
+part1 machine = executeMany S.empty machine
+
+part2 program = filter terminates $ map runProgram programs
+  where programs = altPrograms program
+        runProgram p = executeMany S.empty (Machine p 0 0)
+        terminates (Terminated _) = True
+        terminates (OutOfBounds _ _) = True
+        terminates _ = False
+
+
+executeMany visited machine
+  -- if currentIP `S.member` visited
+  -- then Looped (machineAcc machine)
+  -- else if currentIP == programSize
+  --      then Terminated (machineAcc machine)
+  --      else if currentIP > programSize
+  --           then OutOfBounds (machineAcc machine) currentIP
+  --           else executeMany visited' machine'
+  | currentIP `S.member` visited = Looped (machineAcc machine)
+  | currentIP == programSize     = Terminated (machineAcc machine)
+  | currentIP > programSize      = OutOfBounds (machineAcc machine) currentIP
+  | otherwise                    = executeMany visited' machine'
+  where machine' = executeStep machine
+        currentIP = machineIP machine
+        visited' = S.insert currentIP visited
+        programSize = V.length $ machineProgram machine
+
+
+executeStep m = execute ((machineProgram m)!(machineIP m)) m
+
+execute (Acc n) m = m { machineIP = machineIP m + 1
+                      , machineAcc = machineAcc m + n
+                      }
+execute (Jmp n) m = m { machineIP = machineIP m + n }
+execute (Nop n) m = m { machineIP = machineIP m + 1 }
+
+altPrograms program = map (mutateProgram program) [0..(V.length program - 1)]
+
+mutateProgram program i = go (program!i)
+  where go (Nop n) = program // [(i, Jmp n)]
+        go (Jmp n) = program // [(i, Nop n)]
+        go _ = program
+
+-- -- Parse the input file
+
+
+instructionP = accP <|> jmpP <|> nopP
+
+accP = Acc <$> ("acc " *> signed decimal)
+jmpP = Jmp <$> ("jmp " *> signed decimal)
+nopP = Nop <$> ("nop " *> signed decimal)
+
+programP = V.fromList <$> sepBy instructionP endOfLine
+
+successfulParse :: Text -> Program
+successfulParse input = 
+  case parseOnly programP input of
+    Left  _err -> V.empty -- TIO.putStr $ T.pack $ parseErrorPretty err
+    Right program -> program
diff --git a/data/advent08.txt b/data/advent08.txt
new file mode 100644 (file)
index 0000000..1aac5a0
--- /dev/null
@@ -0,0 +1,644 @@
+acc +17
+jmp +1
+acc +16
+acc +15
+jmp +161
+acc +37
+acc +5
+acc -13
+nop +134
+jmp +426
+acc +26
+acc +0
+jmp +262
+acc -1
+nop +266
+jmp +486
+jmp +149
+acc +20
+acc +27
+jmp +564
+acc +35
+acc +9
+acc +31
+acc +0
+jmp +81
+acc -7
+nop +142
+acc +11
+jmp +125
+jmp +610
+jmp +534
+nop +42
+jmp +469
+acc +48
+acc +47
+acc -4
+jmp +114
+jmp +150
+nop +311
+acc +25
+acc +19
+jmp -4
+acc +48
+acc +38
+acc -7
+jmp +292
+acc +19
+jmp +386
+acc +15
+acc -7
+acc -8
+acc +32
+jmp +98
+acc +33
+jmp +460
+acc +7
+acc +30
+jmp +428
+acc -5
+acc +30
+acc +1
+jmp +305
+jmp +91
+nop -47
+acc +23
+acc +33
+acc +49
+jmp +538
+acc +19
+nop +560
+acc +17
+jmp +362
+jmp +530
+jmp +182
+acc +50
+acc +46
+acc -1
+nop +60
+jmp +39
+acc +36
+acc +28
+acc +49
+acc -13
+jmp +93
+acc -17
+acc +20
+acc -8
+jmp -71
+nop +454
+acc -1
+jmp +365
+acc -13
+acc -3
+acc +5
+jmp +479
+acc +39
+jmp +531
+jmp +68
+acc -15
+acc +10
+acc +19
+jmp +508
+acc +6
+nop +301
+jmp -9
+acc +28
+acc +29
+nop -65
+jmp +116
+acc -4
+acc -3
+jmp -63
+acc -5
+jmp -71
+acc +9
+acc +19
+jmp +34
+jmp +346
+nop +484
+nop +278
+nop +284
+jmp +120
+acc -15
+acc -4
+acc +32
+acc -3
+jmp +461
+acc +24
+acc -7
+jmp -7
+acc +15
+jmp +349
+acc +7
+acc +6
+acc -15
+acc +8
+jmp +402
+jmp +274
+acc +15
+acc +28
+acc +47
+jmp +491
+acc +39
+acc +37
+jmp -65
+nop +31
+nop +437
+nop +183
+acc +33
+jmp +469
+nop +26
+jmp +260
+jmp +20
+acc -19
+acc +11
+acc +8
+jmp +337
+acc +41
+nop +55
+jmp -64
+acc +33
+acc -5
+jmp +79
+acc +43
+jmp +28
+acc +39
+jmp +231
+jmp +268
+acc -10
+jmp +360
+acc +50
+jmp +91
+acc +37
+acc +16
+jmp +170
+jmp +162
+jmp +426
+nop +396
+acc +5
+jmp +276
+acc -14
+acc +1
+acc -7
+acc -17
+jmp +399
+acc +4
+jmp +443
+acc +24
+acc +44
+acc +29
+jmp -161
+jmp -4
+acc -2
+acc -9
+acc +29
+jmp -164
+acc +43
+acc +17
+nop +395
+jmp +68
+acc -10
+jmp +1
+jmp -114
+acc +6
+nop +70
+acc +19
+jmp +191
+jmp +156
+acc -11
+nop +128
+acc +49
+acc +6
+jmp +390
+acc -2
+acc -4
+acc +11
+jmp +257
+jmp +71
+nop +350
+nop +87
+jmp +47
+acc -10
+acc +3
+jmp +345
+acc +21
+acc +6
+jmp -89
+acc +26
+acc +16
+acc -18
+acc +21
+jmp +43
+acc +41
+acc -4
+acc +39
+acc +27
+jmp +227
+acc +21
+nop +183
+acc +5
+jmp +164
+acc +36
+jmp +6
+acc +35
+acc -4
+acc +30
+acc +15
+jmp -82
+acc +29
+acc +8
+nop -138
+jmp +1
+jmp +128
+acc +41
+jmp +288
+acc +12
+acc +36
+jmp +172
+acc +42
+acc +14
+acc +8
+jmp +160
+acc -2
+nop +200
+acc +15
+jmp +105
+jmp -224
+acc +44
+nop +161
+acc +0
+acc +48
+jmp +252
+acc +35
+jmp +354
+nop +114
+acc +10
+acc -18
+jmp +268
+acc +28
+jmp +70
+nop -80
+acc +44
+jmp -220
+acc -4
+acc +1
+acc +43
+acc +39
+jmp -232
+nop -257
+acc -3
+jmp -195
+acc -10
+acc +42
+acc +47
+nop -70
+jmp -145
+acc +21
+jmp +1
+acc +19
+acc +8
+jmp +140
+acc +10
+acc +20
+acc +22
+acc +18
+jmp -129
+acc +40
+jmp +244
+jmp +1
+nop +112
+acc +26
+acc +4
+jmp -162
+acc +2
+acc +29
+jmp +1
+jmp -98
+acc +11
+nop +117
+acc +33
+acc +36
+jmp +208
+nop -172
+acc +13
+acc -4
+acc +48
+jmp -264
+acc +33
+acc +37
+jmp -256
+acc +8
+jmp -51
+acc +43
+acc +19
+acc +48
+acc +41
+jmp +119
+acc +46
+acc +39
+acc +37
+jmp +289
+acc +48
+acc -16
+jmp -136
+jmp +1
+acc +40
+jmp -16
+nop +246
+jmp -300
+acc -6
+jmp +110
+acc +34
+nop -315
+jmp -316
+acc -9
+acc +10
+acc +19
+jmp -347
+acc +37
+acc +49
+acc +45
+acc +35
+jmp -74
+jmp +52
+nop -222
+jmp -141
+acc -8
+jmp +153
+acc +6
+jmp +258
+acc +13
+acc +13
+acc +25
+acc +45
+jmp +140
+acc +12
+acc +4
+acc +6
+acc -13
+jmp +122
+acc +17
+acc -19
+jmp -314
+acc -9
+acc +10
+acc -14
+acc +40
+jmp -345
+acc +42
+acc -6
+acc +10
+jmp -231
+acc -14
+acc +0
+acc -4
+nop +110
+jmp +177
+acc +29
+acc +38
+jmp +121
+acc +28
+acc +6
+acc +12
+jmp +98
+acc -3
+jmp +153
+acc +49
+acc -1
+acc +44
+acc -10
+jmp +119
+jmp -198
+acc +40
+acc -2
+jmp -17
+acc +13
+acc +41
+acc -2
+jmp +28
+nop -351
+jmp -66
+acc +4
+acc +0
+acc +20
+nop -393
+jmp -137
+acc -10
+acc -14
+jmp +101
+jmp -409
+jmp +1
+acc +17
+jmp +173
+jmp +105
+jmp -46
+acc +12
+jmp -319
+nop -284
+nop -340
+jmp +16
+acc +25
+acc -13
+acc +48
+acc -8
+jmp -90
+jmp +113
+acc +28
+acc +20
+acc +3
+nop -289
+jmp +168
+acc +27
+nop -17
+acc -12
+jmp -50
+jmp -248
+acc +38
+acc +21
+jmp +1
+jmp -364
+nop +104
+jmp +103
+jmp -425
+jmp +1
+acc -1
+acc +20
+acc +42
+jmp +38
+acc +20
+acc +5
+acc +0
+acc +20
+jmp -118
+nop +154
+acc +39
+acc -1
+acc -4
+jmp -155
+jmp +1
+jmp +35
+acc +10
+acc +7
+acc +18
+jmp -473
+jmp +84
+acc +14
+acc +20
+jmp -295
+nop -8
+nop -271
+acc -19
+acc -6
+jmp +50
+acc +24
+acc -5
+acc +41
+nop -229
+jmp -329
+acc +40
+acc -10
+jmp -112
+jmp +1
+nop -372
+jmp -137
+jmp -242
+acc +39
+acc +30
+acc +30
+jmp -396
+acc +4
+acc +2
+nop -114
+acc +30
+jmp +114
+acc +48
+acc -7
+acc +28
+jmp -462
+acc +24
+jmp -359
+jmp -272
+acc -17
+jmp +46
+jmp -227
+acc -3
+acc -11
+acc +10
+acc +16
+jmp -5
+jmp -387
+acc +46
+jmp -269
+acc -7
+acc +30
+jmp +1
+jmp -519
+acc +50
+jmp -23
+nop -105
+jmp -359
+acc +19
+jmp -106
+jmp +26
+nop -128
+jmp -123
+acc -7
+acc +12
+jmp -474
+acc +11
+acc +30
+jmp -530
+acc -17
+jmp -504
+acc +20
+acc +15
+acc +27
+acc +34
+jmp -111
+acc +37
+acc -6
+nop -2
+jmp -493
+acc +9
+jmp -49
+jmp -442
+acc +0
+acc -6
+jmp -107
+acc +34
+acc +39
+jmp -166
+acc -7
+jmp +21
+acc +29
+jmp -139
+acc +22
+acc -8
+acc +39
+jmp -337
+jmp -191
+acc +0
+acc +34
+jmp -102
+acc -17
+acc -10
+jmp +8
+jmp +7
+acc +32
+acc -19
+acc -6
+jmp -553
+acc +30
+jmp -470
+acc +43
+acc +2
+acc +11
+acc -7
+jmp +8
+acc +39
+acc -9
+acc +16
+jmp -213
+nop -70
+jmp -341
+jmp +5
+acc +3
+jmp -406
+acc +45
+jmp -478
+nop -409
+acc -11
+acc +40
+jmp -482
+acc +0
+acc -13
+nop -341
+acc +30
+jmp -79
+acc +4
+acc +31
+acc +10
+jmp -389
+acc +24
+acc +15
+acc +36
+acc +6
+jmp -103
+jmp -25
+jmp -436
+acc +4
+jmp -317
+jmp -583
+acc +12
+acc +44
+jmp -61
+acc -12
+acc +21
+acc +19
+jmp -628
+acc +33
+acc +37
+acc +23
+nop -182
+jmp +1
\ No newline at end of file
diff --git a/data/advent08a.txt b/data/advent08a.txt
new file mode 100644 (file)
index 0000000..6fee349
--- /dev/null
@@ -0,0 +1,9 @@
+nop +0
+acc +1
+jmp +4
+acc +3
+jmp -3
+acc -99
+acc +1
+jmp -4
+acc +6
\ No newline at end of file
diff --git a/problems/day08.html b/problems/day08.html
new file mode 100644 (file)
index 0000000..e2974f4
--- /dev/null
@@ -0,0 +1,184 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 8 - Advent of Code 2020</title>
+<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
+<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'/>
+<link rel="stylesheet" type="text/css" href="/static/style.css?25"/>
+<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
+<link rel="shortcut icon" href="/favicon.png"/>
+</head><!--
+
+
+
+
+Oh, hello!  Funny seeing you here.
+
+I appreciate your enthusiasm, but you aren't going to find much down here.
+There certainly aren't clues to any of the puzzles.  The best surprises don't
+even appear in the source until you unlock them for real.
+
+Please be careful with automated requests; I'm not a massive company, and I can
+only take so much traffic.  Please be considerate so that everyone gets to play.
+
+If you're curious about how Advent of Code works, it's running on some custom
+Perl code. Other than a few integrations (auth, analytics, social media), I
+built the whole thing myself, including the design, animations, prose, and all
+of the puzzles.
+
+The puzzles are most of the work; preparing a new calendar and a new set of
+puzzles each year takes all of my free time for 4-5 months. A lot of effort
+went into building this thing - I hope you're enjoying playing it as much as I
+enjoyed making it for you!
+
+If you'd like to hang out, I'm @ericwastl on Twitter.
+
+- Eric Wastl
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-->
+<body>
+<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2020/about">[About]</a></li><li><a href="/2020/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2020/settings">[Settings]</a></li><li><a href="/2020/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2020/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">16*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;<span class="title-event-wrap">0.0.0.0:</span><a href="/2020">2020</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2020">[Calendar]</a></li><li><a href="/2020/support">[AoC++]</a></li><li><a href="/2020/sponsors">[Sponsors]</a></li><li><a href="/2020/leaderboard">[Leaderboard]</a></li><li><a href="/2020/stats">[Stats]</a></li></ul></nav></div></header>
+
+<div id="sidebar">
+<div id="sponsor"><div class="quiet">Our <a href="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.educative.io/adventofcode" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Educative.io</a> - From CSS to System Design, gain in-demand tech skills at the speed you want. Text-based courses with live coding environments help you learn without the fluff</div></div>
+</div><!--/sidebar-->
+
+<main>
+<script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});</script>
+<article class="day-desc"><h2>--- Day 8: Handheld Halting ---</h2><p>Your flight to the major airline hub reaches cruising altitude without incident.  While you consider checking the in-flight menu for one of those drinks that come with a little umbrella, you are interrupted by the kid sitting next to you.</p>
+<p>Their <a target="_blank" href="https://en.wikipedia.org/wiki/Handheld_game_console">handheld game console</a> won't turn on! They ask if you can take a look.</p>
+<p>You narrow the problem down to a strange <em>infinite loop</em> in the <span title="A trendy new line of encrypted footwear?">boot code</span> (your puzzle input) of the device. You should be able to fix it, but first you need to be able to run the code in isolation.</p>
+<p>The boot code is represented as a text file with one <em>instruction</em> per line of text. Each instruction consists of an <em>operation</em> (<code>acc</code>, <code>jmp</code>, or <code>nop</code>) and an <em>argument</em> (a signed number like <code>+4</code> or <code>-20</code>).</p>
+<ul>
+<li><code>acc</code> increases or decreases a single global value called the <em>accumulator</em> by the value given in the argument. For example, <code>acc +7</code> would increase the accumulator by 7. The accumulator starts at <code>0</code>. After an <code>acc</code> instruction, the instruction immediately below it is executed next.</li>
+<li><code>jmp</code> <em>jumps</em> to a new instruction relative to itself. The next instruction to execute is found using the argument as an <em>offset</em> from the <code>jmp</code> instruction; for example, <code>jmp +2</code> would skip the next instruction, <code>jmp +1</code> would continue to the instruction immediately below it, and <code>jmp -20</code> would cause the instruction 20 lines above to be executed next.</li>
+<li><code>nop</code> stands for <em>No OPeration</em> - it does nothing.  The instruction immediately below it is executed next.</li>
+</ul>
+<p>For example, consider the following program:</p>
+<pre><code>nop +0
+acc +1
+jmp +4
+acc +3
+jmp -3
+acc -99
+acc +1
+jmp -4
+acc +6
+</code></pre>
+<p>These instructions are visited in this order:</p>
+<pre><code>nop +0  | 1
+acc +1  | 2, 8(!)
+jmp +4  | 3
+acc +3  | 6
+jmp -3  | 7
+acc -99 |
+acc +1  | 4
+jmp -4  | 5
+acc +6  |
+</code></pre>
+<p>First, the <code>nop +0</code> does nothing. Then, the accumulator is increased from 0 to 1 (<code>acc +1</code>) and <code>jmp +4</code> sets the next instruction to the other <code>acc +1</code> near the bottom. After it increases the accumulator from 1 to 2, <code>jmp -4</code> executes, setting the next instruction to the only <code>acc +3</code>. It sets the accumulator to 5, and <code>jmp -3</code> causes the program to continue back at the first <code>acc +1</code>.</p>
+<p>This is an <em>infinite loop</em>: with this sequence of jumps, the program will run forever. The moment the program tries to run any instruction a second time, you know it will never terminate.</p>
+<p>Immediately <em>before</em> the program would run an instruction a second time, the value in the accumulator is <em><code>5</code></em>.</p>
+<p>Run your copy of the boot code. Immediately before any instruction is executed a second time, <em>what value is in the accumulator?</em></p>
+</article>
+<p>Your puzzle answer was <code>1867</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>After some careful analysis, you believe that <em>exactly one instruction is corrupted</em>.</p>
+<p>Somewhere in the program, <em>either</em> a <code>jmp</code> is supposed to be a <code>nop</code>, <em>or</em> a <code>nop</code> is supposed to be a <code>jmp</code>. (No <code>acc</code> instructions were harmed in the corruption of this boot code.)</p>
+<p>The program is supposed to terminate by <em>attempting to execute an instruction immediately after the last instruction in the file</em>. By changing exactly one <code>jmp</code> or <code>nop</code>, you can repair the boot code and make it terminate correctly.</p>
+<p>For example, consider the same program from above:</p>
+<pre><code>nop +0
+acc +1
+jmp +4
+acc +3
+jmp -3
+acc -99
+acc +1
+jmp -4
+acc +6
+</code></pre>
+<p>If you change the first instruction from <code>nop +0</code> to <code>jmp +0</code>, it would create a single-instruction infinite loop, never leaving that instruction.  If you change almost any of the <code>jmp</code> instructions, the program will still eventually find another <code>jmp</code> instruction and loop forever.</p>
+<p>However, if you change the second-to-last instruction (from <code>jmp -4</code> to <code>nop -4</code>), the program terminates! The instructions are visited in this order:</p>
+<pre><code>nop +0  | 1
+acc +1  | 2
+jmp +4  | 3
+acc +3  |
+jmp -3  |
+acc -99 |
+acc +1  | 4
+<em>nop</em> -4  | 5
+acc +6  | 6
+</code></pre>
+<p>After the last instruction (<code>acc +6</code>), the program terminates by attempting to run the instruction below the last instruction in the file.  With this change, after the program terminates, the accumulator contains the value <em><code>8</code></em> (<code>acc +1</code>, <code>acc +1</code>, <code>acc +6</code>).</p>
+<p>Fix the program so that it terminates normally by changing exactly one <code>jmp</code> (to <code>nop</code>) or <code>nop</code> (to <code>jmp</code>). <em>What is the value of the accumulator after the program terminates?</em></p>
+</article>
+<p>Your puzzle answer was <code>1303</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
+<p>At this point, you should <a href="/2020">return to your Advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="8/input" target="_blank">get your puzzle input</a>.</p>
+<p>You can also <span class="share">[Share<span class="share-content">on
+  <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Handheld+Halting%22+%2D+Day+8+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F8&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Handheld+Halting%22+%2D+Day+8+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F8'}else{return false;}" target="_blank">Mastodon</a
+></span>]</span> this puzzle.</p>
+</main>
+
+<!-- ga -->
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-69522494-1', 'auto');
+ga('set', 'anonymizeIp', true);
+ga('send', 'pageview');
+</script>
+<!-- /ga -->
+</body>
+</html>
\ No newline at end of file
index e7e925dcbbbf76b13c16655019d262b27de124a0..07d779b7d650c430e3951231a77beb19ec18909b 100644 (file)
@@ -42,6 +42,7 @@ packages:
 - advent05
 - advent06
 - advent07
 - advent05
 - advent06
 - advent07
+- advent08
 
 # Dependency packages to be pulled from upstream that are not in the resolver.
 # These entries can reference officially published versions as well as
 
 # Dependency packages to be pulled from upstream that are not in the resolver.
 # These entries can reference officially published versions as well as