Paste: aoc12

Author: jon
Mode: factor
Date: Tue, 12 Dec 2017 14:59:01
Plain Text |
! 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 )
    <bfs> [ [ 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 ;

New Annotation

Summary:
Author:
Mode:
Body: