Paste: AoC 2022 Day 3

Author: nomennescio
Mode: factor
Date: Sat, 3 Dec 2022 06:06:24
Plain Text |
! 2022 nomennescio
USING: arrays assocs grouping io io.encodings.utf8 io.files
kernel math math.order math.parser math.statistics math.vectors
prettyprint sequences sets ;
IN: aoc2022

: parse-file ( path encoding -- pairs ) file-lines ;
: upper? ( ch -- ? ) 65 90 between? ;
: priority ( ch -- priority ) dup upper? [ CHAR: A - 27 + ] [ CHAR: a - 1 + ] if ;
: part1 ( -- ) "input-3.txt" utf8 parse-file [ dup length 2 / cut intersect first priority ] map-sum . ;
: part2 ( -- ) "input-3.txt" utf8 parse-file 3 group [ intersect-all first priority ] map-sum . ;
: day3 ( -- ) part1 part2 ;

MAIN: day3

Annotation: refactor

Author: nomennescio
Mode: factor
Date: Sat, 3 Dec 2022 06:40:02
Plain Text |
! ascii has the misleading LETTER? for upper?
: priority ( ch -- priority ) dup LETTER? [ CHAR: A - 27 + ] [ CHAR: a - 1 + ] if ;

New Annotation

Summary:
Author:
Mode:
Body: