mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 22:00:31 +01:00
Compare commits
4 Commits
b2add928ad
...
e0d458c972
| Author | SHA1 | Date | |
|---|---|---|---|
| e0d458c972 | |||
| 1c54a79d19 | |||
| c5cbd6d24f | |||
| e36f7dd4f7 |
@@ -1,19 +0,0 @@
|
|||||||
variables {
|
|
||||||
input = file("../../tests/samples/01.txt")
|
|
||||||
}
|
|
||||||
|
|
||||||
run "run" {
|
|
||||||
|
|
||||||
command = plan
|
|
||||||
|
|
||||||
assert {
|
|
||||||
condition = output.part1 == 11
|
|
||||||
error_message = "Part1 output is wrong"
|
|
||||||
}
|
|
||||||
|
|
||||||
assert {
|
|
||||||
condition = output.part2 == 31
|
|
||||||
error_message = "Part2 output is wrong"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
variables {
|
|
||||||
input = file("../../tests/samples/02.txt")
|
|
||||||
}
|
|
||||||
|
|
||||||
run "run" {
|
|
||||||
|
|
||||||
command = plan
|
|
||||||
|
|
||||||
assert {
|
|
||||||
condition = output.part1 == 2
|
|
||||||
error_message = "Part1 output is wrong"
|
|
||||||
}
|
|
||||||
|
|
||||||
assert {
|
|
||||||
condition = output.part2 == 4
|
|
||||||
error_message = "Part2 output is wrong"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
11
2024/bonus/day03/main.tf
Normal file
11
2024/bonus/day03/main.tf
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
variable "input" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
muls = regexall("mul\\((\\d+),(\\d+)\\)", var.input)
|
||||||
|
}
|
||||||
|
|
||||||
|
output "part1" {
|
||||||
|
value = sum([for mul in local.muls : parseint(mul[1], 10) * parseint(mul[0], 10)])
|
||||||
|
}
|
||||||
@@ -27,3 +27,12 @@ output "day02_1" {
|
|||||||
output "day02_2" {
|
output "day02_2" {
|
||||||
value = module.day02.part2
|
value = module.day02.part2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module "day03" {
|
||||||
|
source = "./day03"
|
||||||
|
input = file("../inputs/03.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
output "day03_1" {
|
||||||
|
value = module.day03.part1
|
||||||
|
}
|
||||||
|
|||||||
59
2024/bonus/tests.tftest.hcl
Normal file
59
2024/bonus/tests.tftest.hcl
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
run "day1" {
|
||||||
|
command = plan
|
||||||
|
module {
|
||||||
|
source = "./day01"
|
||||||
|
}
|
||||||
|
|
||||||
|
variables {
|
||||||
|
input = file("../tests/samples/01.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
condition = output.part1 == 11
|
||||||
|
error_message = "Part1 output is wrong"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
condition = output.part2 == 31
|
||||||
|
error_message = "Part2 output is wrong"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run "day2" {
|
||||||
|
command = plan
|
||||||
|
|
||||||
|
module {
|
||||||
|
source = "./day02"
|
||||||
|
}
|
||||||
|
|
||||||
|
variables {
|
||||||
|
input = file("../tests/samples/02.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
condition = output.part1 == 2
|
||||||
|
error_message = "Part1 output is wrong"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
condition = output.part2 == 4
|
||||||
|
error_message = "Part2 output is wrong"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run "day3_1" {
|
||||||
|
command = plan
|
||||||
|
|
||||||
|
module {
|
||||||
|
source = "./day03"
|
||||||
|
}
|
||||||
|
|
||||||
|
variables {
|
||||||
|
input = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
condition = output.part1 == 161
|
||||||
|
error_message = "Part1 output is wrong"
|
||||||
|
}
|
||||||
|
}
|
||||||
25
2024/src/aoc/days/day3.py
Normal file
25
2024/src/aoc/days/day3.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
from . import SeparateRunner
|
||||||
|
|
||||||
|
|
||||||
|
class DayRunner(SeparateRunner):
|
||||||
|
@classmethod
|
||||||
|
def part1(cls, data: str) -> int:
|
||||||
|
return sum(int(a) * int(b) for a, b in re.findall(r"mul\((\d+),(\d+)\)", data))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def part2(cls, data: str) -> int:
|
||||||
|
do = True
|
||||||
|
total = 0
|
||||||
|
for op, a, b in re.findall(r"(don't\(\)|do\(\)|mul\((\d+),(\d+)\))", data):
|
||||||
|
match op:
|
||||||
|
case "do()":
|
||||||
|
do = True
|
||||||
|
case "don't()":
|
||||||
|
do = False
|
||||||
|
case _:
|
||||||
|
if do:
|
||||||
|
total += int(a) * int(b)
|
||||||
|
|
||||||
|
return total
|
||||||
12
2024/tests/test_day3.py
Normal file
12
2024/tests/test_day3.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from aoc.days.day3 import DayRunner
|
||||||
|
|
||||||
|
SAMPLE_1 = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
|
||||||
|
SAMPLE_2 = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))"
|
||||||
|
|
||||||
|
|
||||||
|
def test_sample_part1() -> None:
|
||||||
|
assert DayRunner.part1(SAMPLE_1) == 161
|
||||||
|
|
||||||
|
|
||||||
|
def test_sample_part2() -> None:
|
||||||
|
assert DayRunner.part2(SAMPLE_2) == 48
|
||||||
Reference in New Issue
Block a user