! Copyright (C) 2022 Your name. ! See http://factorcode.org/license.txt for BSD license. USING: sets grouping combinators kernel math io.files io.encodings.utf8 sequences ; IN: aoc2022-3 : split-string ( seq -- first second ) dup length 2 / cut ; : load-file ( path -- seq ) utf8 file-lines ; : duplicate-item ( seq seq -- item ) intersect first ; : reduce1 ( seq quot -- n ) [ unclip ] dip reduce ; inline ! if larger or equal to A do ... else do ... : score ( n -- n ) { { [ dup CHAR: a >= ] [ CHAR: a - 1 + ] } { [ dup CHAR: A >= ] [ CHAR: A - 27 + ] } } cond ; CONSTANT: input "resource:/work/aoc2022-3/input.txt" : part1 ( -- n ) input load-file [ split-string duplicate-item score ] map-sum ; : part2 ( -- n ) input load-file 3 group [ [ intersect ] reduce1 first score ] map-sum ;