Advertisement
musifter

AoC 2024, day 22, part 1 faster (dc)

Dec 22nd, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.10 KB | Source Code | 0 0
  1. # Command: dc -fdc-p1-fast.dc <input
  2.  
  3. # Precreating all the numerical constants and assigning them registers
  4. 0s0
  5. 1s1
  6. 2s2
  7. 3s3
  8. 4s4
  9. 5s5
  10.  
  11. 64sa
  12. 32sb
  13. 2048sc
  14. 2000sd
  15. 24se
  16. _1sf
  17.  
  18. # 24-bit XOR top two on stack (counter; 2 bits at a time)
  19. [
  20.     l0d                         # (i=bit#) result
  21.     [
  22.         l3Rl4R                  # arg2 arg1 i result
  23.  
  24.         l4~ l3R l4~             # (B-low2) Brest (A-low2) Arest i result
  25.         l3R
  26.         dlfr^l3R*+l4dl3R+r%     # (B^A low2) (B-rest) (A-rest) i result
  27.  
  28.         l4R d l2r^ l3R*         # (bit<<i) i rest1 rest2 result
  29.         l5R+                    # (result+=bit) i rest1 rest2
  30.         rl2+ d le>L             # i+=2, loop until i == 24
  31.     ] dsLx l3Rl4R++s.           # 3 result junk2 junk1
  32. ] s^
  33.  
  34. ?
  35. [
  36.     #[num: ]np
  37.     ld                      # i num
  38.     [
  39.         r                   # num i
  40.         d la* l^x           # num = (64*num) ^ num
  41.         d lb/ l^x           # num = (num/32) ^ num
  42.         d lc* l^x           # num = (2048*num) ^ num
  43.  
  44.         rl1- dl0<I
  45.     ] dsIx +
  46.  
  47.     lp+sp
  48.  
  49.     ? zl0<M
  50. ] dsMx
  51.  
  52. [Part 1: ]n lpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement