This commit is contained in:
Jonathan Chan 2018-12-01 00:41:50 -08:00
parent 19c0078549
commit f46e146baa
28 changed files with 1018 additions and 2 deletions

View File

@ -8,7 +8,7 @@ To arrive at [⟨ortho|normal⟩](https://hilb.ert.space) as December comes.
| Day | Runtime (s) | With `-O2` |
|-----|-------------|------------|
| 01 | |
| 01 | 0.015 |
| 02 | |
| 03 | |
| 04 | |

View File

@ -0,0 +1,996 @@
-2
-3
+4
-15
-15
+18
-7
+11
-16
-14
+2
-6
+16
+6
+14
-15
+12
-5
+17
-10
-20
-19
-14
-10
+4
-11
+10
-1
+12
-17
-2
+1
-17
+9
+4
+19
+11
-17
+15
-12
+5
+4
-1
-10
-19
-16
-9
+18
+2
+4
-19
+16
+6
-16
-14
+7
-9
+7
+17
+17
-14
+6
-22
-13
-2
-1
-18
-3
+19
+19
+16
-22
+14
-2
-3
+2
-18
-15
-14
-4
-15
+1
-3
-8
+18
-11
+6
-7
+17
+7
-8
-13
-4
+7
-15
-11
+7
+9
-7
+1
-20
-19
-18
-17
-12
+7
-16
-11
-4
-8
-4
-3
-2
+3
-15
+18
+5
+14
+15
+2
-19
+5
-13
+19
+9
+8
+5
-1
-19
+11
+2
+13
-17
+9
-16
+14
+20
+12
+8
+10
+17
-15
-8
+15
+19
-14
-3
-10
+2
+4
-1
+14
-12
+15
-2
-11
-14
-18
+6
-12
+7
+18
+15
+6
+12
+3
-6
+17
+11
+14
+13
+3
+6
-11
-19
-5
+14
-10
-7
+18
-8
-13
-2
+19
-18
-17
+11
+14
+17
+1
+26
+6
+15
+21
-5
+12
+6
+4
+10
-8
+16
-14
+4
-1
+17
-15
-23
+15
+18
+19
+10
-18
-2
+15
+15
+13
+5
+10
-8
+2
-18
+13
+15
+8
-19
+2
-4
-3
+20
-3
+12
+6
+13
+13
-15
+6
-15
+3
+7
-19
+11
+17
+15
-4
-10
-14
-20
+18
-11
-17
+8
+12
+3
-11
+7
-13
-4
+19
-7
-17
+12
+9
+13
+7
-13
+24
-2
+14
-5
+10
-6
-1
-8
-5
-6
+5
+12
+16
+5
-14
+19
+18
-9
-6
-12
-2
+19
-12
-9
+5
-4
-9
-9
+16
-19
-14
-7
-24
-20
+16
+12
+19
+20
-15
+26
+21
-2
+12
+4
-2
+18
-17
-12
-20
+2
+9
+14
+16
+12
-9
+14
+17
-19
+11
+3
-13
-3
+11
-14
+18
+9
-16
-2
+19
+7
-10
-3
+4
+10
+15
+19
-2
-5
+2
+2
-11
+6
-17
-11
+6
-10
+16
+7
-1
-2
+19
+6
+16
-12
+14
-5
+19
-12
+1
-6
-6
-2
+7
+19
+17
-4
+3
+3
+17
+16
-2
-10
-1
-14
-2
-17
-11
+3
-21
+15
+11
+7
-3
-18
+1
-15
-11
+1
-18
+11
+15
-17
-16
-19
+9
-5
+16
-18
+13
+16
-17
-1
-3
-2
+20
+14
-13
-17
+13
+5
+2
+19
+22
-3
-22
+10
-13
+2
-29
-27
-16
+17
-27
+18
-13
-4
+6
-5
+12
-16
-9
+3
+1
+10
-25
-1
-19
+13
+12
+2
-6
-12
+3
+25
+28
-4
+2
+17
-9
+63
+23
-8
+9
-6
+15
-14
+12
+6
+18
-6
-15
+12
-16
-3
+15
+24
+19
-6
+4
-8
-19
+4
+4
-20
-1
+24
+10
-9
+13
+11
+2
+11
+14
-2
+18
-12
+1
-17
+6
+1
-16
+10
+4
+9
-6
+10
-14
-2
+22
+2
+6
+10
-19
-24
+10
+11
+14
+2
+5
+18
+29
+1
+20
+7
+3
-12
+25
-21
+24
+4
-18
+1
+51
+19
-17
-23
+31
-15
+27
+2
+19
-16
+1
+18
+9
+22
+6
+15
-19
+14
-7
+3
+14
-7
-15
+18
-8
-1
-14
-7
-16
+22
+22
-2
+18
+2
-15
-39
+5
+21
-5
-2
+4
+1
+9
-58
+6
-95
-85
-5
+1
+7
+9
+15
-117
-12
-14
-18
+70
+9
-17
+93
-37
-134
-90
+22
-19
-7
-59
+14
-13
-47
+213
+81022
+9
+5
+4
-3
-16
-2
+4
+2
+5
-12
-9
-13
+2
-18
-18
-14
+7
+18
-19
+13
-1
-6
+9
-1
-18
+15
-14
-4
+12
-1
+5
+16
-7
+12
+6
-16
+13
+10
+3
-11
-13
+6
-7
+16
+3
-6
+19
-15
+14
-1
+19
+19
+13
-9
-3
-10
-14
+15
-9
+19
-6
+10
-7
+11
-1
+3
+2
-3
+8
+3
+13
+6
+3
+2
+18
+9
-17
+13
+15
-13
+9
+2
+19
+14
-13
+8
+18
+6
-4
-18
+1
-19
-1
+10
-5
-11
-10
-16
-4
-5
+3
-13
-19
-18
+16
+16
-5
+16
-10
-8
+9
+14
+1
+9
-3
+19
-12
+11
+12
+5
+19
-9
+4
+15
+19
-4
-10
-12
-18
-16
+13
-4
-16
-14
-15
+18
+1
-8
-7
-18
+3
-21
+9
-7
+8
+18
+2
-11
+6
+10
+9
+11
-21
+19
+4
+2
+7
+10
-16
+13
+9
+9
+16
+9
+13
-11
+16
+10
+14
+13
-5
-10
-16
-2
-2
+6
+19
+1
-16
+14
-13
+3
-5
-4
+12
-5
+22
+11
-5
+13
+4
+13
+19
+18
-13
+15
+19
-12
-11
-19
-12
+5
-19
+18
-19
+5
-13
-10
+15
-8
-2
-2
-11
-6
+5
-4
+21
+18
-5
+18
-11
+19
+12
-5
+4
-16
-10
+11
-16
+13
+11
-1
+15
+4
+13
-15
+14
-7
+19
+10
-8
+19
+4
-7
+19
+8
+14
-7
+3
+13
+19
-9
+4
-17
-19
-11
-11
-4
-16
-21
-5
+1
+16
-11
-15
-18
-13
-7
-13
-21
-18
+10
+14
+13
-7
-1
-4
+17
+20
+12
-24
+3
-8
+3
+10
+11
+11
-16
+13
+12
+19
-2
+7
+6
+5
+3
+10
+15
+2
+11
+14
-9
-1
-19
-16
+9
+17
-13
+4
+6
+2
+13
+16
+19
+12
+1
+18
+17
+19
+5
-8
+6
+10
+16
-9
+13
-8
-9
+5
-12
-7
-16
+4
-12
+18
-19
-7
+2
+2
-19
+10
+19
+9
-6
-18
+4
+18
-11
-13
-11
-16
+3
-4
-11
-2
+10
-14
+16
+14
-1
+2
+1
+4
-9
+17
-5
-14
-15
-13
+16
-8
-11
+2
+19
+23
+15
-13
+20
+3
+7
+9
+17
+10
-11
-19
-19
+9
-17
+12
-20
-22
+16
-9
-18
-10
-9
-81046

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

@ -21,6 +21,7 @@ description: Please see the README on GitHub at <https://github.com/iona
dependencies:
- base >= 4.7 && < 5
- containers
library:
source-dirs: src

View File

@ -1,6 +1,25 @@
module Day01 (main) where
import Data.Set (empty, insert, member)
freqChangeList :: String -> [Int]
freqChangeList = map (read . dropWhile (== '+')) . lines
totalFrequency :: [Int] -> Int
totalFrequency = foldr1 (+)
firstFreqTwice :: [Int] -> Int
firstFreqTwice changeList =
let freqs = scanl1 (+) $ cycle changeList
in dupl freqs empty
where dupl (f:fs) s =
if member f s
then f
else dupl fs (insert f s)
main :: IO ()
main = do
input <- readFile "input/01.txt"
print input
let changeList = freqChangeList input
print $ totalFrequency changeList
print $ firstFreqTwice changeList