aoc-forth

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

02b.f (528B) - raw


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