🏡 index : ~doyle/aoc.git

author Jordan Doyle <jordan@doyle.la> 2023-12-10 4:57:55.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-12-10 4:57:55.0 +00:00:00
commit
4cdc3bbf23d2b7ce96d5d256c990d44746def85c [patch]
tree
2927716432040e5c8caddc2a1865c5da54f78f55
parent
55f89dc92fe84f528eb7cae3c17178964359e98e
download
4cdc3bbf23d2b7ce96d5d256c990d44746def85c.tar.gz

Add 2022 day 4



Diff

 treefmt.nix        |  1 +
 2022/4/4.jsonnet   | 18 ++++++++++++++++++
 2022/4/default.nix | 14 ++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/treefmt.nix b/treefmt.nix
index 9c9d5e7..288585d 100644
--- a/treefmt.nix
+++ a/treefmt.nix
@@ -9,5 +9,6 @@
    statix.enable = true;
    rustfmt.enable = true;
    fprettify.enable = true;
    jsonnetfmt.enable = true;
  };
}
diff --git a/2022/4/4.jsonnet b/2022/4/4.jsonnet
new file mode 100644
index 0000000..586a07d 100644
--- /dev/null
+++ a/2022/4/4.jsonnet
@@ -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,
}
diff --git a/2022/4/default.nix b/2022/4/default.nix
new file mode 100644
index 0000000..00c0efe 100644
--- /dev/null
+++ a/2022/4/default.nix
@@ -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
  '';
}