diff --git a/2024/04/krotki/part1.v b/2024/04/krotki/part1.v new file mode 100644 index 0000000..2b14b48 --- /dev/null +++ b/2024/04/krotki/part1.v @@ -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) +} diff --git a/2024/04/krotki/part2.v b/2024/04/krotki/part2.v new file mode 100644 index 0000000..2fcda24 --- /dev/null +++ b/2024/04/krotki/part2.v @@ -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) +} diff --git a/known/2024/04/krotki/part1.out b/known/2024/04/krotki/part1.out new file mode 100644 index 0000000..3c03207 --- /dev/null +++ b/known/2024/04/krotki/part1.out @@ -0,0 +1 @@ +18 diff --git a/known/2024/04/krotki/part2.out b/known/2024/04/krotki/part2.out new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/known/2024/04/krotki/part2.out @@ -0,0 +1 @@ +9