! Copyright (C) 2020 Your name. ! See http://factorcode.org/license.txt for BSD license. 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 ! advent of code 2018 : 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 ;