diff --git a/progress.png b/progress.png index 4f5dc07..4cdeef7 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 3caf049..fceb3db 100644 --- a/progress.yaml +++ b/progress.yaml @@ -9,4 +9,6 @@ 5: stars: 2 6: + stars: 1 +7: stars: 1 \ No newline at end of file diff --git a/res/examples/day7.txt b/res/examples/day7.txt new file mode 100644 index 0000000..87b8b25 --- /dev/null +++ b/res/examples/day7.txt @@ -0,0 +1,9 @@ +190: 10 19 +3267: 81 40 27 +83: 17 5 +156: 15 6 +7290: 6 8 6 15 +161011: 16 10 13 +192: 17 8 14 +21037: 9 7 18 13 +292: 11 6 16 20 \ No newline at end of file diff --git a/src/day7/puzzle1.typ b/src/day7/puzzle1.typ new file mode 100644 index 0000000..6e7898c --- /dev/null +++ b/src/day7/puzzle1.typ @@ -0,0 +1,42 @@ +#import "/src/utils.typ": * + +#let solveable(values, target) = { + if values.len() == 1 { + return values.last() == target + } + + let values = values + let v = values.pop() + if calc.rem(target, v) == 0 { + if solveable(values, target / v) { + return true + } + } + if v > target { + return false + } + + return solveable(values, target - v) +} + +#let solve(input) = { + let equations = input.split("\n") + + let total = 0 + for equation in equations { + let (target, values) = equation.split(": ") + target = int(target) + values = values.split(" ").map(int) + + if solveable(values, target) { + total += target + } + } + return total +} + +#show-puzzle( + 7, 1, + solve, + example: 3749 +) \ No newline at end of file diff --git a/src/day7/puzzle2.typ b/src/day7/puzzle2.typ new file mode 100644 index 0000000..e69de29 diff --git a/src/main.pdf b/src/main.pdf index 901d7ef..6484c5e 100644 Binary files a/src/main.pdf and b/src/main.pdf differ