2024 day 4 part 1

This commit is contained in:
tristan 2024-12-04 15:36:46 +00:00
parent 66576e5acb
commit 5dee6636c7
6 changed files with 392 additions and 0 deletions

10
2024/04/example.txt Normal file
View file

@ -0,0 +1,10 @@
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX

59
2024/04/flake.lock Normal file
View file

@ -0,0 +1,59 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1732837521,
"narHash": "sha256-jNRNr49UiuIwaarqijgdTR2qLPifxsVhlJrKzQ8XUIE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "970e93b9f82e2a0f3675757eb0bfc73297cc6370",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1703013332,
"narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=",
"path": "/nix/store/50bgi74d890mpkp90w1jwc5g0dw4dccr-source",
"rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"tix": "tix"
}
},
"tix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1704309534,
"narHash": "sha256-U9qeMl0WBlpy335gL06WFGvPxLBTd+ToiiCHUHWrgR0=",
"ref": "refs/heads/master",
"rev": "5007770e88c4d5f67c3790761a1125904a9ef257",
"revCount": 20,
"type": "git",
"url": "https://git.tristans.cloud/tristan/tix"
},
"original": {
"type": "git",
"url": "https://git.tristans.cloud/tristan/tix"
}
}
},
"root": "root",
"version": 7
}

31
2024/04/flake.nix Normal file
View file

@ -0,0 +1,31 @@
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
tix.url = "git+https://git.tristans.cloud/tristan/tix";
};
outputs = { self, nixpkgs, tix }: let
pkgs = import nixpkgs {system = "x86_64-linux";};
solution = import ./solution.nix pkgs;
in {
part1example = (solution (pkgs.lib.readFile ./example.txt)).part1result;
part1 = (solution (pkgs.lib.readFile ./input.txt)).part1result;
part2example = (solution (pkgs.lib.readFile ./example.txt)).part2result;
part2 = (solution (pkgs.lib.readFile ./input.txt)).part2result;
packages.x86_64-linux.watch = tix.watch {
cmd = ''
nix run .\#test --impure --extra-experimental-features pipe-operators
'';
};
packages.x86_64-linux.test = tix.run [
./solution.test.nix
];
};
}

140
2024/04/input.txt Normal file
View file

@ -0,0 +1,140 @@
XMXXXMMXXSXMSMMMSXMSSSMASXMAXSMMMAASAMXASASXSXSASMSMSSSXSMASXMMSAMMMSAMXSMMMAMMSMMSXSAMXMSMSASMSMSMSSSMMSMMMMMASMSSMSSXMAMXMASAMAMXSXSXMMASA
MXMMMMMSXMASMMAASAMXMASAMXMXXSAASMMSAMXXAAXAAAAAXAAXAXMASXASAXAAASAXAASMXMAMXMAXMAMAMAMXXSAMXAXAAAAXAAAMAMAMMSAMSAXAMMSMAMSMMAMXSXMSAMXXSASX
XAAMAAAMXXMMASMMMXMASMMXSAXSAMSMSAASAMMSMSMMMMMAMSMSXXMXMMMSAMSSMMASXMMMXSSSSMSSMASASAMMMMAMMMSMSMSMSMMMSSXMAMAMXMMXMAAXXXAASAMAMASMXMAXMASA
SSMXSMSMXSSSMMMXMXAMXAAASASMXMASXMMSXMAAXAAAXMXAXAXSMMMAMAMMMMXAXXXMAXMXAXXAAAMAMAXXSASXASAMAAXXXAXAXSMMAAAMSSSMMXAMMSSSMMSMMAMASXMAAMMXMXMX
AAAXMAXMAXAAAXAAMXSSSMMMSXXMASMSMMASAMSSMMSXSXSASMAMAAXMSAXAAMXMMMMSXMSMSSMSMMMAMMSMSMMMXMAMSASAMAMXSASMMMMAAAAMSMSAMAMAAXM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AMMASXASXMAXMSMMSAAAMMXMSAMAAMSSMXSXAXAMMASXAAXMXAMMSXS
MAMAMMMMSSMMSXSAMMMMMASMMMMAXXAMASMMMMMMXXSAXASMSMSMMAMMAMXAASXMXMAXAXAAMAMSMXMASAMXMSMMAMMAXAMAMAXSASXSSSMSAMXMASMMAMAMMXMAMMMAMXXSMMSAMXMA
MAMAMAAAMXAAAXAMXAAAMXMASXXSXMMMAMXXAAAMAXMMSXAAAXXXMSMMMSMMXMAXAMXMMMMMSAXAMAMXXAXMXXXMMMAMMSMXXAMMXSXMAAASMXSAMXMMXMAMMMSAMXSSMSXAAAXAMASX
SASASMSSMSMMSSMXSSSMSASXMMMMMAAMMSMSSSSSMSSXAMMXMASMXMASAAASXSMMSSMMXSAASMSMSASXSMMSAMMSSMSAAXAXMSMSMSAMSMMMSASASXSSMSXSAAMAMAAAASMMMMSASASA
SASASMAMMAAAAAXAXAAASASXAAAAASXMSAAXAAAMAAXXMAXAXMAAASMMSSSMAAXAAAAMASMMMAAASASAAXXMASAAAAAMSMXMAAAAASMMAAAAMMSAMXXAAAXMMMSAMXSMMMMSAMXXMASM
MXMXMMSMSSSMSSMXSMMMMSXMASMSXXAMSMMMMMMMMMSMXSSXSXXSASXXMXMMSMMMSSSMXSXXMSMMMSMMMMXSAMMSSMXXXXMASMSMMMMASMMSSXMXMASMMMSXMASASXMXMASXXSAAMMMX

72
2024/04/solution.nix Normal file
View file

@ -0,0 +1,72 @@
{lib, ...}: input: rec {
content = lib.trim input;
emptyLines = lines: lines
|> builtins.length
|> genStrList ""
;
genStrList = str: builtins.genList (_: str);
rotated = input: input
|> lib.strings.splitString "\n"
|> map (lib.stringToCharacters)
|> (lines: builtins.foldl'
(lib.zipListsWith (a: b: a + b))
(emptyLines lines)
lines)
|> lib.concatStringsSep "\n"
;
len = builtins.length (lib.strings.splitString "\n" content);
diagonal = input: input
|> lib.strings.splitString "\n"
|> map (lib.stringToCharacters)
|> (lines: builtins.foldl'
({acc, i}: line: {
acc = lib.zipListsWith (a: b: a + b) acc
((genStrList " " i) ++ line ++ (genStrList " " (len - i)));
i = i + 1;
})
{
acc = (emptyLines lines) ++ emptyLines (builtins.elemAt lines 0);
i = 0;
}
lines)
|> ({acc, ...}: acc)
|> map lib.trim
|> lib.concatStringsSep "\n"
;
reversed = input: input
|> lib.strings.splitString "\n"
|> map reverseString
|> lib.concatStringsSep "\n"
;
reverseString = s: s
|> lib.stringToCharacters
|> lib.reverseList
|> lib.concatStringsSep ""
;
search = term: input: input
|> builtins.split term
|> builtins.filter lib.isList
|> builtins.length
;
searchForwardAndBack = term: input:
search term input +
search (reverseString term) input;
findXMAS = searchForwardAndBack "XMAS";
part1result = findXMAS content
+ findXMAS (diagonal content)
+ findXMAS (rotated content)
+ findXMAS (diagonal (reversed content))
;
}

80
2024/04/solution.test.nix Normal file
View file

@ -0,0 +1,80 @@
{describe, it, ...}:
let
pkgs = import <nixpkgs> {};
solution = import ./solution.nix pkgs;
content = ''
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX'';
rotated = ''
MMAMXXSSMM
MSMSMXMAAX
MAXAAASXMM
SMSMSMMAMX
XXXAAMSMMA
XMMSMXAAXX
MSAMXXSSMM
AMASAAXAMA
SSMMMMSAMS
MAMXMASAMX'';
diagonal = ''
M
MM
MSA
SAMM
XMXSX
XXSAMX
MMXMAXS
ASMASAMS
SMASAMSAM
MSAMMMMXAM
AMSXXSAMX
MMAXAMMM
XMASAMX
MMXSXA
ASAMX
SAMM
AMA
MS
X
'';
example = solution content;
in [
(describe "part 1" [
(it "gets content forward" {
actual = example.forward;
expected = content;
})
(it "gets content rotated" {
actual = example.rotated content;
expected = rotated;
})
(it "gets content diagonal" {
actual = example.diagonal content;
expected = diagonal;
})
(it "reverses string" {
actual = example.reverseString "XMAS";
expected = "SAMX";
})
(it "searches for term" {
actual = example.search "XMAS" content;
expected = 3;
})
(it "searches for term in reverse" {
actual = example.searchForwardAndBack "XMAS" content;
expected = 5;
})
(it "gets the result" {
actual = example.part1result;
expected = 18;
})
])
]