New Shared Library

This commit is contained in:
2021-12-16 21:11:39 +00:00
parent 1a2247044a
commit 6111f86a04
24 changed files with 559 additions and 392 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"AdventOfCode2021/shared"
"bufio"
"fmt"
"os"
@ -12,7 +13,7 @@ func main() {
content := returnContent("../input")
//content := returnContent("../testInput")
sheet := make(map[Coordinate]bool)
sheet := make(map[shared.Coordinate]bool)
//var answer string
for _, line := range *content {
@ -37,14 +38,14 @@ func main() {
x, _ := strconv.Atoi(coordinates[0])
y, _ := strconv.Atoi(coordinates[1])
sheet[Coordinate{X: x, Y: y}] = true
sheet[shared.Coordinate{X: x, Y: y}] = true
}
}
for y := 0; y < 8; y++ {
for x := 0; x < 200; x++ {
if sheet[Coordinate{X: x, Y: y}] {
if sheet[shared.Coordinate{X: x, Y: y}] {
fmt.Print("#")
} else {
fmt.Print(" ")
@ -55,8 +56,8 @@ func main() {
}
func FoldX(sheet map[Coordinate]bool, foldPoint int) (folded map[Coordinate]bool) {
folded = make(map[Coordinate]bool)
func FoldX(sheet map[shared.Coordinate]bool, foldPoint int) (folded map[shared.Coordinate]bool) {
folded = make(map[shared.Coordinate]bool)
for mark := range sheet {
x := mark.X
if x > foldPoint {
@ -64,13 +65,13 @@ func FoldX(sheet map[Coordinate]bool, foldPoint int) (folded map[Coordinate]bool
x = 2*foldPoint - x
}
folded[Coordinate{X: x, Y: mark.Y}] = true
folded[shared.Coordinate{X: x, Y: mark.Y}] = true
}
return
}
func FoldY(sheet map[Coordinate]bool, foldPoint int) (folded map[Coordinate]bool) {
folded = make(map[Coordinate]bool)
func FoldY(sheet map[shared.Coordinate]bool, foldPoint int) (folded map[shared.Coordinate]bool) {
folded = make(map[shared.Coordinate]bool)
for mark := range sheet {
y := mark.Y
if y > foldPoint {
@ -78,16 +79,11 @@ func FoldY(sheet map[Coordinate]bool, foldPoint int) (folded map[Coordinate]bool
y = 2*foldPoint - y
}
folded[Coordinate{X: mark.X, Y: y}] = true
folded[shared.Coordinate{X: mark.X, Y: y}] = true
}
return
}
type Coordinate struct {
X int
Y int
}
func returnContent(path string) *[]string {
//read file and return it as an array of integers