Paste: aoc day 3

Author: Kren/chunes
Mode: factor
Date: Sat, 3 Dec 2022 05:15:09
Plain Text |
USING: grouping io.encodings.ascii io.files kernel literals math
prettyprint sequences sets unicode ;
IN: aoc2022.day03

CONSTANT: input $[
    "resource:work/aoc2022/day03/input.txt" ascii file-lines
]

: priority-sum-by ( ... seq quot: ( ... seq -- ... n ) -- ... n )
    '[ @ [ first ] keep upper? 38 96 ? - ] map-sum ; inline

: part1 ( -- )
    input [ halves intersect ] priority-sum-by . ;

: part2 ( -- )
    input 3 group [ intersect-all ] priority-sum-by . ;

: day03 ( -- ) part1 part2 ;

MAIN: day03

Annotation: slight tweak

Author: Kren/chunes
Mode: factor
Date: Sat, 3 Dec 2022 05:33:32
Plain Text |
USING: ascii grouping io.encodings.ascii io.files kernel
literals math prettyprint sequences sets ;
IN: aoc2022.day03

CONSTANT: input $[
    "resource:work/aoc2022/day03/input.txt" ascii file-lines
]

: priority-sum-by ( ... seq quot: ( ... seq -- ... n ) -- ... n )
    '[ @ first dup letter? 96 38 ? - ] map-sum ; inline

: part1 ( -- )
    input [ halves intersect ] priority-sum-by . ;

: part2 ( -- )
    input 3 group [ intersect-all ] priority-sum-by . ;

: day03 ( -- ) part1 part2 ;

MAIN: day03

Annotation: final version

Author: Kren/chunes
Mode: factor
Date: Sun, 4 Dec 2022 01:28:01
Plain Text |
USING: ascii grouping io.encodings.ascii io.files kernel
literals math prettyprint sequences sets ;
IN: aoc2022.day03

CONSTANT: input $[
    "vocab:aoc2022/day03/input.txt" ascii file-lines
]

: priority-sum-by ( ... seq quot: ( ... seq -- ... n ) -- ... n )
    '[ @ first dup letter? 96 38 ? - ] map-sum ; inline

: part1 ( -- )
    input [ halves intersect ] priority-sum-by . ;

: part2 ( -- )
    input 3 <groups> [ intersect-all ] priority-sum-by . ;

: day03 ( -- ) part1 part2 ;

MAIN: day03

Annotation: final version for real

Author: Kren/chunes
Mode: factor
Date: Sun, 4 Dec 2022 01:33:20
Plain Text |
USING: ascii grouping io.encodings.ascii io.files kernel
literals math prettyprint sequences sets ;
IN: aoc2022.day03

CONSTANT: input $[
    "vocab:aoc2022/day03/input.txt" ascii file-lines
]

: priority-sum-by ( ... seq quot: ( ... seq -- ... newseq ) -- ... n )
    '[ @ first dup letter? 96 38 ? - ] map-sum ; inline

: part1 ( -- )
    input [ halves intersect ] priority-sum-by . ;

: part2 ( -- )
    input 3 <groups> [ intersect-all ] priority-sum-by . ;

: day03 ( -- ) part1 part2 ;

MAIN: day03

New Annotation

Summary:
Author:
Mode:
Body: