Paste: AoC day 3

Author: Garklein
Mode: factor
Date: Sat, 3 Dec 2022 13:55:31
Plain Text |
USING: io.encodings.utf8 io.files kernel math math.ranges
sequences sets ;
IN: aoc.3

: input ( -- i ) "~/factor/aoc/3/3.in" utf8 file-lines ;

: halves ( s -- {s,s} ) dup length 2/ cut { } 2sequence ;

: priorities ( -- p ) 97 122 [a,b] 65 90 [a,b] append ;

: intersection-score ( seq -- n ) intersection first priorities index 1 + ;

: part1 ( -- n ) input [ halves intersection-score ] map-sum ;

: 3chunk ( seq -- seq ) { } swap [ dup empty? ] [ 3 cut [ suffix ] dip ] until drop ;

: part2 ( -- n ) input 3chunk [ intersection-score ] map-sum ;

Annotation: edits after reading others' solutions

Author: Garklein
Mode: factor
Date: Sat, 3 Dec 2022 14:14:08
Plain Text |
USING: grouping io.encodings.utf8 io.files kernel math
math.ranges sequences sets ;
IN: aoc.3

: input ( -- i ) "~/factor/aoc/3/3.in" utf8 file-lines ;

: priorities ( -- p ) 97 122 [a,b] 65 90 [a,b] append ;

: intersection-score ( seq -- n ) intersection first priorities index 1 + ;

: part1 ( -- n ) input [ halves { } 2sequence intersection-score ] map-sum ;

: part2 ( -- n ) input 3 <groups> [ intersection-score ] map-sum ;

New Annotation

Summary:
Author:
Mode:
Body: