Skip to content

Commit

Permalink
solve day4 part2
Browse files Browse the repository at this point in the history
  • Loading branch information
SylivanKenobi committed Dec 4, 2024
1 parent 45fe636 commit 136b340
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions 2024/day4/day4.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,38 @@ func Part1(file string) int {
}

func Part2(file string) int {
// lines := utils.ReadFileByLine(file)
result := 0
lines := utils.ReadFileByLine(file)

result := 0
for i, line := range lines {
for j := range line {
letters := strings.Split(line, "")
if letters[j] == "M" || letters[j] == "S" {
down := false
up := false
// diagonal down right
if len(lines)-2 > i && len(letters)-2 > j {
ddr := strings.Join([]string{string(lines[i][j]), string(lines[i+1][j+1]), string(lines[i+2][j+2])}, "")
down = Mas(ddr)
}
// diagonal down left
if len(lines)-2 > i && len(letters)-2 > j && down {
ddl := strings.Join([]string{string(lines[i][j+2]), string(lines[i+1][j+1]), string(lines[i+2][j])}, "")
up = Mas(ddl)
}
if up && down {
result += 1
}
}
}
}
return result
}

func Holliday(holliday string) bool {
return (holliday == "XMAS" || holliday == "SAMX")
}

func Mas(holliday string) bool {
return (holliday == "MAS" || holliday == "SAM")
}

0 comments on commit 136b340

Please sign in to comment.