exercism/go/matrix/matrix.go
2016-09-03 21:35:32 -05:00

35 lines
522 B
Go

package matrix
import "strings"
type Matrix struct {
vals [][]int
}
func New(in string) (*Matrix, error) {
ret := Matrix{}
rows := strings.Split(in, "\n")
return &ret, nil
}
func (m *Matrix) Rows() [][]int {
return m.vals
}
func (m *Matrix) Cols() [][]int {
ret := [][]int{}
if len(m.vals) > 0 {
// for i := 0; i < len(m.vals[0]); i++ {
// }
}
return ret
}
func (m *Matrix) Set(r, c int, val int) bool {
if len(m.vals) < r || len(m.vals[r]) < c {
return false
}
m.vals[r][c] = val
return true
}