blob: 28428e4f598e071ba2f674b9751e2cf9911fb9b0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package main
import (
"bufio"
"fmt"
"os"
)
var (
grid = make([][]byte, 0)
score = 0
)
func powerup(x, y int) {
if x < 0 || x > 9 || y < 0 || y > 9 || grid[x][y] > 9 {
return
}
grid[x][y]++
if grid[x][y] > 9 {
score++
powerup(x-1, y-1)
powerup(x, y-1)
powerup(x+1, y-1)
powerup(x-1, y)
powerup(x+1, y)
powerup(x-1, y+1)
powerup(x, y+1)
powerup(x+1, y+1)
}
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
l := make([]byte, len(line))
for i := 0; i < len(line); i++ {
l[i] = line[i] - '0'
}
grid = append(grid, l)
}
for i := 0; i < 100; i++ {
for y := 0; y < 10; y++ {
for x := 0; x < 10; x++ {
powerup(x, y)
}
}
for y := 0; y < 10; y++ {
for x := 0; x < 10; x++ {
if grid[x][y] > 9 {
grid[x][y] = 0
}
}
}
}
fmt.Println(score)
}
|