Advertisement
musifter

AoC 2023, day 1 (dc part 2)

Dec 1st, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | Source Code | 0 0
  1. # Lookup table
  2. 1 dd:t 18996:t
  3. 2 dd:t 32285:t
  4. 3 dd:t 24203441:t
  5. 4 dd:t 1299471:t
  6. 5 dd:t 694023:t
  7. 6 dd:t 43444:t
  8. 7 dd:t 39325060:t
  9. 8 dd:t 49523414:t
  10. 9 dd:t 683663:t
  11.  
  12. [ dsf ] sF
  13.  
  14. # Found digit (sum ... char1 i buff digit)
  15. [
  16. lf 0=F
  17. dsl
  18. ] sN
  19.  
  20. [ 39- ] sS # shift alpha to start at 10
  21.  
  22. 0 # sum
  23. ?
  24. [
  25. 0dd sl sf # using regs for first and last, leave buff=0
  26. [
  27. r 48- # buff char-48
  28. d 9<S # buff ord (1-9 digits, 10-35 alpha)
  29.  
  30. r36*+ 36 5 ^% # append to buffer (chop to last 5 char: 36^5)
  31.  
  32. # Check table:
  33. 5 # buff i
  34. [
  35. d3R d3R # i buff buff i
  36. 36r^ % # i buff (buff % 36^i)
  37. ;t d0!=N # found number if table(buff % 36^i)
  38. s.
  39.  
  40. r1- d0<I # buff i--
  41. ] dsIx
  42. s. # junk i; stack: sum ... char2 char1 buff
  43.  
  44. z2<L
  45. ] dsLx
  46. s. # clear buff
  47.  
  48. ll 10* lf++ # sum += 10*last + first (string reversed)
  49. ? z1<M
  50. ] dsMx
  51.  
  52. [Part 2: ]np
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement