mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
36 lines
608 B
Go
36 lines
608 B
Go
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type img struct {
|
||
|
raw []string
|
||
|
}
|
||
|
|
||
|
func newImg(sz int) img {
|
||
|
return img{raw: make([]string, sz)}
|
||
|
}
|
||
|
|
||
|
// transposed rotates an image rightwards ninety degrees
|
||
|
func (i img) transposed() []string {
|
||
|
transposed := []string{}
|
||
|
|
||
|
for x := 0; x < len(i.raw[0]); x++ {
|
||
|
buf := ""
|
||
|
for j := len(i.raw) - 1; j >= 0; j-- {
|
||
|
buf += string(i.raw[j][x])
|
||
|
}
|
||
|
transposed = append(transposed, buf)
|
||
|
}
|
||
|
|
||
|
return transposed
|
||
|
}
|
||
|
|
||
|
// String implements the Stringer interface
|
||
|
func (i img) String() string {
|
||
|
out := ""
|
||
|
for _, line := range i.raw {
|
||
|
out += fmt.Sprintf("%s\n", line)
|
||
|
}
|
||
|
return out
|
||
|
}
|