Paste: AOC day 5 clever

Author: chunes
Mode: factor
Date: Sat, 5 Dec 2020 13:52:51
Plain Text |
! NOTE: The following idea is not mine; this is merely a 
! clever solution I saw on reddit that warranted translating 
! to Factor.

! Credit to /u/smokebath at
! https://www.reddit.com/r/adventofcode/comments/k71h6r/2020_day_05_solutions/geo9q7f/

USING: io.encodings.ascii io.files kernel literals math.order
math.parser math.ranges math.statistics multiline peg.ebnf
prettyprint sequences sets ;
IN: aoc.2020.05clever

CONSTANT: input
    $[ "resource:work/aoc/2020/05/input.txt" ascii file-lines ]

EBNF: id [=[
    zero = [FL] => [[ drop CHAR: 0 ]]
    one = [BR] => [[ drop CHAR: 1 ]]
    bin = (zero|one)+ => [[ bin> ]]
]=]

: part1 ( -- ) input [ id ] [ max ] map-reduce . ;

: part2 ( -- )
    input [ id ] map dup minmax [a,b] swap diff first . ;

New Annotation

Summary:
Author:
Mode:
Body: