meta: add lib and refactor

This commit is contained in:
Max Headroom 2022-12-02 16:07:12 +01:00
parent d5b828b1b9
commit bfc3d61f5d
5 changed files with 19 additions and 29 deletions

View file

@ -1,14 +1,7 @@
with import <nixpkgs/lib>;
with import ../lib;
let
input = fileContents ./input.txt;
splitStr = pattern: flip pipe [
(strings.split pattern)
(filter isString)
];
sum = foldl' add 0;
in
pipe input [

View file

@ -1,12 +1,7 @@
with import <nixpkgs/lib>;
with import ../lib;
let
input = fileContents ./input.txt;
splitStr = pattern: flip pipe [
(strings.split pattern)
(filter isString)
];
in
pipe input [
@ -14,7 +9,7 @@ pipe input [
(map (flip pipe [
(splitStr "\n")
(map toInt)
(foldl' add 0)
sum
]))
(foldl' max 0)
]

View file

@ -1,13 +1,8 @@
with import <nixpkgs/lib>;
with import ../lib;
let
input = fileContents ./input.txt;
splitStr = pattern: flip pipe [
(strings.split pattern)
(filter isString)
];
score = myAction: opponentShape: {
X.A = 0 + 3;
X.B = 0 + 1;
@ -28,5 +23,5 @@ pipe input [
elemAt
(get: score (get 1) (get 0))
]))
(foldl' add 0)
sum
]

View file

@ -1,13 +1,8 @@
with import <nixpkgs/lib>;
with import ../lib;
let
input = fileContents ./input.txt;
splitStr = pattern: flip pipe [
(strings.split pattern)
(filter isString)
];
score = myShape: opponentShape: {
X.A = 3 + 1;
X.B = 0 + 1;
@ -28,5 +23,5 @@ pipe input [
elemAt
(get: score (get 1) (get 0))
]))
(foldl' add 0)
sum
]

12
lib/default.nix Normal file
View file

@ -0,0 +1,12 @@
let
nixpkgsLib = import <nixpkgs/lib>;
aocLib = with nixpkgsLib; {
splitStr = pattern: flip pipe [
(strings.split pattern)
(filter isString)
];
sum = foldl' add 0;
};
in nixpkgsLib // aocLib