Optimize day 4 enough to run

This commit is contained in:
2024-12-05 22:52:57 +01:00
parent f7af07a631
commit e9a57701c9
3 changed files with 13 additions and 6 deletions

View File

@@ -19,9 +19,9 @@ variable "dy" {
} }
locals { locals {
match = [for i in range(4) : var.x + i * var.dx >= 0 && try(substr(var.grid[var.y + i * var.dy], var.x + i * var.dx, 1), "F") == substr("XMAS", i, 1)] word = join("", [for i in range(4) : var.x + i * var.dx >= 0 ? try(substr(var.grid[var.y + i * var.dy], var.x + i * var.dx, 1), "F") : "F"])
} }
output "found" { output "found" {
value = alltrue(local.match) ? 1 : 0 value = contains(["SAMX", "XMAS"], local.word) ? 1 : 0
} }

View File

@@ -19,9 +19,6 @@ locals {
y = floor(var.index / var.width) y = floor(var.index / var.width)
directions = { directions = {
"UL" = [-1, -1]
"U" = [0, -1]
"UR" = [1, -1]
"DL" = [-1, 1] "DL" = [-1, 1]
"D" = [0, 1] "D" = [0, 1]
"DR" = [1, 1] "DR" = [1, 1]

View File

@@ -41,8 +41,18 @@ output "day03_2" {
value = module.day03.part2 value = module.day03.part2
} }
# Don't run this, it runs out of memory # Don't run this, it runs forever (6 minutes) and requires a lot of memory (~5.5GB) to execute to
# boot. Trust me, it works.
# module "day04" { # module "day04" {
# source = "./day04" # source = "./day04"
# input = file("../inputs/04.txt") # input = file("../inputs/04.txt")
# } # }
# output "day04_1" {
# value = module.day04.part1
# }
# output "day04_2" {
# value = module.day04.part2
# }