summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2022-12-18 20:59:46 +0100
committerMike Vink <mike1994vink@gmail.com>2022-12-18 20:59:46 +0100
commitdf7e686f243cf5b177e74e1aa67d97b0893c3b60 (patch)
tree28d61673b55be940859c76a3020f42c751656d6b
parent0679280f51e94fefe6c6cabac7bead095033b21f (diff)
start day14
-rw-r--r--day14.go60
-rw-r--r--day14.txt2
2 files changed, 62 insertions, 0 deletions
diff --git a/day14.go b/day14.go
new file mode 100644
index 0000000..c1babe6
--- /dev/null
+++ b/day14.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "log"
+ "os"
+ "strconv"
+ "strings"
+)
+
+type coord struct {
+ x, y int
+}
+
+type cave struct {
+ scan []byte
+}
+
+func main() {
+ f, err := os.Open("day14.txt")
+ if err != nil {
+ log.Fatal("Could not read input file")
+ }
+
+ s := bufio.NewScanner(f)
+ coords := []coord{}
+ xmin, xmax := 1<<31, 0
+ ymin, ymax := 1<<31, 0
+ for s.Scan() {
+ line := s.Text()
+ for _, coordString := range strings.Split(line, "->") {
+ nums := strings.Split(strings.Trim(coordString, " "), ",")
+ x, err := strconv.Atoi(nums[0])
+ if err != nil {
+ panic(err)
+ }
+ y, err := strconv.Atoi(nums[1])
+ if err != nil {
+ panic(err)
+ }
+ if x > xmax {
+ xmax = x
+ }
+ if x < xmin {
+ xmin = x
+ }
+ if y > ymax {
+ ymax = y
+ }
+ if y < ymin {
+ ymin = y
+ }
+ coords = append(coords, coord{x, y})
+ }
+ }
+ fmt.Println(coords, xmin, xmax, ymin, ymax)
+
+ cave := &cave{scan: make([]byte, (xmax-xmin)*(ymax-ymin))}
+}
diff --git a/day14.txt b/day14.txt
new file mode 100644
index 0000000..4e87bb5
--- /dev/null
+++ b/day14.txt
@@ -0,0 +1,2 @@
+498,4 -> 498,6 -> 496,6
+503,4 -> 502,4 -> 502,9 -> 494,9