: (connected-components) ( key graph res -- ) [ [ [ t swap find-path drop ] keep in-closed-set>> ] keep ] dip [ nip adjoin ] [ drop swap [ nip in? ] curry assoc-reject! drop ] 3bi ; : connected-components ( graph -- components ) V{ } clone [ [ over assoc-size zero? ] [ over keys first 2over (connected-components) ] until 2drop ] keep ; "/tmp/input" ascii file-lines [ "," split [ string>number ] map ] map 2 selections [ first2 [ - abs ] 2map sum 3 <= ] filter natural-sort [ first ] group-by [ first2 [ second ] map 2array ] map >hashtable connected-components length