Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

3 of 7
added 3 characters in body
d01
  • 3.5k
  • 15
  • 26

Rattle, 54 bytes

Fizz&Buzz|!sSs1S1s2P3[g+R1bs%3[0b1b^0]g%5[0b2b^0]B]100

Try it online!

This is my first answer in my new programming language! Please note: this language is not available yet on TIO, but because the interpreter itself is in Python 3, then I can still provide links to my answers. For these answers, the interpreter itself is in the header while the code for DENSE is in the actual code section. Note that the \ in the code section is necessary only as a continuation character and is not part of the DENSE code. Eventually, DENSE will probably be added to TIO and the above code will run natively. If you hit run on TIO, this code will still produce the correct output.

I am also still open to suggestions for what to name my language - DENSE is simply a placeholder.

If you're interested in learning this new language, I would recommend you wait about a week. I admit, the documentation is not great yet but I'm working on improving it.

Eventually, this programming language might have a more concise way to solve this challenge.

Explanation

Fizz&Buzz is a hard-coded input which gets split automatically into a list
| signals the end of the input
! is a flag to disable implicit printing at EOF
sS saves the list to memory slot 0, selects the first index of the list
s1S1 saves this to memory slot 1, selects list index 2
s2P3 saves this to memory slot 2, moves pointer to slot 3
[ start outer loop
g+is gets value at slot 3 (initialized to zero), increments, prints it as an integer, saves to slot 3
%3 takes the current value on stack and pushes the value mod 3 to stack
[0b1] if the value on stack is equal to 0, concatenates value from memory slot 1 to a buffer
g%5 pushes value from slot 3 to stack, takes the value and pushes the value mod 5 to stack
[0b2] if the value on stack is equal to 0, concatenates the value from memory slot 2 to the buffer
B if the buffer is non-empty, prints buffer
]100 end outer loop - repeats 100 times

edit: This new version actually replaces the numbers with Fizz and/or Buzz, the last version did not

d01
  • 3.5k
  • 15
  • 26

AltStyle によって変換されたページ (->オリジナル) /