mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 12:50:32 +01:00
Implement day 1 part 1 in Terraform
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -67,3 +67,6 @@ flamegraph.svg
|
||||
|
||||
# Ignore saved inputs
|
||||
inputs/
|
||||
|
||||
# Terraform dir
|
||||
.terraform
|
||||
|
||||
20
2024/bonus/day01/main.tf
Normal file
20
2024/bonus/day01/main.tf
Normal 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
12
2024/bonus/main.tf
Normal file
@@ -0,0 +1,12 @@
|
||||
terraform {
|
||||
|
||||
}
|
||||
|
||||
module "day01" {
|
||||
source = "./day01"
|
||||
input = file("../inputs/01.txt")
|
||||
}
|
||||
|
||||
output "day01_1" {
|
||||
value = module.day01.part1
|
||||
}
|
||||
Reference in New Issue
Block a user