package main import ( "bytes" "fmt" "os" h "git.bullercodeworks.com/brian/adventofcode/helpers" ) func main() { if len(os.Args) < 3 { fmt.Println("Usage: ./day18 ") } input := h.FileToBytes(os.Args[1]) numRows := h.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") }