adventofcode/2016/day18/main.go

44 lines
855 B
Go
Raw Normal View History

2016-12-18 15:32:37 +00:00
package main
import (
"bytes"
"fmt"
"os"
"../../"
)
func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: ./day18 <filename> <numrows>")
}
input := aoc.FileToBytes(os.Args[1])
numRows := aoc.Atoi(os.Args[2])
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")
}