Paste: aoc7

Author: jonenst
Mode: factor
Date: Fri, 7 Dec 2018 15:05:23
Plain Text |
: befores ( seq -- hash )
H{ } clone [ [ [ first2 ] dip push-at ] curry each ] keep ;
: afters ( seq -- graph )
H{ } clone [ [ [ first2 swap ] dip push-at ] curry each ] keep ;


: roots ( seq befores -- roots )
[ concat members ] [ keys ] bi* diff ;

: init-heap ( seq befores -- heap )
roots [ t ] H{ } map>assoc <min-heap> [ heap-push-all ] keep ;

:: aoc7-1 ( -- )
"/tmp/input" ascii file-lines
[ " " split { 1 7 } swap nths ] map :> seq
seq befores :> b
seq afters :> a

seq b init-heap :> h
<linked-hash> :> r
[ h heap-empty? ]
[ 
  h heap-pop nip :> cur
  t cur r set-at
  cur a at [| after |
    after b at [ r at ] all?
    [ t after h heap-push ] when
  ] each
] until
r keys concat print ;
aoc7-1

New Annotation

Summary:
Author:
Mode:
Body: