Paste: aoc day5

Author: jonenst
Mode: factor
Date: Wed, 5 Dec 2018 17:04:25
Plain Text |
: delete-all-matching ( deque node --  dequeu node' )
dup next>> dup [
  2dup [ node-value ] bi@ [ max ] [ min ] 2bi 32 + =
  [ pick pick prev>> dup [ drop over next>> ] unless [ [ swap delete-node ] bi-curry@ bi ]
  2dip delete-all-matching ] [ nip delete-all-matching ] if
] [ nip ] if ;

: polymer-length ( str -- length )
  <dlist> [ push-all-back ] keep
  dup front>> delete-all-matching drop
  0 swap [ drop 1 + ] slurp-deque ;
: day5-1 ( -- count )
"/tmp/input" ascii file-lines first polymer-length
 ;

: reject-polymer ( str n -- str' )
  CHAR: A + dup 32 + [ [ = ] bi-curry@ bi or ] 2curry reject ;
: day5-2 ( -- count )
"/tmp/input" ascii file-lines first
  0 26 [a,b) [ reject-polymer polymer-length ] with map infimum  ;
day5-1 . day5-2 .

New Annotation

Summary:
Author:
Mode:
Body: