musifter

AoC 2025 day 2, part 2 (dc)

Dec 2nd, 2025 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.89 KB | Source Code | 0 0
  1. # Command: tr -c '0-9' ' ' <input | dc -fdc-p2.dc
  2.  
  3. [ q ] sQ
  4.  
  5. [
  6.     # Note that hash is offset from start of range, so that indices are < 2^31 (max)
  7.     d dls-;h 1r-*           # (1-hash(num-stat))*num num i
  8.     lc+ sc                  # Score if not in hash
  9.     dls- 1 r:h              # Record num in hash
  10. ] sC
  11.  
  12. ?                           # end start ...
  13. [
  14.     se ss
  15.  
  16.     0 Sh                    # Clear hash
  17.  
  18.     1                       # i=1 ...
  19.     [
  20.         dddZAr^ dsf *+      # factor = 10^len(i); num=i,i i ...
  21.         d le <Q             # quit search if two repeats is too large
  22.  
  23.         [
  24.             d le <Q         # quit if (end < num)
  25.             d ls !>C        # count if (num >= start)
  26.  
  27.             lf* r d3R+      # num = num,i
  28.             lAx
  29.         ] dsAx
  30.  
  31.         s. 1+ lLx           # junk num; i++ loop
  32.     ] dsLx +s.
  33.  
  34.     z0<M
  35. ] dsMx
  36.  
  37. [Part 2: ]nlcp
Advertisement
Add Comment
Please, Sign In to add comment