Paste: AOC Day 3

Author: Kacarott
Mode: factor
Date: Sat, 3 Dec 2022 07:34:45
Plain Text |
! Copyright (C) 2022 Keldan Chapman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel AOC prettyprint splitting sequences math math.statistics
       assocs grouping sets ;
IN: AOC.2022.3

: find-wrong ( rucksack -- item )
    dup length 2 / [ head histogram ] [ tail histogram ] 2bi
    assoc-intersect keys first ;

: find-badge ( seq -- badge ) intersect-all first ;

: get-priority ( item -- value ) 96 - dup neg? [ 58 + ] when ;

: part-1 ( input -- result )
    "\n" split harvest [ find-wrong get-priority ] map-sum ;

: part-2 ( input -- result )
    "\n" split harvest 3 <groups> [ find-badge get-priority ] map-sum ;

MAIN: [ 3 read-day-input [ part-1 . ] [ part-2 . ] bi ]

New Annotation

Summary:
Author:
Mode:
Body: