Skip to content

Commit

Permalink
Add day 10p1
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry committed Nov 19, 2023
1 parent a35f7cc commit 823ab6e
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 2022/10p1.go
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
}
}
145 changes: 145 additions & 0 deletions 2022/inputs/10.txt
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
1 change: 1 addition & 0 deletions 2022/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var solutions = map[string]func(){
"08P2:Treetop Tree House": D08P2,
"09P1:Rope Bridge": D09P1,
"09P2:Rope Bridge": D09P2,
"10P1: Cathode-Ray Tube": D10P1,
}

func main() {
Expand Down

0 comments on commit 823ab6e

Please sign in to comment.