diff --git a/2024/bonus/day01/main.tf b/2024/bonus/day01/main.tf index add48b2..41fd6b1 100644 --- a/2024/bonus/day01/main.tf +++ b/2024/bonus/day01/main.tf @@ -13,8 +13,14 @@ locals { right_sorted = sort(local.right) diffs = [for i in range(length(local.left_sorted)): abs(local.left_sorted[i] - local.right_sorted[i])] + + matching = [for left in local.left: sum([for right in local.right: left == right ? left : 0])] } output "part1" { value = sum(local.diffs) } + +output "part2" { + value = sum(local.matching) +} diff --git a/2024/bonus/day01/sample.tftest.hcl b/2024/bonus/day01/sample.tftest.hcl new file mode 100644 index 0000000..51fc196 --- /dev/null +++ b/2024/bonus/day01/sample.tftest.hcl @@ -0,0 +1,19 @@ +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" + } + +} diff --git a/2024/bonus/main.tf b/2024/bonus/main.tf index c18ee14..d157bb3 100644 --- a/2024/bonus/main.tf +++ b/2024/bonus/main.tf @@ -10,3 +10,7 @@ module "day01" { output "day01_1" { value = module.day01.part1 } + +output "day01_2" { + value = module.day01.part2 +}