USING: accessors alien.c-types classes.struct combinators hash-sets hashtables kernel locals math math.parser sequences sets specialized-vectors vectors ; IN: ant ! TUPLE: point { x uint } { y uint } ; ! : ( x y -- point ) point boa ; inline STRUCT: point { x uint } { y uint } ; : ( x y -- point ) point ; inline : push-point ( x y stack -- ) [ ] dip push ; inline : >point< ( point -- x y ) [ x>> ] [ y>> ] bi ; inline : sum-digits ( n -- x ) 0 swap [ dup zero? ] [ 10 /mod swap [ + ] dip ] until drop ; inline : walkable? ( point -- ? ) [ x>> ] [ y>> ] bi [ sum-digits ] bi@ + 25 <= ; inline :: ant ( -- total ) HS{ } clone :> seen 200,000 :> stack 1000 1000 stack push 0 [ stack empty? ] [| total | stack pop :> p p seen in? [ total ] [ p seen adjoin p walkable? [ p >point< stack { [ [ 1 + ] 2dip push-point ] [ [ 1 - ] 2dip push-point ] [ [ 1 + ] dip push-point ] [ [ 1 - ] dip push-point ] } 3cleave total 1 + ] [ total ] if ] if ] until ;