diff --git a/progress.png b/progress.png index 4cdeef7..5995e44 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index fceb3db..b5c56e4 100644 --- a/progress.yaml +++ b/progress.yaml @@ -11,4 +11,4 @@ 6: stars: 1 7: - stars: 1 \ No newline at end of file + stars: 2 \ No newline at end of file diff --git a/src/day7/puzzle2.typ b/src/day7/puzzle2.typ index e69de29..0d07f82 100644 --- a/src/day7/puzzle2.typ +++ b/src/day7/puzzle2.typ @@ -0,0 +1,60 @@ +#import "/src/utils.typ": * + +#let concat(a, b) = { + return int(str(a) + str(b)) +} + +#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 + } + } + let str-target = str(target) + let str-v = str(v) + if str-target == str-v { + return false + } + if str-target.ends-with(str-v) { + let target2 = str-target.slice( + 0, + str-target.len() - str-v.len() + ) + if solveable(values, int(target2)) { + 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, 2, + solve, + example: 11387 +) \ No newline at end of file diff --git a/src/main.pdf b/src/main.pdf index 6484c5e..35c1dad 100644 Binary files a/src/main.pdf and b/src/main.pdf differ