USING: accessors alien.c-types classes.struct combinators hash-sets hashtables kernel locals math math.parser sequences sets specialized-vectors vectors ; IN: ant STRUCT: point { x uint } { y uint } ; SPECIALIZED-VECTOR: point : ( x y -- point ) point ; inline : push-point ( x y stack -- ) push-new [ y<< ] [ x<< ] bi ; 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 point-vector{ } clone :> stack 0 :> total! 1000 1000 stack push [ stack empty? ] [ stack pop clone :> p p seen in? [ p seen adjoin p walkable? [ total 1 + total! p >point< stack { [ [ 1 + ] 2dip push-point ] [ [ 1 - ] 2dip push-point ] [ [ 1 + ] dip push-point ] [ [ 1 - ] dip push-point ] } 3cleave ] when ] unless ] until total ;