2024-01 in factor
This commit is contained in:
parent
fe5c243db7
commit
cdee7f76a0
2 changed files with 40 additions and 0 deletions
7
2024/01-Historian_Hysteria/01-tests.factor
Normal file
7
2024/01-Historian_Hysteria/01-tests.factor
Normal file
|
@ -0,0 +1,7 @@
|
|||
! Copyright (C) 2024 Julien (adyxax) Dessaux.
|
||||
! See https://git.adyxax.org/adyxax/advent-of-code/tree/LICENSE for EUPL license.
|
||||
USING: tools.test aoc.2024.01.private ;
|
||||
IN: aoc.2024.01.tests
|
||||
|
||||
{ 11 } [ "example" part1 ] unit-test
|
||||
{ 31 } [ "example" part2 ] unit-test
|
33
2024/01-Historian_Hysteria/01.factor
Normal file
33
2024/01-Historian_Hysteria/01.factor
Normal file
|
@ -0,0 +1,33 @@
|
|||
! Copyright (C) 2024 Julien (adyxax) Dessaux.
|
||||
! See https://git.adyxax.org/adyxax/advent-of-code/tree/LICENSE for EUPL license.
|
||||
USING: assocs io io.encodings.utf8 io.files kernel math math.parser
|
||||
math.statistics namespaces prettyprint sequences sorting splitting ;
|
||||
IN: aoc.2024.01
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: load_input ( filename -- array array )
|
||||
"~/git/adyxax/aoc/2024/01-Historian_Hysteria/"
|
||||
swap append utf8 file-lines
|
||||
[ split-words harvest ] map unzip
|
||||
[ [ string>number ] map ] bi@ ;
|
||||
|
||||
: part1 ( filename -- n )
|
||||
load_input
|
||||
[ sort ] bi@
|
||||
[ - abs ] 2map
|
||||
sum ;
|
||||
|
||||
: part2 ( filename -- n )
|
||||
load_input
|
||||
histogram ! turns an array into a hashtable of { value occurrences }
|
||||
'[ dup _ at 0 or * ] map
|
||||
sum ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: aoc202401 ( -- )
|
||||
"input" part1 pprint nl
|
||||
"input" part2 pprint nl ;
|
||||
|
||||
MAIN: aoc202401
|
Loading…
Add table
Reference in a new issue