! 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