From df7e686f243cf5b177e74e1aa67d97b0893c3b60 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Sun, 18 Dec 2022 20:59:46 +0100 Subject: start day14 --- day14.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ day14.txt | 2 ++ 2 files changed, 62 insertions(+) create mode 100644 day14.go create mode 100644 day14.txt 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 -- cgit v1.2.3