Paste: AOC day 20 part 1
Author: | chunes |
Mode: | factor |
Date: | Sun, 20 Dec 2020 11:37:22 |
Plain Text |
USING: accessors assocs columns io.encodings.ascii io.files
kernel literals math.parser prettyprint sequences
sequences.extras sets sets.extras splitting strings ;
IN: aoc.2020.20
<<
: ?>string ( obj -- obj/str ) dup sequence? [ >string ] when ;
: prune ( seq -- first last )
[ first ] [ last ] bi [ ?>string ] bi@ ;
: (edges) ( seq -- newseq )
[ [ prune ] [ <flipped> prune ] bi ] [ 4sequence ] bi ;
: edge>id ( seq -- n )
{ { CHAR: . CHAR: 0 } { CHAR: # CHAR: 1 } }
substitute bin> ;
: edges ( seq -- newseq )
(edges) dup [ reverse ] map append [ edge>id ] map ;
TUPLE: tile data id edges ;
C: <tile> tile
>>
CONSTANT: input $[
"input2.txt" ascii file-lines { "" } split
[ unclip "Tile: " without dec> over edges <tile> ] map
]
: part1 ( -- )
input [ edges>> ] map-concat non-repeating input
[ edges>> intersect length 4 = ] with filter
[ id>> ] map-product . ;
New Annotation