New Shared Library
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"AdventOfCode2021/shared"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -11,7 +12,7 @@ func main() {
|
||||
content := returnContent("../input")
|
||||
//content := returnContent("../testInput")
|
||||
|
||||
octopuses := map[Coordinate]int{}
|
||||
octopuses := map[shared.Coordinate]int{}
|
||||
|
||||
answer := 0
|
||||
|
||||
@ -22,12 +23,12 @@ func main() {
|
||||
for y, row := range *content {
|
||||
width = len(row)
|
||||
for x, val := range row {
|
||||
octopuses[Coordinate{X: x, Y: y}] = val
|
||||
octopuses[shared.Coordinate{X: x, Y: y}] = val
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
flashers := map[Coordinate]bool{}
|
||||
flashers := map[shared.Coordinate]bool{}
|
||||
|
||||
for coord := range octopuses {
|
||||
octopuses[coord]++
|
||||
@ -63,49 +64,6 @@ func main() {
|
||||
fmt.Println(answer)
|
||||
}
|
||||
|
||||
//Coordinate Class
|
||||
type Coordinate struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
func (c *Coordinate) Neighbours(gridWidth int, gridHeight int, diagonal bool) (out []Coordinate) {
|
||||
spaceLeft := c.X > 0
|
||||
spaceRight := c.X < gridWidth-1
|
||||
spaceUp := c.Y > 0
|
||||
spaceDown := c.Y < gridHeight-1
|
||||
|
||||
if spaceLeft {
|
||||
out = append(out, Coordinate{c.X - 1, c.Y})
|
||||
}
|
||||
if spaceRight {
|
||||
out = append(out, Coordinate{c.X + 1, c.Y})
|
||||
}
|
||||
if spaceUp {
|
||||
out = append(out, Coordinate{c.X, c.Y - 1})
|
||||
}
|
||||
if spaceDown {
|
||||
out = append(out, Coordinate{c.X, c.Y + 1})
|
||||
}
|
||||
|
||||
if diagonal {
|
||||
if spaceUp && spaceLeft {
|
||||
out = append(out, Coordinate{c.X - 1, c.Y - 1})
|
||||
}
|
||||
if spaceUp && spaceRight {
|
||||
out = append(out, Coordinate{c.X + 1, c.Y - 1})
|
||||
}
|
||||
if spaceDown && spaceLeft {
|
||||
out = append(out, Coordinate{c.X - 1, c.Y + 1})
|
||||
}
|
||||
if spaceDown && spaceRight {
|
||||
out = append(out, Coordinate{c.X + 1, c.Y + 1})
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func returnContent(path string) *[][]int {
|
||||
//read file and return it as an array of integers
|
||||
|
||||
|
Reference in New Issue
Block a user