! 2021 nomennescio USING: accessors kernel io io.files io.encodings.utf8 locals math math.parser math.vectors namespaces prettyprint sequences sequences.windowed splitting words ; IN: aoc2021 TUPLE: submarine hpos depth aim ; C: submarine :: forward ( sm n -- sm' ) sm [ n + ] change-hpos [ n sm aim>> * + ] change-depth ; :: down ( sm n -- sm' ) sm [ n + ] change-aim ; : up ( sm n -- sm' ) neg down ; : run ( sm lines -- sm' ) [ " " split1 [ "aoc2021" lookup-word ] [ dec> ] bi* swap execute( sm n -- sm' ) ] each ; : 2-2 ( -- ) 0 0 0 "input.2-1.txt" utf8 file-lines run [ hpos>> ] [ depth>> ] bi * . ; MAIN: 2-2