mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Part 2 and actual testing
This commit is contained in:
@@ -13,8 +13,14 @@ locals {
|
|||||||
right_sorted = sort(local.right)
|
right_sorted = sort(local.right)
|
||||||
|
|
||||||
diffs = [for i in range(length(local.left_sorted)): abs(local.left_sorted[i] - local.right_sorted[i])]
|
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" {
|
output "part1" {
|
||||||
value = sum(local.diffs)
|
value = sum(local.diffs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "part2" {
|
||||||
|
value = sum(local.matching)
|
||||||
|
}
|
||||||
|
|||||||
19
2024/bonus/day01/sample.tftest.hcl
Normal file
19
2024/bonus/day01/sample.tftest.hcl
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,3 +10,7 @@ module "day01" {
|
|||||||
output "day01_1" {
|
output "day01_1" {
|
||||||
value = module.day01.part1
|
value = module.day01.part1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "day01_2" {
|
||||||
|
value = module.day01.part2
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user