aoc-forth

Advent of code solutions in UF forth
git clone git://git.alexwennerberg.com/aoc-forth
Log | Files | Refs | README

02a.f (410B) - raw


      1 \ doesnt need stdin, reads from file named "input.txt"
      2 include dmath.f
      3 
      4 variable horiz 0 horiz !
      5 variable depth 0 depth !
      6 
      7 : to-num ( a u -- n ) 0 -rot 0 do dup r@ + c@ h# 30 - rot 10 * + swap loop drop ;
      8 : get-n bl parse to-num ;
      9 : forward ( "N" -- ) get-n horiz +! ;
     10 : down ( "N" -- ) get-n depth +! ;
     11 : up ( "N" -- ) get-n negate depth +! ;
     12 : solve horiz @ depth @ um* ;
     13 
     14 include input.txt
     15 
     16 solve d. cr bye