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

@@ -1,9 +1,9 @@
package common
import (
"bufio"
"strconv"
"strings"
"bufio"
"strconv"
"strings"
)
type Assignment struct {

View File

@@ -1,9 +1,9 @@
package common
import (
"bufio"
"strconv"
"strings"
"bufio"
"strconv"
"strings"
)
type Stack []byte

View File

@@ -1,7 +1,7 @@
package common
import (
"bufio"
"bufio"
)
type Signal string

View File

@@ -1,9 +1,9 @@
package common
import (
"bufio"
"strconv"
"strings"
"bufio"
"strconv"
"strings"
)
type FileBase interface {

View File

@@ -1,7 +1,7 @@
package common
import (
"bufio"
"bufio"
)
type Tree int

View File

@@ -1,10 +1,10 @@
package main
import (
"aoc2022/day10/common"
"bufio"
"fmt"
"os"
"aoc2022/day10/common"
"bufio"
"fmt"
"os"
)
func main() {

View File

@@ -1,9 +1,9 @@
package common
import (
"bufio"
"strconv"
"strings"
"bufio"
"strconv"
"strings"
)

View File

@@ -1,11 +1,11 @@
package main
import (
"aoc2022/day11/common"
"bufio"
"fmt"
"os"
"sort"
"aoc2022/day11/common"
"bufio"
"fmt"
"os"
"sort"
)
func main() {

View File

@@ -1,11 +1,11 @@
package main
import (
"aoc2022/day11/common"
"bufio"
"fmt"
"os"
"sort"
"aoc2022/day11/common"
"bufio"
"fmt"
"os"
"sort"
)
func main() {

View File

@@ -1,8 +1,8 @@
package common
import (
"bufio"
"math"
"bufio"
"math"
)

View File

@@ -1,10 +1,10 @@
package main
import (
"aoc2022/day12/common"
"bufio"
"fmt"
"os"
"aoc2022/day12/common"
"bufio"
"fmt"
"os"
)
func main() {

View File

@@ -1,10 +1,10 @@
package main
import (
"aoc2022/day12/common"
"bufio"
"fmt"
"os"
"aoc2022/day12/common"
"bufio"
"fmt"
"os"
)
func main() {

View File

@@ -1,21 +1,21 @@
package main
import (
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
)
func main() {
pairs := common.ParsePairs(*bufio.NewScanner(os.Stdin))
sum := 0
sum := 0
for i, pair := range pairs {
if pair.CheckOrder() {
sum += (i + 1)
}
}
for i, pair := range pairs {
if pair.CheckOrder() {
sum += (i + 1)
}
}
fmt.Println(sum)
}

View File

@@ -1,26 +1,26 @@
package main
import (
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
"sort"
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
"sort"
)
func main() {
packets := common.ParsePackets(*bufio.NewScanner(os.Stdin), []string{"[[2]]", "[[6]]"})
sort.Slice(packets, func(i int, j int) bool {
return packets[i].Compare(packets[j]) < 0
})
sort.Slice(packets, func(i int, j int) bool {
return packets[i].Compare(packets[j]) < 0
})
result := 1
for i := 0; i < len(packets); i++ {
if packets[i].IsSeparator() {
result *= (i+1)
}
}
result := 1
for i := 0; i < len(packets); i++ {
if packets[i].IsSeparator() {
result *= (i+1)
}
}
fmt.Println(result)
}

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)
}

View File

@@ -1,10 +1,10 @@
package common
import (
"bufio"
"fmt"
"strconv"
"strings"
"bufio"
"fmt"
"strconv"
"strings"
)
@@ -185,21 +185,21 @@ func (tileMap *Map) GetCoverageYInXInterval(xMin, xMax, y int) int {
}
func (tileMap *Map) Print(xMin, xMax, yMin, yMax int) {
for i := yMin; i <= yMax; i++ {
for j := xMin; j <= xMax; j++ {
switch tileMap.GetTile(j, i) {
case Beacon:
fmt.Print("B")
case Sensor:
fmt.Print("S")
case Covered:
fmt.Print("#")
for i := yMin; i <= yMax; i++ {
for j := xMin; j <= xMax; j++ {
switch tileMap.GetTile(j, i) {
case Beacon:
fmt.Print("B")
case Sensor:
fmt.Print("S")
case Covered:
fmt.Print("#")
case Free:
fmt.Print(".")
}
}
fmt.Println()
}
}
}
fmt.Println()
}
}

View File

@@ -1,19 +1,19 @@
package main
import (
"aoc2022/day15/common"
"bufio"
"fmt"
"os"
"aoc2022/day15/common"
"bufio"
"fmt"
"os"
)
func main() {
sensors := common.Parse(*bufio.NewScanner(os.Stdin))
tileMap := common.NewMap()
tileMap := common.NewMap()
for _, sensor := range sensors {
tileMap.SetSensor(sensor)
}
for _, sensor := range sensors {
tileMap.SetSensor(sensor)
}
fmt.Println(tileMap.GetCoverageY(2000000))
fmt.Println(tileMap.GetCoverageY(2000000))
}

View File

@@ -1,33 +1,33 @@
package main
import (
"aoc2022/day15/common"
"bufio"
"fmt"
"os"
"aoc2022/day15/common"
"bufio"
"fmt"
"os"
)
func main() {
sensors := common.Parse(*bufio.NewScanner(os.Stdin))
tileMap := common.NewMap()
tileMap := common.NewMap()
for _, sensor := range sensors {
tileMap.SetSensor(sensor)
}
for _, sensor := range sensors {
tileMap.SetSensor(sensor)
}
var frequency int
found := false
for i := 0; i <= 4000000 && !found; i++ {
coverage := tileMap.GetCoverageYInXInterval(0, 4000000, i)
if coverage <= 4000000 {
for j := 0; j < 4000000 && !found; j++ {
if tileMap.GetTile(j, i) == common.Free {
frequency = j * 4000000 + i
found = true
}
}
}
}
var frequency int
found := false
for i := 0; i <= 4000000 && !found; i++ {
coverage := tileMap.GetCoverageYInXInterval(0, 4000000, i)
if coverage <= 4000000 {
for j := 0; j < 4000000 && !found; j++ {
if tileMap.GetTile(j, i) == common.Free {
frequency = j * 4000000 + i
found = true
}
}
}
}
fmt.Println(frequency)
fmt.Println(frequency)
}