git.alexw.nyc home about git garden
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
f<< /lib/array.fs

1000 const gridsize 

struct[ Point
    field x
    field y
    : :up ( -- ) to1+ y ;
    : :down ( -- ) to1- y ;
    : :left to1- x ;
    : :right to1+ x ;
    : :gridoffset x gridsize * y + ;
    : :new ( x y -- ) here# >r swap , , r> ;
]struct 

0 0 Point :new structbind Point head
0 0 Point :new structbind Point tail

create grid gridsize dup * cells allot ;

: updatetail 
  \ tail :gridoffset grid + 1 swap !
;

: U word head :up updatetail ;
: D word head :down updatetail ;
: L word head :left updatetail ;
: R word head :right updatetail ;

\ f<< /aoc/input