0
\$\begingroup\$

A normal Brainfuck program starts out with an array of cells, all containing the number 0. This program, on the other hand, must be able to run starting with any number x in the leftmost cell. The only rule is that at the end of program execution, the "pointed-to" cell must be cell x. (The leftmost cell is cell 0).

  • Each cell contains a number from 0 to 255, and every cell but the leftmost one starts out with a value of 0.
  • There are an infinite number of cells, but none to the left of the leftmost cell.

This is code golf, so the submission using the fewest bytes wins. Good luck!

\$\endgroup\$
4
  • 2
    \$\begingroup\$ I'm not sure I understand what the challenge actually is... perhaps some time on the Sandbox would do it some good? \$\endgroup\$ May 28, 2020 at 21:05
  • \$\begingroup\$ Okay, it took me a while to read correctly, but I guess this seems fine. Maybe tag it atomic-code-golf and include a little description of Brainfuck just for the sake of self-containedness. I'm leaving my close vote in place just in case someone else finds a problem that needs to be fixed, though. \$\endgroup\$ May 28, 2020 at 21:11
  • 1
    \$\begingroup\$ ...well, being self-contained, and defining the behavior of trying to go left from the leftmost cell. Brainfuck has enough variants none of which are standard that we can't really make assumptions here. VTC for being unclear. \$\endgroup\$ May 28, 2020 at 21:16
  • 2
    \$\begingroup\$ In addition to those restictions what happens when + is executed on a 255, or - on a zero? Do they wrap around or just do nothing? \$\endgroup\$
    – Wheat Wizard
    May 28, 2020 at 21:40

2 Answers 2

4
\$\begingroup\$

10 bytes

[[->+<]>-]

Try it online!

Move x one cell to the right, and decrease it by 1. Repeat until x is 0.

\$\endgroup\$
0
\$\begingroup\$

20 bytes

[->>[>]+[<]<]>>[>]<<

Try it online.

This could be made shorter if there were a single cell to the left of cell 0.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.