Advertisement
musifter

AoC 2024, day 1, part 2 (dc)

Dec 1st, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.39 KB | Source Code | 0 0
  1. # Command: dc -fdc-p2-nosentinel.dc <input 2>/dev/null
  2. # Redirecting the error for popping an empty stack to /dev/null
  3.  
  4. # Read Input
  5. ?
  6. [
  7.     # stack: item2  item1
  8.     d;b 1+ r:b      # b(item2)++
  9.     Sa              # push item1 on stack a
  10.     ? z0<I
  11. ] dsIx
  12.  
  13. # Process
  14. 0 La                # item sum
  15. [
  16.     d;b *+          # sum += b(item) * item
  17.     La z1<L
  18. ] dsLx
  19.  
  20. [Part 2: ]np
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement