Paste: aoc25

Author: jonenst
Mode: factor
Date: Tue, 25 Dec 2018 13:36:43
Plain Text |
: (connected-components) ( key graph res -- )
[
  [ <bfs> [ 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

New Annotation

Summary:
Author:
Mode:
Body: