-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path457.go
54 lines (47 loc) · 850 Bytes
/
457.go
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
// UVa 457 - Linear Cellular Automata
package main
import (
"fmt"
"io"
"os"
)
var (
symbol = [4]byte{' ', '.', 'x', 'W'}
out io.WriteCloser
)
func output(dish []int) {
for _, vi := range dish {
fmt.Fprintf(out, "%c", symbol[vi])
}
fmt.Fprintln(out)
}
func solve(dna []int) {
dish := make([]int, 42)
dish[20] = 1
for i := 0; i < 50; i++ {
output(dish[1:41])
next := make([]int, 42)
for i := 1; i <= 40; i++ {
next[i] = dna[dish[i-1]+dish[i]+dish[i+1]]
}
copy(dish, next)
}
}
func main() {
in, _ := os.Open("457.in")
defer in.Close()
out, _ = os.Create("457.out")
defer out.Close()
var kase int
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
fmt.Fscanln(in)
dna := make([]int, 10)
for i := range dna {
fmt.Fscanf(in, "%d", &dna[i])
}
solve(dna)
if kase > 1 {
fmt.Fprintln(out)
}
}
}