From 8c822222cc98136e516a70a5b04a50572a9cca04 Mon Sep 17 00:00:00 2001 From: JalonSolov Date: Mon, 23 Dec 2024 09:50:33 -0500 Subject: [PATCH 1/2] 2024 Day 4 --- 2024/04/JalonSolov.v | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2024/04/words.input | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 2024/04/JalonSolov.v diff --git a/2024/04/JalonSolov.v b/2024/04/JalonSolov.v new file mode 100644 index 0000000..f8a782b --- /dev/null +++ b/2024/04/JalonSolov.v @@ -0,0 +1,56 @@ +import os + +// vfmt off +const deltas = [[-1, 0]!, [1, 0]!, [0, -1]!, [0, 1]!, [-1, -1]!, [-1, 1]!, [1, -1]!, [1, 1]!]! +// vfmt on +const lines = os.read_lines('words.input')! + +fn word_found(x int, y int, dir int) bool { + mut adjusted_x := x + mut adjusted_y := y + + for c in 'MAS' { + adjusted_x += deltas[dir][0] + adjusted_y += deltas[dir][1] + + if adjusted_x < 0 || adjusted_y < 0 || adjusted_x >= lines[0].len || adjusted_y >= lines.len + || lines[adjusted_y][adjusted_x] != c { + return false + } + } + + return true +} + +fn main() { + mut xmas := 0 + mut x_mas := 0 + + for y, line in lines { + for x, c in line { + match c { + `X` { + for dir in 0 .. deltas.len { + if word_found(x, y, dir) { + xmas++ + } + } + } + `A` { + if x > 0 && x < line.len - 1 && y > 0 && y < lines.len - 1 { + if ((lines[y - 1][x - 1] == `M` && lines[y + 1][x + 1] == `S`) + || (lines[y - 1][x - 1] == `S` && lines[y + 1][x + 1] == `M`)) + && ((lines[y - 1][x + 1] == `M` && lines[y + 1][x - 1] == `S`) + || (lines[y - 1][x + 1] == `S` && lines[y + 1][x - 1] == `M`)) { + x_mas++ + } + } + } + else {} + } + } + } + + println('Part 1: ${xmas}') + println('Part 2: ${x_mas}') +} diff --git a/2024/04/words.input b/2024/04/words.input index 1f4eda2..c41c5ea 100644 --- a/2024/04/words.input +++ b/2024/04/words.input @@ -7,4 +7,4 @@ XXAMMXXAMA SMSMSASXSS SAXAMASAAA MAMMMXMMMM -MXMXAXMASX +MXMXAXMASX \ No newline at end of file From c7329f3ee9fd3e7b617a664815ad9b26709ed44e Mon Sep 17 00:00:00 2001 From: JalonSolov Date: Mon, 23 Dec 2024 09:51:48 -0500 Subject: [PATCH 2/2] add .out --- known/2024/04/JalonSolov.out | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 known/2024/04/JalonSolov.out diff --git a/known/2024/04/JalonSolov.out b/known/2024/04/JalonSolov.out new file mode 100644 index 0000000..1567462 --- /dev/null +++ b/known/2024/04/JalonSolov.out @@ -0,0 +1,2 @@ +Part 1: 18 +Part 2: 9