|
@ -40,7 +40,51 @@ func (d Day4) Part1(r io.Reader) string { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (d Day4) Part2(r io.Reader) string { |
|
|
func (d Day4) Part2(r io.Reader) string { |
|
|
return "" |
|
|
wordsearch := make([][]rune, 0) |
|
|
|
|
|
s := bufio.NewScanner(r) |
|
|
|
|
|
var sum int |
|
|
|
|
|
|
|
|
|
|
|
for s.Scan() { |
|
|
|
|
|
line := []rune(s.Text()) |
|
|
|
|
|
wordsearch = append(wordsearch, line) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
s1 := make([]rune, 3) |
|
|
|
|
|
s2 := make([]rune, 3) |
|
|
|
|
|
for startx := range wordsearch { |
|
|
|
|
|
for starty := range wordsearch[startx] { |
|
|
|
|
|
|
|
|
|
|
|
toptobottom := [][]int{ |
|
|
|
|
|
{-1, -1}, |
|
|
|
|
|
{0, 0}, |
|
|
|
|
|
{1, 1}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i, transpose := range toptobottom { |
|
|
|
|
|
x, y := startx+transpose[0], starty+transpose[1] |
|
|
|
|
|
s1[i] = runeAt(wordsearch, x, y) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bottomtotop := [][]int{ |
|
|
|
|
|
{-1, 1}, |
|
|
|
|
|
{0, 0}, |
|
|
|
|
|
{1, -1}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i, transpose := range bottomtotop { |
|
|
|
|
|
x, y := startx+transpose[0], starty+transpose[1] |
|
|
|
|
|
s2[i] = runeAt(wordsearch, x, y) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if str1, str2 := string(s1), string(s2); (str1 == "SAM" || str1 == "MAS") && (str2 == "SAM" || str2 == "MAS") { |
|
|
|
|
|
sum++ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return printi(sum) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func runeAt(r [][]rune, x, y int) rune { |
|
|
func runeAt(r [][]rune, x, y int) rune { |
|
|