meta: add lib and refactor
This commit is contained in:
parent
d5b828b1b9
commit
bfc3d61f5d
5 changed files with 19 additions and 29 deletions
|
@ -1,14 +1,7 @@
|
||||||
with import <nixpkgs/lib>;
|
with import ../lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
input = fileContents ./input.txt;
|
input = fileContents ./input.txt;
|
||||||
|
|
||||||
splitStr = pattern: flip pipe [
|
|
||||||
(strings.split pattern)
|
|
||||||
(filter isString)
|
|
||||||
];
|
|
||||||
|
|
||||||
sum = foldl' add 0;
|
|
||||||
in
|
in
|
||||||
|
|
||||||
pipe input [
|
pipe input [
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
with import <nixpkgs/lib>;
|
with import ../lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
input = fileContents ./input.txt;
|
input = fileContents ./input.txt;
|
||||||
|
|
||||||
splitStr = pattern: flip pipe [
|
|
||||||
(strings.split pattern)
|
|
||||||
(filter isString)
|
|
||||||
];
|
|
||||||
in
|
in
|
||||||
|
|
||||||
pipe input [
|
pipe input [
|
||||||
|
@ -14,7 +9,7 @@ pipe input [
|
||||||
(map (flip pipe [
|
(map (flip pipe [
|
||||||
(splitStr "\n")
|
(splitStr "\n")
|
||||||
(map toInt)
|
(map toInt)
|
||||||
(foldl' add 0)
|
sum
|
||||||
]))
|
]))
|
||||||
(foldl' max 0)
|
(foldl' max 0)
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
with import <nixpkgs/lib>;
|
with import ../lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
input = fileContents ./input.txt;
|
input = fileContents ./input.txt;
|
||||||
|
|
||||||
splitStr = pattern: flip pipe [
|
|
||||||
(strings.split pattern)
|
|
||||||
(filter isString)
|
|
||||||
];
|
|
||||||
|
|
||||||
score = myAction: opponentShape: {
|
score = myAction: opponentShape: {
|
||||||
X.A = 0 + 3;
|
X.A = 0 + 3;
|
||||||
X.B = 0 + 1;
|
X.B = 0 + 1;
|
||||||
|
@ -28,5 +23,5 @@ pipe input [
|
||||||
elemAt
|
elemAt
|
||||||
(get: score (get 1) (get 0))
|
(get: score (get 1) (get 0))
|
||||||
]))
|
]))
|
||||||
(foldl' add 0)
|
sum
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
with import <nixpkgs/lib>;
|
with import ../lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
input = fileContents ./input.txt;
|
input = fileContents ./input.txt;
|
||||||
|
|
||||||
splitStr = pattern: flip pipe [
|
|
||||||
(strings.split pattern)
|
|
||||||
(filter isString)
|
|
||||||
];
|
|
||||||
|
|
||||||
score = myShape: opponentShape: {
|
score = myShape: opponentShape: {
|
||||||
X.A = 3 + 1;
|
X.A = 3 + 1;
|
||||||
X.B = 0 + 1;
|
X.B = 0 + 1;
|
||||||
|
@ -28,5 +23,5 @@ pipe input [
|
||||||
elemAt
|
elemAt
|
||||||
(get: score (get 1) (get 0))
|
(get: score (get 1) (get 0))
|
||||||
]))
|
]))
|
||||||
(foldl' add 0)
|
sum
|
||||||
]
|
]
|
||||||
|
|
12
lib/default.nix
Normal file
12
lib/default.nix
Normal 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
|
Reference in a new issue