diff --git a/.gitignore b/.gitignore index 076c644..4039c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,6 @@ flamegraph.svg # Ignore saved inputs inputs/ + +# Terraform dir +.terraform diff --git a/2024/bonus/day01/main.tf b/2024/bonus/day01/main.tf new file mode 100644 index 0000000..add48b2 --- /dev/null +++ b/2024/bonus/day01/main.tf @@ -0,0 +1,20 @@ +variable "input" { + type = string +} + +locals { + cleaned_input = replace(var.input, "/ +/", " ") + lines = split("\n", trim(local.cleaned_input, "\n")) + lines_split = [for line in local.lines: split(" ", line)] + left = [for line in local.lines_split: parseint(line[0], 10)] + right = [for line in local.lines_split: parseint(line[1], 10)] + + left_sorted = sort(local.left) + right_sorted = sort(local.right) + + diffs = [for i in range(length(local.left_sorted)): abs(local.left_sorted[i] - local.right_sorted[i])] +} + +output "part1" { + value = sum(local.diffs) +} diff --git a/2024/bonus/main.tf b/2024/bonus/main.tf new file mode 100644 index 0000000..c18ee14 --- /dev/null +++ b/2024/bonus/main.tf @@ -0,0 +1,12 @@ +terraform { + +} + +module "day01" { + source = "./day01" + input = file("../inputs/01.txt") +} + +output "day01_1" { + value = module.day01.part1 +}