day 7 puzzle 1
This commit is contained in:
parent
6071366ed6
commit
acdb212ddd
BIN
progress.png
BIN
progress.png
Binary file not shown.
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
@ -9,4 +9,6 @@
|
||||
5:
|
||||
stars: 2
|
||||
6:
|
||||
stars: 1
|
||||
7:
|
||||
stars: 1
|
9
res/examples/day7.txt
Normal file
9
res/examples/day7.txt
Normal file
@ -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
|
42
src/day7/puzzle1.typ
Normal file
42
src/day7/puzzle1.typ
Normal file
@ -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
|
||||
)
|
0
src/day7/puzzle2.typ
Normal file
0
src/day7/puzzle2.typ
Normal file
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
Reference in New Issue
Block a user