Add 2022 day 4
Diff
treefmt.nix | 1 +
2022/4/4.jsonnet | 18 ++++++++++++++++++
2022/4/default.nix | 14 ++++++++++++++
3 files changed, 33 insertions(+)
@@ -9,5 +9,6 @@
statix.enable = true;
rustfmt.enable = true;
fprettify.enable = true;
jsonnetfmt.enable = true;
};
}
@@ -1,0 +1,18 @@
local input = importstr './input';
local parsedInput = [[[std.parseInt(z) for z in std.split(y, '-')] for y in std.split(x, ',')] for x in std.split(input, '\n')];
local part1 = std.sum([
if ((x[0][0] >= x[1][0] && x[0][1] <= x[1][1]) || (x[1][0] >= x[0][0] && x[1][1] <= x[0][1])) then 1 else 0
for x in parsedInput
]);
local part2 = std.sum([
if (x[0][0] <= x[1][1] && x[0][1] >= x[1][0]) then 1 else 0
for x in parsedInput
]);
{
part1: part1,
part2: part2,
}
@@ -1,0 +1,14 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.stdenv.mkDerivation rec {
name = "aoc-2022-4";
src = ./.;
phases = [ "buildPhase" ];
doCheck = true;
buildInputs = with pkgs; [ go-jsonnet ];
buildPhase = ''
jsonnet $src/4.jsonnet > $out
'';
}