diff --git a/2024/bonus/day03/main.tf b/2024/bonus/day03/main.tf new file mode 100644 index 0000000..35962f9 --- /dev/null +++ b/2024/bonus/day03/main.tf @@ -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)]) +} diff --git a/2024/bonus/tests.tftest.hcl b/2024/bonus/tests.tftest.hcl index 341da75..09dc5c4 100644 --- a/2024/bonus/tests.tftest.hcl +++ b/2024/bonus/tests.tftest.hcl @@ -39,5 +39,21 @@ run "day2" { 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" + } }