advent-of-code

Perserverance, or the lack thereof

git clone git://git.shimmy1996.com/advent-of-code.git
commit c80ff36745187674bd373354d3f41b2d3548a866
parent 0c084d14a584da8b7bf14ca3c9893854be6a8984
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date:   Fri, 11 Dec 2020 20:26:15 -0600

Add 2020 day 11

Diffstat:
A2020/day11/input.txt | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/day11/main.go | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 235 insertions(+), 0 deletions(-)
diff --git a/2020/day11/input.txt b/2020/day11/input.txt
@@ -0,0 +1,97 @@
+LL.LL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLL
+LLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLL
+.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLLLLLL.LL.LLLL.LLLLLLLLL.LLLLLLLL
+LLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL
+LLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLL.LLLL.LLLLLLLL.LLLLLLLLLLLLLLLL.LLL.LLLLL.LLLLLLLL
+.LLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLL
+LLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLL
+LLLLL.LLLLLL.LLL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LLLLLLLLLLLL.LLLLLL.L
+....L........L.....LLL....L......LL.L...LLLL.LLL.L.LL.......L.L.L.L......LL..L.LLLL....LL.L
+LLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLLLL..LLLLLLLL.LLLLLLLLLLL
+LLLLL.LLL.LL.LLLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL
+LLLLL.LLLLLL.LLLLLL.LLLLL.LLL.LL..LLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLL
+LLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL
+LLLLL.LLLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLL
+LLLLL.LLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
+LLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLLLL.L.LLLLLLLL.LLLLLLLL.LLLLLLL.LLLLLLLLL.LLLLLLLL
diff --git a/2020/day11/main.go b/2020/day11/main.go
@@ -0,0 +1,138 @@
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"os"
+)
+
+const (
+	FLOOR    = '.'
+	EMPTY    = 'L'
+	OCCUPIED = '#'
+)
+
+type seats struct {
+	width  int
+	height int
+	v      []rune
+}
+
+func (this *seats) val(x, y int) rune {
+	return this.v[x*this.width+y]
+}
+
+func (this *seats) valChecked(x, y int) (rune, bool) {
+	if x >= 0 && x < this.height && y >= 0 && y < this.width {
+		return this.v[x*this.width+y], true
+	} else {
+		return 0, false
+	}
+}
+
+func (this *seats) set(x, y int, val rune) {
+	this.v[x*this.width+y] = val
+}
+
+func (this seats) copy() seats {
+	return seats{this.width, this.height, append([]rune(nil), this.v...)}
+}
+
+func readInput(filename string) (res seats) {
+	file, _ := os.Open(filename)
+	defer file.Close()
+	scanner := bufio.NewScanner(file)
+	for scanner.Scan() {
+		row := scanner.Text()
+		res.height += 1
+		res.width = len(row)
+		for _, ch := range row {
+			res.v = append(res.v, ch)
+		}
+	}
+	return
+}
+
+func main() {
+	input := readInput("./input.txt")
+	// 2281
+	fmt.Println(part(input, update1))
+	// 2085
+	fmt.Println(part(input, update2))
+}
+
+func update1(input seats, x, y int) rune {
+	old := input.val(x, y)
+	if old == FLOOR {
+		return FLOOR
+	}
+	dx := []int{-1, +0, +1, -1, +1, -1, +0, +1}
+	dy := []int{-1, -1, -1, +0, +0, +1, +1, +1}
+	occCount := 0
+	for i := 0; i < len(dx); i++ {
+		val, ok := input.valChecked(x+dx[i], y+dy[i])
+		if ok && val == OCCUPIED {
+			occCount += 1
+		}
+	}
+	if old == EMPTY && occCount == 0 {
+		return OCCUPIED
+	}
+	if old == OCCUPIED && occCount >= 4 {
+		return EMPTY
+	}
+	return old
+}
+
+func update2(input seats, x, y int) rune {
+	old := input.val(x, y)
+	if old == FLOOR {
+		return FLOOR
+	}
+	dx := []int{-1, +0, +1, -1, +1, -1, +0, +1}
+	dy := []int{-1, -1, -1, +0, +0, +1, +1, +1}
+	occCount := 0
+	for i := 0; i < len(dx); i++ {
+		xNew, yNew := x, y
+		for val, ok := FLOOR, true; ok; val, ok = input.valChecked(xNew, yNew) {
+			if val == FLOOR {
+				xNew += dx[i]
+				yNew += dy[i]
+			} else {
+				if val == OCCUPIED {
+					occCount += 1
+				}
+				break
+			}
+		}
+	}
+	if old == EMPTY && occCount == 0 {
+		return OCCUPIED
+	}
+	if old == OCCUPIED && occCount >= 5 {
+		return EMPTY
+	}
+	return old
+}
+
+func part(input seats, updater func(seats, int, int) rune) (occCount int) {
+	curr := input.copy()
+	next := input.copy()
+	for updated := true; updated; {
+		updated = false
+		for x := 0; x < curr.height; x++ {
+			for y := 0; y < curr.width; y++ {
+				old := next.val(x, y)
+				next.set(x, y, updater(curr, x, y))
+				updated = updated || old != next.val(x, y)
+			}
+		}
+		curr, next = next, curr
+	}
+	for _, v := range curr.v {
+		if v == OCCUPIED {
+			occCount += 1
+		}
+	}
+	return
+}