Implement a function or program that can run simplified BitCycle code. The functions you must implement are:
<^>v
: Change the direction of a bit to the direction this is pointing.
+
: Turn all 0s left and all 1s right.
\
and /
: Reflect one bit 90 degrees, then become inactive. In regular BitCycle, this is displayed as -
or |
, but that isn't required here. There are no collectors in this implementation, so these will never reset.
?
: Take one bit at a time from input and send it east until all input is gone. You only need to worry about one input here. Bits only input from ?
.
!
: Output and delete the bit present here. Only one output is required.
~
: Send the inputted bit right and a negated version of it left.
@
: When a bit hits this device, terminate the program.
The =
, 0
, and 1
operations, multiple inputs/outputs, and collectors are not included in this specification. Other than that, everything should behave the same as in regular BitCycle.
Basic BitCycle Rules
The program itself forms a rectangular grid. A list of bits, either 0 or 1, will be taken as input, and a potentially-empty list of bits will be given as output. Bits travel rightwards at a rate of 1 character per cycle (which is the term I will try to use for each "tick" of the program) until they hit some sort of operation character. In those cases, they will behave as specified by the operator. Code will stop running upon hitting a @
character, or, depending on your output specification, also after some amount of time.
Left-right turns (from +
) are relative to the direction of input. For example, if the character entered from the right, 0s will head downwards and 1s upward.
In standard BitCycle, values output as soon as they reach a !
character. However you may instead save all the bits and output them at the end, as long as your interpreter will stop evaluation after some amount of time. Any bit which leaves the grid is destroyed.
For the purpose of this challenge, if it doesn't otherwise interfere with your code (ignoring integer overflow of their position), you may choose to not destroy the bits and just have them continue moving in the direction they were.
All undefined characters are no-ops.
Example Programs (mostly taken from the BitCycle github)
?!
Cat program
v ~
!+~
?^<
Truth Machine
? v
~ /
>! <
Negate the first bit, output the rest
?~
@+!
Output all 0s before the first 1
Rules
This is code-golf, so lowest byte count wins.
Standard I/O rules apply for both the bits and the program.
You may choose whether to output as bits, a signed integer, or an unsigned integer, however, you must always be able to handle a case with only 1 or 0 bits as output AND if you don't output as bits, your program must meet the output-at-end rules. This is because any integer-output version wouldn't output anything on an infinite loop unless there was some form of max round number.
If you are outputting all bits at the end, your code must stop after some number of rounds. You may handle this in any "reasonable" way, as long as most simple programs will fully evaluate before your code automatically halts them.
A few examples of a valid method for halting the code:
- A button that shows the round number, and when pressed, outputs all bits and halts the program.
- A program which halts in n cycles, where n based on the number of flags it is given (as long as the max size of n isn't unreasonably small)
- A third input which specifies the number of cycles it should do.
- A program that always halts after 1000 cycles.
- A function which halts after going 100 cycles with no new I/O.
-u
flag (unsigned integers), or under the-U
flag (signed integers)? Reason why I'm asking is because programs will have different outputs based on what flag the program is ran under. \$\endgroup\$11!
will output11
when ran normally, but will output2
when ran under the-u
or-U
flag. \$\endgroup\$1
's if under any of the flags). If so, please specify that in the post. \$\endgroup\$