aboutsummaryrefslogtreecommitdiff
path: root/2024/04
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-04 07:04:54 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-04 07:04:54 +0100
commit74226de3f925ce8314f06fe7fdb05dd42c0f434b (patch)
tree9447d1d98efb03c2d9fac5f87f24ec3d2bc46005 /2024/04
parentd9fc4e3c82544aeef441ddece9992e2a4aa144f0 (diff)
gofmt that bad boy
Diffstat (limited to '2024/04')
-rw-r--r--2024/04/puzzles.go58
1 files changed, 31 insertions, 27 deletions
diff --git a/2024/04/puzzles.go b/2024/04/puzzles.go
index d59791f..42e27cd 100644
--- a/2024/04/puzzles.go
+++ b/2024/04/puzzles.go
@@ -31,33 +31,34 @@ func parseInput(sc *bufio.Scanner) [][]rune {
}
// START PART 1
+
func xmasCnt(data [][]rune) int {
cnt := 0
for i := range data {
for j := range data[i] {
coords := [...][8]int{
- {i+0, j+0, i+1, j+0, i+2, j+0, i+3, j+0}, // Vertical; top-down
- {i+0, j+0, i-1, j+0, i-2, j+0, i-3, j+0}, // Vertical; down-top
- {i+0, j+0, i+0, j+1, i+0, j+2, i+0, j+3}, // Horizontal; left-right
- {i+0, j+0, i+0, j-1, i+0, j-2, i+0, j-3}, // Horizontal; left-right
- {i+0, j+0, i-1, j+1, i-2, j+2, i-3, j+3}, // Diagonal; bl-tr
- {i+0, j+0, i+1, j+1, i+2, j+2, i+3, j+3}, // Diagonal; tl-br
- {i+0, j+0, i+1, j-1, i+2, j-2, i+3, j-3}, // Diagonal; tr-bl
- {i+0, j+0, i-1, j-1, i-2, j-2, i-3, j-3}, // Diagonal; br-tl
+ {i + 0, j + 0, i + 1, j + 0, i + 2, j + 0, i + 3, j + 0}, // Vertical; top-down
+ {i + 0, j + 0, i - 1, j + 0, i - 2, j + 0, i - 3, j + 0}, // Vertical; down-top
+ {i + 0, j + 0, i + 0, j + 1, i + 0, j + 2, i + 0, j + 3}, // Horizontal; left-right
+ {i + 0, j + 0, i + 0, j - 1, i + 0, j - 2, i + 0, j - 3}, // Horizontal; left-right
+ {i + 0, j + 0, i - 1, j + 1, i - 2, j + 2, i - 3, j + 3}, // Diagonal; bl-tr
+ {i + 0, j + 0, i + 1, j + 1, i + 2, j + 2, i + 3, j + 3}, // Diagonal; tl-br
+ {i + 0, j + 0, i + 1, j - 1, i + 2, j - 2, i + 3, j - 3}, // Diagonal; tr-bl
+ {i + 0, j + 0, i - 1, j - 1, i - 2, j - 2, i - 3, j - 3}, // Diagonal; br-tl
}
for _, x := range coords {
- if x[0] >= 0 && x[0] < len(data) &&
- x[2] >= 0 && x[2] < len(data) &&
- x[4] >= 0 && x[4] < len(data) &&
- x[6] >= 0 && x[6] < len(data) &&
- x[1] >= 0 && x[1] < len(data[0]) &&
- x[3] >= 0 && x[3] < len(data[0]) &&
- x[5] >= 0 && x[5] < len(data[0]) &&
- x[7] >= 0 && x[7] < len(data[0]) &&
- data[x[0]][x[1]] == 'X' &&
- data[x[2]][x[3]] == 'M' &&
- data[x[4]][x[5]] == 'A' &&
- data[x[6]][x[7]] == 'S' {
+ if x[0] >= 0 && x[0] < len(data) &&
+ x[2] >= 0 && x[2] < len(data) &&
+ x[4] >= 0 && x[4] < len(data) &&
+ x[6] >= 0 && x[6] < len(data) &&
+ x[1] >= 0 && x[1] < len(data[0]) &&
+ x[3] >= 0 && x[3] < len(data[0]) &&
+ x[5] >= 0 && x[5] < len(data[0]) &&
+ x[7] >= 0 && x[7] < len(data[0]) &&
+ data[x[0]][x[1]] == 'X' &&
+ data[x[2]][x[3]] == 'M' &&
+ data[x[4]][x[5]] == 'A' &&
+ data[x[6]][x[7]] == 'S' {
cnt++
}
}
@@ -65,24 +66,27 @@ func xmasCnt(data [][]rune) int {
}
return cnt
}
+
// END PART 1 START PART 2
+
func xmasCnt(data [][]rune) int {
cnt := 0
for i := range data {
for j := range data[i] {
if data[i][j] != 'A' ||
- i == 0 || i == len(data) - 1 ||
- j == 0 || j == len(data[0]) - 1 {
+ i == 0 || i == len(data)-1 ||
+ j == 0 || j == len(data[0])-1 {
continue
}
- x1 := []rune{data[i-1][j-1], data[i+1][j+1]}
- x2 := []rune{data[i+1][j-1], data[i-1][j+1]}
- if (((x1[0] == 'S' && x1[1] == 'M') || (x1[0] == 'M' && x1[1] == 'S')) &&
- ((x2[0] == 'S' && x2[1] == 'M') || (x2[0] == 'M' && x2[1] == 'S'))) {
+ x1 := [...]rune{data[i-1][j-1], data[i+1][j+1]}
+ x2 := [...]rune{data[i+1][j-1], data[i-1][j+1]}
+ if ((x1[0] == 'S' && x1[1] == 'M') || (x1[0] == 'M' && x1[1] == 'S')) &&
+ ((x2[0] == 'S' && x2[1] == 'M') || (x2[0] == 'M' && x2[1] == 'S')) {
cnt++
}
}
}
return cnt
}
-// END PART 2 \ No newline at end of file
+
+// END PART 2