crlogic

Day10

Dec 10th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. # Part 1
  2. [string[]]$instructions = $puzzleInput -split '\n' | Select -SkipLast 1
  3. $cpu = [ordered]@{}
  4. $cpu.register = 1
  5. $cpu.cycle = 1
  6. $dB = [ordered]@{}
  7. $checkdBincr = {
  8. if ($cpu.cycle % 20 -eq 0) {
  9. $dB.$($cpu.cycle) = $cpu.register * $cpu.cycle
  10. }
  11. $cpu.cycle++
  12. }
  13. for ($i = 0; $i -lt $instructions.count; $i++) {
  14. &$checkdBincr
  15. if ($instructions[$i] -eq 'noop') {continue}
  16. $null,[int]$addX = $instructions[$i] -split ' '
  17. &$checkdBincr
  18. $cpu.register = $cpu.register + $addX
  19. }
  20. $dB.sum = (20,60,100,140,180,220 | Foreach {$dB["$_"]} | Measure -Sum).Sum
  21. $dB
Advertisement
Add Comment
Please, Sign In to add comment