Advertisement
musifter

AoC 2015, dc (part 2)

Nov 17th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | Source Code | 0 0
  1. [ 1sp ] sP
  2.  
  3. 0d # count = 0, sentinel
  4. ?
  5. [
  6. 0dd sp ss St # init flags (pairs, sandwich), clear table/tmp with push
  7.  
  8. # Process string (note: arrives backwards)
  9. [
  10. # pairs
  11. d3R d3R # a b -> a b b a
  12. 27*+ d # -> index index b a
  13. ;t 1=P # set pairs if in table
  14. 1 lt:t st # delay add to table (with tmp) to avoid overlaps
  15. r # b a -> a b
  16.  
  17. # sandwich
  18. 3Rd3R =S r # a b c -> b c (sandwich set if a = c)
  19.  
  20. z 3<L # leave: last-char sentinel count
  21. ] dsLx
  22.  
  23. s. # clear last-char
  24. lpls*++ # count += pair * sandwich + 0 (sentinel)
  25.  
  26. 0 ? z 2<M # leave: sentinel count
  27. ] dsMx
  28.  
  29. +p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement