Implement day 1 part 1 in Terraform

This commit is contained in:
2024-12-01 16:51:45 +01:00
parent 26ee876f7a
commit 73f886359b
3 changed files with 35 additions and 0 deletions

3
.gitignore vendored
View File

@@ -67,3 +67,6 @@ flamegraph.svg
# Ignore saved inputs # Ignore saved inputs
inputs/ inputs/
# Terraform dir
.terraform

20
2024/bonus/day01/main.tf Normal file
View File

@@ -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)
}

12
2024/bonus/main.tf Normal file
View File

@@ -0,0 +1,12 @@
terraform {
}
module "day01" {
source = "./day01"
input = file("../inputs/01.txt")
}
output "day01_1" {
value = module.day01.part1
}