2020 Day 3 Done!
This commit is contained in:
46
helpers/coordinateByteMap.go
Normal file
46
helpers/coordinateByteMap.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package aoc
|
||||
|
||||
type CoordByteMap struct {
|
||||
Field map[Coordinate]byte
|
||||
Height int
|
||||
Width int
|
||||
}
|
||||
|
||||
func StringSliceToCoordByteMap(input []string) CoordByteMap {
|
||||
ret := CoordByteMap{
|
||||
Field: make(map[Coordinate]byte),
|
||||
Height: len(input),
|
||||
Width: 0,
|
||||
}
|
||||
for y := range input {
|
||||
for x := range input[y] {
|
||||
ret.Field[Coordinate{X: x, Y: y}] = input[y][x]
|
||||
if x > ret.Width {
|
||||
ret.Width = x
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) Get(pos Coordinate) byte {
|
||||
if pos.X <= m.Width && pos.Y <= m.Height {
|
||||
return m.Field[pos]
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) Put(pos Coordinate, val byte) {
|
||||
m.Field[pos] = val
|
||||
}
|
||||
|
||||
func (m CoordByteMap) String() string {
|
||||
var ret string
|
||||
for y := 0; y <= m.Height; y++ {
|
||||
for x := 0; x <= m.Width; x++ {
|
||||
ret = ret + string(m.Field[Coordinate{X: x, Y: y}])
|
||||
}
|
||||
ret = ret + "\n"
|
||||
}
|
||||
return ret
|
||||
}
|
@@ -101,6 +101,10 @@ func StdinToStringSlice() []string {
|
||||
return input
|
||||
}
|
||||
|
||||
func StdinToCoordMap() CoordByteMap {
|
||||
return StringSliceToCoordByteMap(StdinToStringSlice())
|
||||
}
|
||||
|
||||
func Atoi(i string) int {
|
||||
var ret int
|
||||
var err error
|
||||
|
Reference in New Issue
Block a user