! Copyright (C) 2017 Jon Harper`. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs kernel math path-finding sequences sets splitting ; IN: aoc.2017.12 : parse-input ( lines -- assoc ) H{ } [ [ [ " <-> ," split harvest unclip ] dip set-at ] curry each ] keep ; : bfs ( from assoc -- visited ) [ [ f ] dip find-path drop ] keep in-closed-set>> ; : p1 ( lines -- n ) parse-input [ "0" ] dip bfs cardinality ; : p2 ( lines -- n ) parse-input [ 0 ] dip [ keys empty? ] [ [ [ keys first ] keep bfs members ] [ [ delete-at ] curry each ] bi 1 + ] bi-curry until ;