-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a35f7cc
commit 823ab6e
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
noop | ||
noop | ||
addx 5 | ||
addx 21 | ||
addx -16 | ||
noop | ||
addx 1 | ||
noop | ||
noop | ||
addx 4 | ||
addx 1 | ||
addx 4 | ||
addx 1 | ||
noop | ||
addx 4 | ||
addx -9 | ||
noop | ||
addx 19 | ||
addx -5 | ||
noop | ||
noop | ||
addx 5 | ||
addx 1 | ||
addx -38 | ||
addx 5 | ||
addx -2 | ||
addx 2 | ||
noop | ||
noop | ||
addx 7 | ||
addx 9 | ||
addx 20 | ||
addx -3 | ||
addx -18 | ||
addx 2 | ||
addx 5 | ||
noop | ||
noop | ||
addx -2 | ||
noop | ||
noop | ||
addx 7 | ||
addx 3 | ||
addx -2 | ||
addx 2 | ||
addx -28 | ||
addx -7 | ||
addx 5 | ||
noop | ||
addx 2 | ||
addx 32 | ||
addx -27 | ||
noop | ||
noop | ||
noop | ||
noop | ||
noop | ||
addx 7 | ||
noop | ||
addx 22 | ||
addx -19 | ||
noop | ||
addx 5 | ||
noop | ||
addx -7 | ||
addx 17 | ||
addx -7 | ||
noop | ||
addx -20 | ||
addx 27 | ||
noop | ||
addx -16 | ||
addx -20 | ||
addx 1 | ||
noop | ||
addx 3 | ||
addx 15 | ||
addx -8 | ||
addx -2 | ||
addx -6 | ||
addx 14 | ||
addx 4 | ||
noop | ||
noop | ||
addx -17 | ||
addx 22 | ||
noop | ||
addx 5 | ||
noop | ||
noop | ||
noop | ||
addx 2 | ||
noop | ||
addx 3 | ||
addx -32 | ||
addx -5 | ||
noop | ||
addx 4 | ||
addx 3 | ||
addx -2 | ||
addx 34 | ||
addx -27 | ||
addx 5 | ||
addx 16 | ||
addx -18 | ||
addx 7 | ||
noop | ||
addx -2 | ||
addx -1 | ||
addx 8 | ||
addx 14 | ||
addx -9 | ||
noop | ||
addx -15 | ||
addx 16 | ||
addx 2 | ||
addx -35 | ||
noop | ||
noop | ||
noop | ||
noop | ||
addx 3 | ||
addx 4 | ||
noop | ||
addx 1 | ||
addx 4 | ||
addx 1 | ||
noop | ||
addx 4 | ||
addx 2 | ||
addx 3 | ||
addx -5 | ||
addx 19 | ||
addx -9 | ||
addx 2 | ||
addx 4 | ||
noop | ||
noop | ||
noop | ||
noop | ||
addx 3 | ||
addx 2 | ||
noop | ||
noop | ||
noop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters