aboutsummaryrefslogtreecommitdiff
path: root/2024/04/puzzles.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-04 07:02:38 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-04 07:02:38 +0100
commitd9fc4e3c82544aeef441ddece9992e2a4aa144f0 (patch)
treea3d3f271146913de00426cf00e6749e817bea527 /2024/04/puzzles.go
parent9b3cd9200ebeba744e532c43cd7dcbba2c0f400a (diff)
Formatting
Diffstat (limited to '2024/04/puzzles.go')
-rw-r--r--2024/04/puzzles.go40
1 files changed, 20 insertions, 20 deletions
diff --git a/2024/04/puzzles.go b/2024/04/puzzles.go
index eca88a2..d59791f 100644
--- a/2024/04/puzzles.go
+++ b/2024/04/puzzles.go
@@ -36,28 +36,28 @@ func xmasCnt(data [][]rune) int {
for i := range data {
for j := range data[i] {
coords := [...][8]int{
- {i, j, i+1, j, i+2, j, i+3, j}, // Vertical; top-down
- {i, j, i-1, j, i-2, j, i-3, j}, // Vertical; down-top
- {i, j, i, j+1, i, j+2, i, j+3}, // Horizontal; left-right
- {i, j, i, j-1, i, j-2, i, j-3}, // Horizontal; left-right
- {i, j, i-1, j+1, i-2, j+2, i-3, j+3}, // Diagonal; bl-tr
- {i, j, i+1, j+1, i+2, j+2, i+3, j+3}, // Diagonal; tl-br
- {i, j, i+1, j-1, i+2, j-2, i+3, j-3}, // Diagonal; tr-bl
- {i, j, 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++
}
}