Skip to content

Commit

Permalink
docs(2024): add descriptive explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Dec 4, 2024
1 parent 99909bb commit a440d6d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion go/2024/puzzles/day04/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,37 @@ func part2(name string) int {
for j := range strings.Split(r, "") {
// A's are always in the middle
if string(r[j]) == "A" {
// Check line above
// Check line above and below
if i-1 >= 0 && j-1 >= 0 && i+1 < rows && j+1 < cols {
diagonalTopLeft := string(lines[i-1][j-1])
diagonalTopRight := string(lines[i-1][j+1])
diagonalBottomLeft := string(lines[i+1][j-1])
diagonalBottomRight := string(lines[i+1][j+1])

// M.M
// .A.
// S.S
if diagonalTopLeft == "M" && diagonalBottomRight == "S" && diagonalTopRight == "M" && diagonalBottomLeft == "S" {
xmas++
}

// M.S
// .A.
// M.S
if diagonalTopLeft == "M" && diagonalBottomRight == "S" && diagonalTopRight == "S" && diagonalBottomLeft == "M" {
xmas++
}

// S.S
// .A.
// M.M
if diagonalTopLeft == "S" && diagonalBottomRight == "M" && diagonalTopRight == "S" && diagonalBottomLeft == "M" {
xmas++
}

// S.M
// .A.
// S.M
if diagonalTopLeft == "S" && diagonalBottomRight == "M" && diagonalTopRight == "M" && diagonalBottomLeft == "S" {
xmas++
}
Expand Down

0 comments on commit a440d6d

Please sign in to comment.