Skip to content

Commit

Permalink
Krotki, day4 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krotki authored Dec 4, 2024
1 parent 0408cab commit 75d0f1b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 2024/04/krotki/part1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module main

import os

fn main() {
input := os.get_lines()

dirs := [
[0, 1],
[0, -1],
[1, 0],
[-1, 0],
[1, 1],
[1, -1],
[-1, 1],
[-1, -1],
]

xmax := input[0].len
ymax := input.len

mut count := 0
for y, line in input {
for x, c in line.bytes() {
if c == `X` {
dirl: for dir in dirs {
for dist, letter in 'MAS' {
d := dist + 1
dx := x + dir[0] * d
dy := y + dir[1] * d
if dx < 0 || dx >= xmax || dy < 0 || dy >= ymax || input[dy][dx] != letter {
continue dirl
}
if d == 3 {
count++
}
}
}
}
}
}

println(count)
}
32 changes: 32 additions & 0 deletions 2024/04/krotki/part2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module main

import os

fn main() {
input := os.get_raw_lines()

xmax := input[0].len
ymax := input.len

mut count := 0
for y, line in input {
for x, c in line.bytes() {
if x <= 0 || x >= xmax - 1 || y <= 0 || y >= ymax - 1 {
continue
}
if c == `A` {
// /
diag1 := (input[y - 1][x - 1] == `M` && input[y + 1][x + 1] == `S`)
|| (input[y - 1][x - 1] == `S` && input[y + 1][x + 1] == `M`)
// \
diag2 := (input[y + 1][x - 1] == `M` && input[y - 1][x + 1] == `S`)
|| (input[y + 1][x - 1] == `S` && input[y - 1][x + 1] == `M`)
if diag1 && diag2 {
count++
}
}
}
}

println(count)
}
1 change: 1 addition & 0 deletions known/2024/04/krotki/part1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions known/2024/04/krotki/part2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9

0 comments on commit 75d0f1b

Please sign in to comment.