Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Part 1
- [string[]]$instructions = $puzzleInput -split '\n' | Select -SkipLast 1
- $cpu = [ordered]@{}
- $cpu.register = 1
- $cpu.cycle = 1
- $dB = [ordered]@{}
- $checkdBincr = {
- if ($cpu.cycle % 20 -eq 0) {
- $dB.$($cpu.cycle) = $cpu.register * $cpu.cycle
- }
- $cpu.cycle++
- }
- for ($i = 0; $i -lt $instructions.count; $i++) {
- &$checkdBincr
- if ($instructions[$i] -eq 'noop') {continue}
- $null,[int]$addX = $instructions[$i] -split ' '
- &$checkdBincr
- $cpu.register = $cpu.register + $addX
- }
- $dB.sum = (20,60,100,140,180,220 | Foreach {$dB["$_"]} | Measure -Sum).Sum
- $dB
Advertisement
Add Comment
Please, Sign In to add comment