Paste: advent of code 2018 part 1
Author: | itmuckel |
Mode: | factor |
Date: | Tue, 16 Jun 2020 17:26:16 |
Plain Text |
USING: assocs continuations hashtables io io.encodings.utf8 io.files
io.pathnames kernel locals math namespaces parser prettyprint sequences
sequences.extras ;
IN: advent-of-code
: puzzle-input ( relative-path -- seq )
current-directory get swap append-path utf8 file-lines ;
: part-1 ( seq-of-numbers -- solution )
[ parse-number ] map sum ;
: part-1-complete ( -- )
"./1.txt" puzzle-input part-1 . ;
:: produce-frequencies ( -- )
"./1.txt" puzzle-input [ parse-number ] map :> input!
0 :> current-frequency!
H{ { 0 0 } } :> frequencies!
f :> break!
[ break ]
[
input first :> a
current-frequency a + current-frequency!
current-frequency frequencies at
[
current-frequency .
t break!
] when
0 current-frequency frequencies set-at
frequencies :> frequencies!
input 1 rotate input!
]
until ;
New Annotation