Paste: AoC 2022 day 1

Author: xr
Mode: factor
Date: Thu, 1 Dec 2022 09:35:45
Plain Text |
USING: io.encodings io.files.private math.parser splitting ;
IN: aoc2022-1
: load-file ( path -- seq ) cwd "/" append swap append utf8 file-lines ;

: group-elf ( seq -- seq ) [ empty? ] split-when ;

: elf-sum ( seq -- seq ) [ [ string>number ] map sum ] map ;

: max-list ( seq -- n ) 0 [ max ] reduce  ;

"2022-1.txt" load-file group-elf elf-sum
[ max-list ] keep
[ dup ] dip
remove
[ max-list ] keep
[ dup ] dip
remove
max-list
+ +

Annotation: different combinators

Author: xr
Mode: factor
Date: Thu, 1 Dec 2022 09:53:24
Plain Text |
USING: io.encodings io.files.private math.parser splitting combinators.extras ;
IN: aoc2022-1
: load-file ( path -- seq ) cwd "/" append swap append utf8 file-lines ;

: group-elf ( seq -- seq ) [ empty? ] split-when ;

: elf-sum ( seq -- seq ) [ [ string>number ] map sum ] map ;

: max-list ( seq -- n ) 0 [ max ] reduce  ;

"2022-1.txt" load-file group-elf elf-sum
[ [ max-list dup ] keep remove ] twice
max-list
+ +

Annotation: Deal with duplicates

Author: xr
Mode: factor
Date: Thu, 1 Dec 2022 10:06:07
Plain Text |
USING: io.encodings io.files.private math.parser splitting combinators.extras ;
IN: aoc2022-1
: load-file ( path -- seq ) cwd "/" append swap append utf8 file-lines ;

: group-elf ( seq -- seq ) [ empty? ] split-when ;

: elf-sum ( seq -- seq ) [ [ string>number ] map sum ] map ;

: max-list ( seq -- n ) 0 [ max ] reduce  ;

"2022-1.txt" load-file group-elf elf-sum
[ [ max-list dup ] keep remove-first ] twice
max-list
+ +

Annotation: Deal with duplicates

Author: xr
Mode: factor
Date: Thu, 1 Dec 2022 10:26:10
Plain Text |
USING: io.encodings io.files.private math.parser splitting combinators.extras sequences.extras ;
IN: aoc2022-1
: load-file ( path -- seq ) cwd "/" append swap append utf8 file-lines ;

: group-elf ( seq -- seq ) [ empty? ] split-when ;

: elf-sum ( seq -- seq ) [ [ string>number ] map sum ] map ;

: max-list ( seq -- n ) 0 [ max ] reduce  ;

"2022-1.txt" load-file group-elf elf-sum
[ [ max-list dup ] keep remove-first ] twice
max-list
+ +

New Annotation

Summary:
Author:
Mode:
Body: