This commit is contained in:
2022-12-15 14:56:28 +01:00
parent 108980344b
commit cc58326f8c
20 changed files with 145 additions and 145 deletions

View File

@@ -78,8 +78,8 @@ func (tileMap *Map) DropSand() bool {
func (tileMap *Map) AddFloor() {
currFloor := 0
for i := 0; i < len(*tileMap); i++ {
for j := 0; j < len((*tileMap)[i]); j++ {
for i := 0; i < len(*tileMap); i++ {
for j := 0; j < len((*tileMap)[i]); j++ {
if (*tileMap)[i][j] == Rock && i > currFloor {
currFloor = i
}
@@ -97,19 +97,19 @@ func (tileMap *Map) IsSourceBlocked() bool {
}
func (tileMap *Map) Print(xMin, xMax, yMin, yMax int) {
for i := yMin; i <= yMax; i++ {
for j := xMin; j <= xMax; j++ {
switch (*tileMap)[i][j] {
case Air:
fmt.Print(".")
case Rock:
fmt.Print("#")
case Sand:
fmt.Print("o")
}
}
fmt.Println()
}
for i := yMin; i <= yMax; i++ {
for j := xMin; j <= xMax; j++ {
switch (*tileMap)[i][j] {
case Air:
fmt.Print(".")
case Rock:
fmt.Print("#")
case Sand:
fmt.Print("o")
}
}
fmt.Println()
}
}
type RockStructure struct {

View File

@@ -9,16 +9,16 @@ import (
func main() {
rockStructures := common.Parse(*bufio.NewScanner(os.Stdin))
tileMap := common.NewMap()
tileMap := common.NewMap()
for _, rockStructure := range rockStructures {
tileMap.AddRockStructure(rockStructure)
}
for _, rockStructure := range rockStructures {
tileMap.AddRockStructure(rockStructure)
}
units := 0
for tileMap.DropSand() {
units++
}
units := 0
for tileMap.DropSand() {
units++
}
fmt.Println(units)
fmt.Println(units)
}

View File

@@ -9,18 +9,18 @@ import (
func main() {
rockStructures := common.Parse(*bufio.NewScanner(os.Stdin))
tileMap := common.NewMap()
tileMap := common.NewMap()
for _, rockStructure := range rockStructures {
tileMap.AddRockStructure(rockStructure)
}
tileMap.AddFloor()
for _, rockStructure := range rockStructures {
tileMap.AddRockStructure(rockStructure)
}
tileMap.AddFloor()
units := 0
for !tileMap.IsSourceBlocked() {
tileMap.DropSand()
units++
}
units := 0
for !tileMap.IsSourceBlocked() {
tileMap.DropSand()
units++
}
fmt.Println(units)
fmt.Println(units)
}