esolang

BuzzFizz

Counters can only go up, and the only way to read one is to ask whether something divides it.

ais523, 2017 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org

Tested with 5 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

ais523 made BuzzFizz in 2017. It looks like an ordinary small imperative language and was meant to be easy to implement and easy to write the usual exercises in, yet short of Turing complete.

Read the story

The trick is in how data is read. A counter can only be incremented, never set or decremented, and a program can never look at its value directly. It can only test whether a counter divides a constant, or a constant divides a counter. FizzBuzz, which asks exactly that, comes out naturally.

Input is hidden in the constants. A constant written as a number is that number. A constant written as a name has no value until it is first used; at that moment the program reads a number from input.

The machine

LineDoes
$c++Add one to counter $c (all start at 0)
print $c / print 12 / print n / print "text"Print, with no newline unless the text has one
if x\y: commandWhen x divides y, clear the else flag and run the command
else: commandRun the command if the else flag is set; then set the flag
loopSet the else flag and go back to the first line
clear nForget constant n, so it is read again
# textA comment

Since only divisibility is visible, a counter that has passed twice the least common multiple of the program's constants behaves like a smaller one. That bounds the useful state of a program by the size of its input, which makes BuzzFizz a linear bounded automaton.

Example

The second is FizzBuzz with spaces instead of newlines.
Expected: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz

The second is FizzBuzz with spaces instead of newlines. The first line only mentions max so that it is read before the loop starts. if 3\$a and if 5\$a both clear the else flag when they match, so the number itself is printed only when neither did. The last two lines loop until max divides $a.

Patterns it teaches

  • Counter machines: a counter machine with the decrement taken away, and what is left.
  • Encoding tricks: a counter that only counts up can still hold a flag, since 2\$x asks whether it is even.

Further

Also in Turing tarpits

Write your own in Run Convert a program from BuzzFizz

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: buzzfizz.

Command line

shib run buzzfizz -e 'print "Hello, World!"'
shib manual buzzfizz

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/buzzfizz.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org