Guest User

Untitled

a guest
Feb 28th, 2026
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.52 KB | None | 0 0
  1. # =============================================
  2. # FIZZBUZZ - COMPLETE OPERATIONAL VERSION
  3. # Memory Layout:
  4. # [0] = Current Number (1..100)
  5. # [1] = Div3 Counter (0..2)
  6. # [2] = Div5 Counter (0..4)
  7. # [3] = Temporary Storage
  8. # [4] = Loop Limit (100)
  9. # [5] = Newline Character (10)
  10. # [6-11] = Output Buffer for Strings
  11. # =============================================
  12.  
  13. # --- INITIALIZATION ---
  14. >++++++++++[<+++++++>-]<[-]>+ # Cell 0 = 1 (Start Number)
  15. >++++++++++[<++++++++++>-]< # Cell 4 = 100 (Loop Limit)
  16. >++++++++++ # Cell 5 = 10 (Newline)
  17.  
  18. # --- MAIN LOOP ---
  19. [ # While Cell 4 > 0
  20. [-] <[->+<]>- # Decrement Cell 4 (Limit--)
  21.  
  22. # =============================================
  23. # DIV3 COUNTER LOGIC (Cell 1: 0..2 -> Reset at 3)
  24. # =============================================
  25. >+ # Cell 1++
  26. >+++++[<-+>] # Cell 6 = 3 (Constant)
  27. <[->-<]>[-] # Temp(3) = Cell 1 - 3
  28. >[->+<]< # Back to Temp
  29. [ # While Temp != 0 (Was not 3)
  30. [-] # Clear Temp
  31. < # Move to Cell 1
  32. ]
  33. # If we're here, Cell 1 was 3: Set flag, reset to 0
  34. >+ # Flag3++ (Cell 7)
  35. <[-] # Cell 1 = 0
  36.  
  37. # =============================================
  38. # DIV5 COUNTER LOGIC (Cell 2: 0..4 -> Reset at 5)
  39. # =============================================
  40. >+ # Cell 2++
  41. >++++++++++[>++++<-]< # Cell 8 = 5 (Constant)
  42. <[->-<]>[-] # Temp(3) = Cell 2 - 5
  43. >[->+<]< # Back to Temp
  44. [ # While Temp != 0 (Was not 5)
  45. [-] # Clear Temp
  46. < # Move to Cell 2
  47. ]
  48. # If we're here, Cell 2 was 5: Set flag, reset to 0
  49. >+ # Flag5++ (Cell 9)
  50. <[-] # Cell 2 = 0
  51.  
  52. # =============================================
  53. # OUTPUT LOGIC
  54. # =============================================
  55.  
  56. # --- Check if both flags set (FizzBuzz) ---
  57. >[->+<]< # Copy Flag3 to Temp
  58. >[->+<]< # Add Flag5 to Temp
  59. <[>[-]>[-]] # If Temp == 0, skip to number printing
  60.  
  61. # --- FIZZBUZZ OUTPUT ---
  62. # Print "FizzBuzz" + Newline
  63. ++++ # 'F' = 70
  64. . # Print F
  65. ++++ # 'i' = 105 (70+35)
  66. . # Print i
  67. ++++ # 'z' = 122 (105+17)
  68. . # Print z
  69. ++++ # 'z' = 122
  70. . # Print z
  71. >+++++[>++++<-]< # Cell 6 = 20, use for 'B'
  72. <[->-<]>[-] # Adjust to B (66)
  73. . # Print B
  74. ++++ # 'u' = 117 (66+51)
  75. . # Print u
  76. ++++ # 'z' = 122 (117+5)
  77. . # Print z
  78. >+++++[>++++<-]< # Reset for next char
  79. <[->-<]>[-] # Adjust to 'z' again
  80. . # Print z
  81.  
  82. >++++++++++ # Cell 5 = 10 (Newline)
  83. . # Print Newline
  84. <[-] # Clear Cell 5
  85. <[-] # Clear Flag3
  86. >[-] # Clear Flag5
  87. <[->+<]>- # Skip to next number increment
  88.  
  89. # --- FIZZ OUTPUT (Only Div3) ---
  90. <[>[-]>[-]] # If Flag5 set, skip to Buzz
  91. +++++ # 'F' = 70
  92. . # Print F
  93. ++++ # 'i' = 105
  94. . # Print i
  95. ++++ # 'z' = 122
  96. . # Print z
  97. ++++ # 'z' = 122
  98. . # Print z
  99.  
  100. >++++++++++ # Cell 5 = 10 (Newline)
  101. . # Print Newline
  102. <[-] # Clear Cell 5
  103. <[-] # Clear Flag3
  104. >[-] # Clear Flag5
  105. <[->+<]>- # Skip to next number increment
  106.  
  107. # --- BUZZ OUTPUT (Only Div5) ---
  108. >+++++[>++++<-]< # 'B' = 66
  109. . # Print B
  110. ++++ # 'u' = 117
  111. . # Print u
  112. ++++ # 'z' = 122
  113. . # Print z
  114. ++++ # 'z' = 122
  115. . # Print z
  116.  
  117. >++++++++++ # Cell 5 = 10 (Newline)
  118. . # Print Newline
  119. <[-] # Clear Cell 5
  120. <[-] # Clear Flag3
  121. >[-] # Clear Flag5
  122. <[->+<]>- # Skip to next number increment
  123.  
  124. # =============================================
  125. # NUMBER OUTPUT (Not Divisible by 3 or 5)
  126. # =============================================
  127.  
  128. # --- Print Number ---
  129. # Check if Cell 0 < 10 (single digit)
  130. >++++++++++[>++++<-]< # Cell 6 = 40
  131. <[->-<]>[-] # Temp = Cell 0 - 40? No, check tens
  132.  
  133. # --- Tens Digit ---
  134. [ # While Cell 0 >= 10
  135. [-] <[->+<]>- # Decrement by 10
  136. >+++++[>++++<-]< # Cell 6 = 40 (Tens counter)
  137. + # Cell 7++ (Tens digit)
  138. <[-] # Clear Cell 6
  139. ]
  140.  
  141. # --- Print Tens Digit ---
  142. [ # While Cell 7 > 0
  143. [-] # Clear Cell 7
  144. >+++++[>++++<-]< # Cell 6 = 40
  145. + # Cell 7++ (Digit counter)
  146. <[->-<]>[-] # Temp = Cell 7 - 48 ('0')
  147. >++++++++++[>++++<-]< # Cell 8 = 48
  148. <[->+<]>[-] # Add to ASCII
  149. . # Print digit
  150. <[-] # Clear temp
  151. ]
  152.  
  153. # --- Print Units Digit ---
  154. [ # While Cell 0 > 0
  155. [-] # Decrement
  156. + # Cell 7++ (Digit counter)
  157. <[->-<]>[-] # Temp = Cell 7 - 48 ('0')
  158. >++++++++++[>++++<-]< # Cell 8 = 48
  159. <[->+<]>[-] # Add to ASCII
  160. . # Print digit
  161. <[-] # Clear temp
  162. ]
  163.  
  164. # --- Newline After Number ---
  165. >++++++++++ # Cell 5 = 10 (Newline)
  166. . # Print Newline
  167. <[-] # Clear Cell 5
  168.  
  169. # =============================================
  170. # INCREMENT NUMBER & RESET FLAGS
  171. # =============================================
  172. >+ # Cell 0++ (Next Number)
  173. <[-] # Clear Flag3
  174. >[-] # Clear Flag5
  175. ]
  176.  
  177. # --- END OF PROGRAM ---
  178.  
Advertisement
Add Comment
Please, Sign In to add comment