Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions 2024/04/JalonSolov.v
Original file line number Diff line number Diff line change
@@ -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}')
}
2 changes: 1 addition & 1 deletion 2024/05/pages.input
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
75,29,13
75,97,47,61,53
61,13,29
97,13,75,29,47
97,13,75,29,47
2 changes: 2 additions & 0 deletions known/2024/04/JalonSolov.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Part 1: 18
Part 2: 9
Loading