adventofcode/2016/day18/main.go

44 lines
897 B
Go
Raw Normal View History

2016-12-18 15:32:37 +00:00
package main
import (
"bytes"
"fmt"
"os"
2023-12-17 16:52:08 +00:00
h "git.bullercodeworks.com/brian/adventofcode/helpers"
2016-12-18 15:32:37 +00:00
)
func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: ./day18 <filename> <numrows>")
}
2023-12-17 16:52:08 +00:00
input := h.FileToBytes(os.Args[1])
numRows := h.Atoi(os.Args[2])
2016-12-18 15:32:37 +00:00
room := [][]byte{input}
for row := 1; row < numRows; row++ {
room = append(room, []byte{})
for tile := 0; tile < len(room[0])-1; tile++ {
var l, r byte
switch tile {
case 0:
l, r = '.', room[row-1][tile+1]
case len(input) - 2:
l, r = room[row-1][tile-1], '.'
default:
l, r = room[row-1][tile-1], room[row-1][tile+1]
}
if l != r && (l == '^' || r == '^') {
room[row] = append(room[row], '^')
} else {
room[row] = append(room[row], '.')
}
}
}
var safeCount int
for i := range room {
safeCount += bytes.Count(room[i], []byte{'.'})
}
fmt.Println(safeCount, "safe tiles")
}