USING: accessors combinators hash-sets hashtables kernel locals math math.parser sequences sets vectors ; IN: ant : sum-digits ( n -- x ) 0 swap [ dup zero? ] [ 10 [ mod + ] [ /i ] 2bi ] until drop ; TUPLE: point x y ; C: point : walkable? ( point -- ? ) [ x>> ] [ y>> ] bi [ sum-digits ] bi@ + 25 <= ; :: ant ( -- total ) HS{ } clone :> seen V{ } clone :> stack 0 :> total! 1000 1000 stack push [ stack empty? total 10000 > or ] [ stack pop :> p p seen in? [ p seen adjoin p walkable? [ total 1 + total! p clone [ 1 + ] change-x stack push p clone [ 1 - ] change-x stack push p clone [ 1 + ] change-y stack push p clone [ 1 - ] change-y stack push ] when ] unless ] until total ;