-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10.go
88 lines (71 loc) · 1.36 KB
/
day10.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bufio"
_ "embed"
"fmt"
"strconv"
"strings"
)
//go:embed input.txt
var input string
const SCREEN_WIDTH = 40
const SCREEN_HEIGHT = 6
var screen [SCREEN_HEIGHT][SCREEN_WIDTH]bool
var cycle int = 0
var register int = 1
var sumOfSignalStrength int = 0
func UpdateSignalStrength() {
if (cycle-20)%40 == 0 {
sumOfSignalStrength += register * cycle
}
}
func PrintScreen() {
var scr string
for row := 0; row < SCREEN_HEIGHT; row++ {
for col := 0; col < SCREEN_WIDTH; col++ {
if screen[row][col] {
scr += "█"
} else {
scr += "."
}
}
scr += "\n"
}
fmt.Println(scr)
}
var row int = 0
func Crt() {
synced := cycle % SCREEN_WIDTH
if synced == register-1 || synced == register || synced == register+1 {
screen[row][synced] = true
}
if (cycle+1)%SCREEN_WIDTH == 0 {
row++
}
}
func Part1() int {
scanner := bufio.NewScanner(strings.NewReader(input))
scanner.Split(bufio.ScanLines)
Crt()
for scanner.Scan() {
line := scanner.Text()
// noop or 1st cycle of addx
cycle++
UpdateSignalStrength()
Crt()
if line[0] == 'a' { // 2nd cycle of addx
cycle++
UpdateSignalStrength()
value, _ := strconv.Atoi(line[5:])
register += value
Crt()
}
}
return sumOfSignalStrength
}
func Solve() (int, int) {
part1 := Part1()
PrintScreen()
part2 := 0
return part1, part2 // 13140/17020 , / RLEZFLGE
}