mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +00:00
57 lines
888 B
Go
57 lines
888 B
Go
package two
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type matrix [3][3]rune
|
|
|
|
func newMatrix(mid, nw, ne, se, sw rune) *matrix {
|
|
return &matrix{
|
|
{nw, -1, ne},
|
|
{-1, mid, -1},
|
|
{sw, -1, se},
|
|
}
|
|
}
|
|
|
|
func (m *matrix) String() string {
|
|
temp := [3][3]string{}
|
|
for i := 0; i < 3; i++ {
|
|
for j := 0; j < 3; j++ {
|
|
temp[i][j] = string(m[i][j])
|
|
}
|
|
}
|
|
return fmt.Sprintf("\n%s\n%s\n%s", temp[0], temp[1], temp[2])
|
|
}
|
|
|
|
func (m *matrix) rotate() *matrix {
|
|
temp := matrix{}
|
|
for i := 0; i < 3; i++ {
|
|
for j := 0; j < 3; j++ {
|
|
temp[3-j-1][i] = m[i][j]
|
|
}
|
|
}
|
|
return &temp
|
|
}
|
|
|
|
func (m *matrix) isValid() bool {
|
|
golden := &matrix{
|
|
{'M', -1, 'M'},
|
|
{-1, 'A', -1},
|
|
{'S', -1, 'S'},
|
|
}
|
|
|
|
for range 4 {
|
|
if reflect.DeepEqual(m, golden) {
|
|
log.Debugf("%s \n---- %s", m.String(), golden.String())
|
|
return true
|
|
}
|
|
golden = golden.rotate()
|
|
}
|
|
|
|
return false
|
|
}
|