Write a program that outputs the number 0.

That's a bit trivial, isn't it?

Let the length of your program be \$S\$. Write a program that outputs the number 0. When your program is cyclically shifted \$i < S\$ bytes left, it should output \$i\$. To cyclically shift a string \$i\$ bytes left means to move the last \$i\$ bytes (including newlines) to the front, without changing the order.

For example, if your code is ABCD, then ABCD should output 0; DABC should output 1; CDAB should output 2; BCDA should output 3.


  • Your program must be at least 3 bytes long.
  • "Output" represents any acceptable output: on the stack, to STDOUT, as a return value, as an exit code, etc.
  • Your program is to not take any form of input.
  • This is , so shortest code wins.
  • 1
    \$\begingroup\$ I would say this is more interesting as an attempt to make the longest program that satisfies this restriction. Otherwise, a submission of length 3 is automatically the winner. \$\endgroup\$
    – RGS
    Commented Apr 28, 2020 at 12:07
  • \$\begingroup\$ @RGS Won't a brainfuck ".++++++++++++++++++++++++++++++++++++++ <infinitely many pluses>` work? \$\endgroup\$
    – user62257
    Commented Apr 28, 2020 at 12:09
  • \$\begingroup\$ @BaaingCow also true :) except that in most bf implementations you are capped at 255 because the memory is mod 256 \$\endgroup\$
    – RGS
    Commented Apr 28, 2020 at 12:11
  • \$\begingroup\$ i'm disappointed :( \$\endgroup\$
    – user62257
    Commented Apr 28, 2020 at 12:11
  • 5
    \$\begingroup\$ @BaaingCow please update the challenge to allow the right-shift, comments can become cluttered and are a non-optimal way of providing specifications. \$\endgroup\$ Commented Apr 28, 2020 at 16:35

4 Answers 4


brainfuck, 3 bytes


Try it online!

how it works: it's really simple, actually. The internal memory is initialized at 0 so we output (with .) the original cell and we get 0. By shifting the program, we are shifting memory increments (done with +) to before the output, so each byte shifted corresponds to one more increment, and hence we increase the counter.

  • \$\begingroup\$ FGITW, you win. \$\endgroup\$
    – user92069
    Commented Apr 28, 2020 at 12:26
  • \$\begingroup\$ @petStorm *LGITW to be honest; (luckiest instead of fastest) I haven't been around much and I was lucky enough to scroll past this challenge while it had no answers :) \$\endgroup\$
    – RGS
    Commented Apr 28, 2020 at 13:42

Jelly, 3 bytes


The implicit input of a Jelly program is 0:

Try ‘n¬ online! 0 incremented \$\neq\$ not(0) \$\implies0+1 \neq 1 \implies 1\neq 1 \implies 0\$
Try ¬‘n online! not(0) incremented \$\neq\$ 0 \$\implies1+1\neq 0 \implies 2\neq 0 \implies 1\$
Try n¬‘ online! (0 \$\neq\$ not(0)) incremented \$\implies(0\neq 1)+1 \implies 1+1 \implies 2\$


Keg -hd, 3 bytes


Try it online!


Keg only outputs the top item of the stack. These individual digits push themselves onto the stack. So for every cyclic shift, it outputs the character code of the top of the stack.

Program ->   Stack   -> Output last item
  210   -> [2, 1, 0] ->       [0]
  021   -> [0, 2, 1] ->       [1]
  102   -> [1, 0, 2] ->       [2]

05AB1E, 3 bytes

Right-shifts instead of left-shifts.


Try it online!


>>g : >>  Increment empty string twice
        g Find the length of the empty string (0)

>g> : >   Increment empty string
       g  Find the length (0)
        > Increment that (1)

g>> : g   Find length of empty string (0)
       >> Increment twice (2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.