-
Notifications
You must be signed in to change notification settings - Fork 0
/
10p1.go
40 lines (32 loc) · 917 Bytes
/
10p1.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
package main
import (
"fmt"
"strconv"
"aoc2022/utils"
)
func D10P1() {
instructions := utils.ReadLines("inputs/10.txt")
registerValue := 1
signalStrengthTotal := 0
cycleNumber := 1
for _, instruction := range instructions {
if instruction[0] == 'a' {
updateSignalStrength(&signalStrengthTotal, cycleNumber, registerValue)
cycleNumber++
updateSignalStrength(&signalStrengthTotal, cycleNumber, registerValue)
cycleNumber++
instructionValue, _ := strconv.Atoi(instruction[5:])
registerValue += instructionValue
continue
}
updateSignalStrength(&signalStrengthTotal, cycleNumber, registerValue)
cycleNumber++
}
fmt.Printf("Signal strength: %d\n", signalStrengthTotal)
}
func updateSignalStrength(signalStrengthTotal *int, cycleNumber int, registerValue int) {
switch cycleNumber {
case 20, 60, 100, 140, 180, 220:
*signalStrengthTotal += cycleNumber * registerValue
}
}