Paste: AOC day 5
Author: | chunes |
Mode: | factor |
Date: | Sat, 5 Dec 2020 13:50:55 |
Plain Text |
USING: arrays combinators io.encodings.ascii io.files kernel
literals math math.functions math.order math.ranges
math.statistics prettyprint sequences sets ;
IN: aoc.2020.05
CONSTANT: input
$[ "resource:work/aoc/2020/05/input.txt" ascii file-lines ]
: front 2dup + 2/ nip ;
: back 2dup + 2 / ceiling spin drop ;
: partition
{
{ CHAR: F [ front ] }
{ CHAR: B [ back ] }
{ CHAR: L [ front ] }
[ drop back ]
} case ;
: row
0 127 rot 3 head* [ partition ] each drop ;
: col
0 7 rot 3 tail* [ partition ] each drop ;
: seat [ row ] [ col ] bi ;
: id [ 8 * ] [ + ] bi* ;
: part1 input [ seat id ] [ max ] map-reduce . ;
: part2
input [ seat id ] map dup minmax [a,b] swap diff first . ;
New Annotation