Paste: AoC Day 1

Author: Kyoko Tomato
Mode: factor
Date: Fri, 2 Dec 2022 00:01:06
Plain Text |
USING: io.encodings.utf8 splitting math.parser sequences ;

: input ( -- contents ) "/tmp/aoc1.txt" utf8 file-contents ;

: greatest-calories ( contents -- n )
    "\n\n" split [ empty? ] split-when
    [ 0 [ dec> + ] reduce ] [ max ] map-reduce ;

: main ( -- n )
    input greatest-calories ;

Annotation: I forgot the IN: bit, and also, sum and supremum are a thing. So. Oops.

Author: Kyoko Tomato
Mode: factor
Date: Fri, 2 Dec 2022 00:18:35
Plain Text |
USING: io.encodings.utf8 splitting math.parser sequences ;
IN: aoc1

: input ( -- contents ) "/tmp/aoc1.txt" utf8 file-contents ;

: greatest-calories ( contents -- n )
    "\n" split [ empty? ] split-when
    [ [ dec> ] map sum ] map supremum ;

: main ( -- n )
    input greatest-calories ;

New Annotation

Summary:
Author:
Mode:
Body: