From cdee7f76a018e7313258318047d0becb8b59b974 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 7 Dec 2024 01:35:34 +0100 Subject: 2024-01 in factor --- 2024/01-Historian_Hysteria/01-tests.factor | 7 +++++++ 2024/01-Historian_Hysteria/01.factor | 33 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 2024/01-Historian_Hysteria/01-tests.factor create mode 100644 2024/01-Historian_Hysteria/01.factor diff --git a/2024/01-Historian_Hysteria/01-tests.factor b/2024/01-Historian_Hysteria/01-tests.factor new file mode 100644 index 0000000..48c6cb2 --- /dev/null +++ b/2024/01-Historian_Hysteria/01-tests.factor @@ -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 diff --git a/2024/01-Historian_Hysteria/01.factor b/2024/01-Historian_Hysteria/01.factor new file mode 100644 index 0000000..a34721e --- /dev/null +++ b/2024/01-Historian_Hysteria/01.factor @@ -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 + +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 -- cgit v1.2.3