diff --git a/progress.png b/progress.png index c33e7c4..78d063d 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 8ce05f4..0cb296d 100644 --- a/progress.yaml +++ b/progress.yaml @@ -5,4 +5,6 @@ 3: stars: 2 4: - stars: 2 \ No newline at end of file + stars: 2 +5: + stars: 1 \ No newline at end of file diff --git a/res/examples/day5.txt b/res/examples/day5.txt new file mode 100644 index 0000000..d4d4441 --- /dev/null +++ b/res/examples/day5.txt @@ -0,0 +1,28 @@ +47|53 +97|13 +97|61 +97|47 +75|29 +61|13 +75|53 +29|13 +97|29 +53|29 +61|53 +97|53 +61|29 +47|13 +75|47 +97|75 +47|61 +75|61 +47|29 +75|13 +53|13 + +75,47,61,53,29 +97,61,53,29,13 +75,29,13 +75,97,47,61,53 +61,13,29 +97,13,75,29,47 \ No newline at end of file diff --git a/src/day5/puzzle1.typ b/src/day5/puzzle1.typ new file mode 100644 index 0000000..5a5f9d9 --- /dev/null +++ b/src/day5/puzzle1.typ @@ -0,0 +1,52 @@ +#import "/src/utils.typ": * + +#let make-rules-dict(rules) = { + let dict = (:) + + for rule in rules { + let (a, b) = rule + + if a not in dict { + dict.insert(a, ()) + } + dict.at(a).push(b) + } + + return dict +} + +#let is-update-valid(dict, update) = { + for i in range(update.len() - 1) { + let a = str(update.at(i)) + for j in range(i + 1, update.len()) { + let b = str(update.at(j)) + if a in dict.at(b, default: ()) { + return false + } + } + } + return true +} + +#let solve(input) = { + let (rules, updates) = input.split("\n\n") + rules = rules.split("\n").map(l => l.split("|")) + updates = updates.split("\n").map(l => l.split(",").map(int)) + + let total = 0 + let rules-dict = make-rules-dict(rules) + + for update in updates { + if is-update-valid(rules-dict, update) { + total += update.at(calc.div-euclid(update.len(), 2)) + } + } + + return total +} + +#show-puzzle( + 5, 1, + solve, + example: 143 +) \ No newline at end of file diff --git a/src/day5/puzzle2.typ b/src/day5/puzzle2.typ new file mode 100644 index 0000000..e69de29 diff --git a/src/main.pdf b/src/main.pdf index a519912..f123f54 100644 Binary files a/src/main.pdf and b/src/main.pdf differ diff --git a/src/utils.pdf b/src/utils.pdf new file mode 100644 index 0000000..27e6d81 Binary files /dev/null and b/src/utils.pdf differ