Solutions for day 10.
This commit is contained in:
parent
e47b6c4a45
commit
28998c5d14
4 changed files with 67 additions and 18 deletions
|
@ -14,6 +14,16 @@ func (p *Point) Move() {
|
|||
p.Y += p.Yv
|
||||
}
|
||||
|
||||
func (p *Point) Reverse() {
|
||||
p.X -= p.Xv
|
||||
p.Y -= p.Yv
|
||||
}
|
||||
|
||||
func CalculateRange(points []*Point) int {
|
||||
xMin, xMax, yMin, yMax := findBounds(points)
|
||||
return xMax - xMin + yMax - yMin
|
||||
}
|
||||
|
||||
func DrawPoints(points []*Point) {
|
||||
pointArr := makeBuffer(points)
|
||||
|
||||
|
@ -33,7 +43,11 @@ func DrawPoints(points []*Point) {
|
|||
// findBounds returns xMin, xMax, yMin, and yMax from the provided points.
|
||||
func findBounds(points []*Point) (int, int, int, int) {
|
||||
// find min and max values
|
||||
var xMin, xMax, yMin, yMax int
|
||||
xMin := points[0].X
|
||||
xMax := points[0].X
|
||||
yMin := points[0].Y
|
||||
yMax := points[0].Y
|
||||
|
||||
for _, point := range points {
|
||||
if point.X < xMin {
|
||||
xMin = point.X
|
||||
|
@ -54,6 +68,7 @@ func findBounds(points []*Point) (int, int, int, int) {
|
|||
|
||||
func makeBuffer(points []*Point) [][]byte {
|
||||
xMin, xMax, yMin, yMax := findBounds(points)
|
||||
|
||||
// get the total magnitude; we'll do adjustments later
|
||||
xRange := xMax - xMin
|
||||
yRange := yMax - yMin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue