Paste: AoC 2021 2-2

Author: nomennescio
Mode: factor
Date: Sun, 5 Dec 2021 20:04:14
Plain Text |
! 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> 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 <submarine>
  "input.2-1.txt" utf8 file-lines run
  [ hpos>> ] [ depth>> ] bi * . ;

MAIN: 2-2

New Annotation

Summary:
Author:
Mode:
Body: