-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.go
54 lines (52 loc) · 774 Bytes
/
10.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
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
x := 1
cycle := 1
strength := 0
scycle := 20
crt := []string{}
row := ""
sprite := 0
tick := func() {
if cycle == scycle {
strength += cycle * x
scycle += 40
}
if (cycle-1)%40 == 0 {
crt = append(crt, row)
row = ""
sprite = 0
}
if sprite >= x-1 && sprite <= x+1 {
row += "#"
} else {
row += "."
}
cycle += 1
sprite += 1
}
for scanner.Scan() {
var instruction string
var n int
fmt.Sscanf(scanner.Text(), "%s %d", &instruction, &n)
switch instruction {
case "noop":
tick()
case "addx":
tick()
tick()
x += n
}
}
fmt.Println(strength)
for _, r := range crt {
fmt.Println(r)
}
fmt.Println(row)
}