Done day 1
authorNeil Smith <neil.git@njae.me.uk>
Sun, 1 Dec 2019 09:00:57 +0000 (09:00 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Sun, 1 Dec 2019 09:00:57 +0000 (09:00 +0000)
README.html [new file with mode: 0644]
README.md
advent-of-code.sublime-project [new file with mode: 0644]
advent01/package.yaml
advent01/src/advent01.hs
data/advent01.txt
problems/day01.html [new file with mode: 0644]
stack.yaml

diff --git a/README.html b/README.html
new file mode 100644 (file)
index 0000000..218a7f9
--- /dev/null
@@ -0,0 +1,64 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <meta http-equiv="Content-Style-Type" content="text/css" />
+  <meta name="generator" content="pandoc" />
+  <title>Advent of Code 2018</title>
+  <style type="text/css">code{white-space: pre;}</style>
+  <link rel="stylesheet" href="modest.css" type="text/css" />
+</head>
+<body>
+<div id="header">
+<h1 class="title">Advent of Code 2018</h1>
+</div>
+<p>Code to solve the <a href="http://adventofcode.com/2019/">Advent of Code</a> puzzles. This year, I'm using the puzzles to develop my skills in <a href="https://wiki.haskell.org/Haskell">Haskell</a>.</p>
+<p><a href="http://learnyouahaskell.com/chapters">Learn you a Haskell</a>, <a href="https://www.haskell.org/tutorial/index.html">Introduction to Haskell 98</a>, and <a href="https://hackage.haskell.org/">Hackage</a> are good resources.</p>
+<p>The <a href="https://docs.haskellstack.org/en/stable/README/">Stack documentation</a> and <a href="http://howistart.org/posts/haskell/1/">How I Start: Haskell</a> are good sources of using the tools.</p>
+<h1 id="toolchain">Toolchain</h1>
+<p>I'm using the basic Haskell Platform installation, together with <code>stack</code> to manage the packages and dependencies (install with</p>
+<pre><code>$ sudo aptitude install haskell-platform haskell-stack</code></pre>
+<p>), then updgrade with</p>
+<pre><code> stack upgrade --binary-only</code></pre>
+<p>as the version in the Ubuntu repos is too old to work with current Haskell Stack package sets. ##</p>
+<h2 id="creating-the-repository-and-project">Creating the repository and project</h2>
+<p>Create the repository as normal: create the project in Gitolite, clone it, and insert the <code>.gitignore</code> and <code>README.md</code> files.</p>
+<p>There's just one package, with the code in sub-directories of the <code>src</code> directory. Each day will generate one (or more) entries in the <code>adventofcode17.cabal</code> file.</p>
+<p>Create the basic <code>stack</code> project. This will create a new directory. Note that this new directory name can't have a hyphen-delimited word that's just digits, so the project will have to be <code>advent-of-code</code></p>
+<pre><code>stack new advent-of-code --bare simple</code></pre>
+<p>Modify the <code>stack.yaml</code> file as needed, such as adding the <code>ghc-options</code> stanza.</p>
+<h2 id="creating-subsequent-days">Creating subsequent days</h2>
+<p>Each day lives in a separate directory within the <code>src</code> directory. It will also need it's own stanza in <code>advent-of-code.cabal</code>.</p>
+<p>Compile with</p>
+<pre><code>stack build</code></pre>
+<p>or</p>
+<pre><code>stack build advent01</code></pre>
+<p>Run with</p>
+<pre><code>stack exec advent01</code></pre>
+<p>If you want to pass in additional RTS parameters, do it like this:</p>
+<pre><code>stack exec -- advent01 +RTS -K0 -RTS</code></pre>
+<p>Run interactively with</p>
+<pre><code>stack ghci advent-of-code:exe:advent01</code></pre>
+<p>To profile, use</p>
+<pre><code>stack build --executable-profiling --library-profiling --ghc-options=&quot;-fprof-auto -rtsopts&quot;</code></pre>
+<p>then run with</p>
+<pre><code>stack exec -- advent01 +RTS -p -hy</code></pre>
+<p>Generate the profile graph with</p>
+<pre><code>stack exec hp2ps advent01.hp</code></pre>
+<h1 id="packages">Packages</h1>
+<p>Stack is using the <a href="https://www.stackage.org/lts-14.16">14.16-lts resolver</a> for packages, so make sure you read the <a href="https://www.stackage.org/lts-14.16/docs">correct documentation for the packages included in it</a>.</p>
+<p>When you use a new package, use</p>
+<pre><code>stack solver</code></pre>
+<p>to see how the <code>stack.yaml</code> file needs to change, and</p>
+<pre><code>stack solver --update-yaml</code></pre>
+<p>to implement the changes.</p>
+<h1 id="ihaskell">IHaskell</h1>
+<p>Install following the <a href="https://github.com/gibiansky/IHaskell">IHaskell instructions</a>.</p>
+<p>Run it with</p>
+<pre><code>stack exec jupyter -- notebook</code></pre>
+<h1 id="readme">Readme</h1>
+<p>Build this readme file wth</p>
+<pre><code>pandoc -s README.md &gt; README.html</code></pre>
+<p>(Using the <a href="https://github.com/markdowncss/modest">Modest style</a>.)</p>
+</body>
+</html>
index aa3689e9ac689ab55ba05a026a538e023830f838..1d363c8c15d5bc57d64586abd309815ac6c02340 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 ---
-title: "Advent of Code 2018"
+title: "Advent of Code 2019"
 output: html_document
 css: modest.css
 ---
diff --git a/advent-of-code.sublime-project b/advent-of-code.sublime-project
new file mode 100644 (file)
index 0000000..24db303
--- /dev/null
@@ -0,0 +1,8 @@
+{
+       "folders":
+       [
+               {
+                       "path": "."
+               }
+       ]
+}
index 30024177fc8dbbfa67c91735c2a0e14579290966..448035a78f7789609755b92bb71c695e64123711 100644 (file)
@@ -5,6 +5,49 @@
 name: advent01
 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
+- NegativeLiterals
+- NumDecimals
+- OverloadedLists
+- PartialTypeSignatures
+- PatternGuards
+- PatternSynonyms
+- PolyKinds
+- RankNTypes
+- RecordWildCards
+- ScopedTypeVariables
+- TemplateHaskell
+- TransformListComp
+- TupleSections
+- TypeApplications
+- TypeInType
+- TypeOperators
+- ViewPatterns
+
+
 executables:
   advent01:
     main: advent01.hs
index e1935f475587e9f1ee771303b31d4e1d659e5681..5c70f596c4e4d92062f30a2bee20778abbe51e39 100644 (file)
@@ -1,6 +1,3 @@
-{-# LANGUAGE NegativeLiterals #-}
-{-# LANGUAGE OverloadedStrings #-}
-
 import Data.Text (Text)
 import qualified Data.Text.IO as TIO
 
@@ -11,8 +8,6 @@ import Text.Megaparsec.Char
 import qualified Text.Megaparsec.Char.Lexer as L
 import qualified Control.Applicative as CA
 
-import Data.IntSet (IntSet)
-import qualified Data.IntSet as S
 
 main :: IO ()
 main = do 
@@ -23,16 +18,18 @@ main = do
 
 
 part1 :: [Int] -> Int
-part1 = sum 
+part1 = sum . map fuelRequired
 
 part2 :: [Int] -> Int
-part2 = snd . head . dropWhile unRepeated . scanl merge (S.empty, 0) . cycle 
+part2= sum . map fuelForFuel
+
+
+fuelRequired :: Int -> Int
+fuelRequired m = (m `div` 3) - 2
 
-merge :: (IntSet, Int) -> Int -> (IntSet, Int)
-merge (frequencies, frequency) change = (S.insert frequency frequencies, frequency + change)
+fuelForFuel :: Int -> Int
+fuelForFuel m = sum $ takeWhile (> 0) $ drop 1 $ iterate fuelRequired m
 
-unRepeated :: (IntSet, Int) -> Bool
-unRepeated (frequencies, frequency) = frequency `S.notMember` frequencies
 
 -- Parse the input file
 type Parser = Parsec Void Text
@@ -44,12 +41,12 @@ sc = L.space (skipSome spaceChar) CA.empty CA.empty
 
 lexeme  = L.lexeme sc
 integer = lexeme L.decimal
-signedInteger = L.signed sc integer
+-- signedInteger = L.signed sc integer
 
-changesP = many signedInteger
+moduleP = many integer
 
 successfulParse :: Text -> [Int]
 successfulParse input = 
-        case parse changesP "input" input of
+        case parse moduleP "input" input of
                 Left  _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
                 Right changes -> changes     
\ No newline at end of file
index f907f859061252319b0d2f336d42064dba790d30..9feebe211d7f8fdc3e4ed10a177ae15b3e21e964 100644 (file)
--16
-+12
--18
--1
-+5
--8
-+9
--15
-+12
-+6
-+11
-+7
--9
-+13
-+5
--4
--4
--2
--5
-+19
-+4
-+14
-+7
-+8
--16
--9
-+16
-+8
--11
--7
-+12
-+8
-+13
-+11
-+12
--19
-+11
-+7
-+9
--7
--16
--5
-+11
--1
-+8
-+5
-+12
--1
--1
-+6
--2
--12
-+6
--18
-+11
-+5
-+13
--12
--15
--8
--13
-+2
--11
-+1
--14
--6
-+11
--15
-+11
-+8
-+18
--8
-+18
--7
--9
--24
--12
-+2
-+20
--9
--5
--14
--6
-+16
--1
--12
--16
-+8
-+9
--15
--8
--2
--4
--16
--18
--8
-+10
-+10
-+2
-+3
--8
--10
--1
--2
-+20
--5
--4
--13
-+10
-+9
--12
--19
-+15
--4
--13
--11
--9
--4
--12
-+3
--7
--4
-+13
-+8
--5
-+10
--11
-+7
-+10
-+13
-+10
--17
--21
-+11
-+3
-+9
--15
--11
-+15
-+10
--3
-+17
-+6
-+11
-+16
-+19
-+8
-+8
-+4
-+9
-+7
-+15
-+2
-+15
-+22
-+19
-+11
-+3
-+19
-+9
--4
-+9
--19
--16
-+6
-+2
--3
-+5
-+5
--18
-+1
--14
--6
--20
-+10
--13
-+19
--18
--17
-+5
--39
-+2
-+33
-+2
-+24
--16
-+45
-+9
-+21
-+6
-+20
-+4
--12
--7
--3
-+8
-+12
-+5
--1
-+8
-+18
--13
--9
-+3
-+16
--4
-+15
-+13
--10
--8
--13
--21
-+15
-+17
-+13
--4
--18
--15
-+3
-+11
-+5
-+3
-+10
--11
-+9
-+19
--2
-+9
-+3
--13
-+2
--7
--14
--2
--7
--19
-+7
-+3
--13
-+6
-+10
-+5
--9
--20
--8
-+5
--17
-+11
--12
-+17
--12
--14
-+24
--22
--13
-+15
-+15
-+1
--4
-+13
--30
-+12
-+17
-+8
-+45
-+4
--3
--5
-+3
--9
-+13
-+8
-+14
-+2
--12
--3
-+9
-+20
-+7
-+1
-+1
--17
--10
-+3
--2
-+4
--6
-+16
--8
-+15
-+16
-+8
--11
--14
--4
-+2
-+15
-+19
-+12
-+14
-+17
--18
--18
--18
--1
--1
--7
--17
--2
--18
-+15
--3
-+5
--20
-+39
--1
-+6
-+8
-+10
-+16
--19
-+11
-+19
-+15
--6
-+19
--8
-+6
-+1
--2
--20
--4
-+18
-+2
--17
--10
--10
--12
-+18
-+2
--16
--8
-+14
--15
-+12
--14
--19
--16
--21
--17
-+21
--12
--34
--22
--25
--15
-+14
--12
--10
-+11
--20
-+4
--6
--11
-+14
-+21
-+74
-+40
-+3
-+15
--4
-+16
-+12
-+3
-+6
-+2
-+11
-+10
--3
-+17
--5
-+10
-+13
-+5
--13
--4
-+13
--8
-+17
--2
-+6
--12
-+7
-+2
-+13
--2
--9
-+18
-+15
--11
-+4
-+3
--21
--17
-+3
-+12
--1
--12
--3
--20
--10
-+13
--6
--4
--20
-+7
-+15
--6
--15
--26
-+13
-+6
--23
--9
--1
-+44
-+8
--14
-+26
-+13
-+5
-+31
-+24
-+7
--2
-+7
--4
-+17
--16
--3
-+36
--10
--22
--11
-+62
--7
-+21
--17
--10
--18
-+11
-+4
-+5
--23
--26
--40
-+2
-+32
-+62
-+23
-+45
-+109
--37
--10
--99
--210
--21
--33
-+379
-+262
-+66
-+66407
-+13
--8
--14
--16
--6
--19
-+12
-+15
--10
--19
--8
-+12
-+13
--11
-+18
-+7
--11
-+14
--12
--11
--2
-+4
--19
--9
-+3
--5
-+7
--4
-+9
--19
-+20
-+7
--14
--2
--7
--8
--2
--16
-+8
--10
-+1
--4
--16
-+2
-+1
--13
--2
--3
--16
-+5
--6
--17
-+3
-+9
-+14
-+1
--11
-+6
--2
--12
--10
-+11
-+19
--9
-+5
--11
--8
--17
--19
-+8
--3
--17
-+13
-+14
--16
--8
-+19
-+17
--16
--16
--13
--11
-+9
--19
-+6
-+12
-+5
--12
--12
--16
--14
--6
-+7
-+8
--12
--18
-+12
-+13
--17
-+3
--5
-+1
-+6
--4
--18
-+1
-+11
-+2
--8
--15
--17
-+16
--10
--12
-+16
--14
--1
--11
-+5
-+14
-+20
-+16
--18
-+16
-+17
-+13
--9
--6
--16
-+19
-+13
-+8
--13
-+1
-+19
--12
--20
--20
--11
--12
-+4
-+12
-+6
--17
--9
--3
--18
--15
--2
--5
-+17
-+12
--8
-+4
--12
--7
--18
--4
--1
--19
-+1
--7
--8
-+5
-+1
-+19
--7
--19
-+18
-+12
-+6
-+19
-+8
--1
-+20
--17
--16
--5
--1
--3
-+6
--13
--2
-+6
--8
-+12
--13
--3
--13
-+8
-+4
--16
-+19
-+18
-+16
--13
--1
-+3
-+9
-+18
-+1
-+3
-+14
-+10
-+3
-+1
--8
-+18
-+4
-+26
-+22
-+13
--12
--7
--3
-+6
--17
-+5
-+14
--7
-+12
-+10
--7
-+8
--7
-+18
-+17
--6
-+12
-+17
-+2
-+3
--9
-+18
-+10
--17
--10
--2
--13
-+6
-+4
-+17
-+12
-+14
--15
-+5
-+17
-+4
--1
--14
--19
--1
-+5
--15
--16
-+1
--11
--13
--5
-+15
--4
--15
-+1
-+22
-+17
--20
--21
-+13
-+1
--2
-+17
-+23
--35
--14
--18
-+6
-+1
-+1
--13
--10
-+34
-+35
-+8
-+4
-+14
-+24
-+16
--5
--2
-+10
-+16
--10
--11
-+1
--2
--3
-+7
-+5
-+20
--14
-+2
-+2
--5
-+14
--18
-+23
--3
-+2
-+4
-+2
-+7
-+8
-+3
--16
--5
-+4
-+12
--20
--15
--22
-+5
--10
-+31
--2
-+9
-+10
--14
-+18
-+6
-+3
-+19
--15
-+9
-+7
-+18
--1
--8
-+19
-+12
-+1
-+16
--5
--4
--9
-+16
-+13
-+2
-+7
-+5
--3
--19
-+12
-+9
-+2
-+9
-+16
--17
--13
-+12
--5
-+11
-+4
--1
-+2
--6
-+18
-+19
--10
-+3
--19
--19
--13
--16
--2
--13
-+8
-+18
-+6
--11
-+2
--16
-+11
-+12
--20
-+18
-+17
-+14
--13
-+26
--1
-+20
--1
--17
--11
--8
-+13
--7
--5
--5
--7
-+18
--20
--4
-+29
--2
-+21
-+21
-+16
-+15
-+14
-+21
--15
--14
-+17
-+5
--10
--27
--18
-+10
--20
-+34
--13
-+18
-+17
--21
-+32
-+13
-+6
-+6
-+28
--37
-+20
-+29
--25
--69
--57
--3
--59
-+3
--21
--9
-+14
--19
--18
-+20
--5
-+15
-+5
--9
--24
-+20
--14
--10
--15
-+30
-+21
--9
--34
-+4
--31
-+25
--85
-+25
-+38
--36
--28
-+58
-+121
--31
-+13
-+202
-+66221
--5
--19
--10
--7
--8
--2
-+6
--5
--6
-+8
--17
-+10
-+18
-+16
-+3
--12
--2
--11
-+14
-+7
-+11
--1
--5
-+10
-+9
--5
--3
--3
--11
--13
-+18
--8
--5
-+18
-+17
--6
-+3
-+19
--18
-+5
-+5
--4
--12
-+7
-+14
-+19
--6
-+10
--8
--11
-+10
--17
-+9
-+11
-+7
--133358
+50350
+104487
+101866
+143582
+58497
+69981
+98300
+119291
+148489
+83005
+107291
+124738
+142256
+108102
+121054
+119697
+75546
+109022
+136754
+52073
+115235
+87668
+64523
+71179
+69071
+142380
+68233
+115226
+132656
+137007
+82838
+79339
+131726
+52295
+102941
+98297
+144374
+118998
+63910
+146772
+82916
+72068
+82855
+55915
+91663
+82917
+105876
+119551
+70639
+114459
+129235
+56041
+70031
+145187
+54913
+56928
+52159
+144384
+80104
+83932
+81334
+72693
+50595
+128895
+54138
+79126
+69930
+72896
+108357
+67415
+110581
+131477
+65517
+87912
+125782
+51785
+145472
+54358
+87715
+98067
+99791
+92502
+50750
+76614
+110137
+56118
+149501
+76542
+87183
+128333
+127657
+144246
+141704
+96873
+62434
+136609
+121829
+111796
+103936
+69807
diff --git a/problems/day01.html b/problems/day01.html
new file mode 100644 (file)
index 0000000..a011978
--- /dev/null
@@ -0,0 +1,143 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 1 - Advent of Code 2019</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?20"/>
+<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, ads, 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="/2019/about">[About]</a></li><li><a href="/2019/events">[Events]</a></li><li><a href="https://teespring.com/adventofcode-2019" target="_blank">[Shop]</a></li><li><a href="/2019/settings">[Settings]</a></li><li><a href="/2019/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <span class="star-count">2*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">/^</span><a href="/2019">2019</a><span class="title-event-wrap">$/</span></h1><nav><ul><li><a href="/2019">[Calendar]</a></li><li><a href="/2019/support">[AoC++]</a></li><li><a href="/2019/sponsors">[Sponsors]</a></li><li><a href="/2019/leaderboard">[Leaderboard]</a></li><li><a href="/2019/stats">[Stats]</a></li></ul></nav></div></header>
+
+<div id="sidebar">
+<div id="sponsor"><div class="quiet">Our <a href="/2019/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://lifeatgalois.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Galois</a> - Employee-owned, self-directed, radically transparent. Tackle challenging computer science problems in a unique and nurturing community.</div></div>
+</div><!--/sidebar-->
+
+<main>
+<article class="day-desc"><h2>--- Day 1: The Tyranny of the Rocket Equation ---</h2><p>Santa has become stranded at the edge of the Solar System while delivering presents to other planets! To accurately calculate his position in space, safely align his warp drive, and return to Earth in time to save Christmas, he needs you to bring him <span title="If only you had time to grab an astrolabe.">measurements</span> from <em class="star">fifty stars</em>.</p>
+<p>Collect stars by solving puzzles.  Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first.  Each puzzle grants <em class="star">one star</em>. Good luck!</p>
+<p>The Elves quickly load you into a spacecraft and prepare to launch.</p>
+<p>At the first Go / No Go poll, every Elf is Go until the Fuel Counter-Upper.  They haven't determined the amount of fuel required yet.</p>
+<p>Fuel required to launch a given <em>module</em> is based on its <em>mass</em>.  Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.</p>
+<p>For example:</p>
+<ul>
+<li>For a mass of <code>12</code>, divide by 3 and round down to get <code>4</code>, then subtract 2 to get <code>2</code>.</li>
+<li>For a mass of <code>14</code>, dividing by 3 and rounding down still yields <code>4</code>, so the fuel required is also <code>2</code>.</li>
+<li>For a mass of <code>1969</code>, the fuel required is <code>654</code>.</li>
+<li>For a mass of <code>100756</code>, the fuel required is <code>33583</code>.</li>
+</ul>
+<p>The Fuel Counter-Upper needs to know the total fuel requirement.  To find it, individually calculate the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.</p>
+<p><em>What is the sum of the fuel requirements</em> for all of the modules on your spacecraft?</p>
+</article>
+<p>Your puzzle answer was <code>3212842</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the launch sequence.  Apparently, you forgot to include additional fuel for the fuel you just added.</p>
+<p>Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and subtract 2.  However, that fuel <em>also</em> requires fuel, and <em>that</em> fuel requires fuel, and so on.  Any mass that would require <em>negative fuel</em> should instead be treated as if it requires <em>zero fuel</em>; the remaining mass, if any, is instead handled by <em>wishing really hard</em>, which has no mass and is outside the scope of this calculation.</p>
+<p>So, for each module mass, calculate its fuel and add it to the total.  Then, treat the fuel amount you just calculated as the input mass and repeat the process, continuing until a fuel requirement is zero or negative. For example:</p>
+<ul>
+<li>A module of mass <code>14</code> requires <code>2</code> fuel.  This fuel requires no further fuel (2 divided by 3 and rounded down is <code>0</code>, which would call for a negative fuel), so the total fuel required is still just <code>2</code>.</li>
+<li>At first, a module of mass <code>1969</code> requires <code>654</code> fuel.  Then, this fuel requires <code>216</code> more fuel (<code>654 / 3 - 2</code>).  <code>216</code> then requires <code>70</code> more fuel, which requires <code>21</code> fuel, which requires <code>5</code> fuel, which requires no further fuel.  So, the total fuel required for a module of mass <code>1969</code> is <code>654 + 216 + 70 + 21 + 5 = 966</code>.</li>
+<li>The fuel required by a module of mass <code>100756</code> and its fuel is: <code>33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346</code>.</li>
+</ul>
+<p><em>What is the sum of the fuel requirements</em> for all of the modules on your spacecraft when also taking into account the mass of the added fuel? (Calculate the fuel requirements for each module separately, then add them all up at the end.)</p>
+</article>
+<p>Your puzzle answer was <code>4816402</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="/2019">return to your Advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="1/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+%22The+Tyranny+of+the+Rocket+Equation%22+%2D+Day+1+%2D+Advent+of+Code+2019&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F1&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2019%2Fday%2F1&amp;title=I%27ve+completed+%22The+Tyranny+of+the+Rocket+Equation%22+%2D+Day+1+%2D+Advent+of+Code+2019" target="_blank">Reddit</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 c341fe33253a166b47d56c9ffcff247853641498..115ecb82eb23532c9c8cc65e9f62d34838b97d12 100644 (file)
@@ -34,6 +34,7 @@ ghc-options:
 #   - auto-update
 #   - wai
 
+
 packages:
 # - .
 - advent01