Countable

From Esolang
Jump to navigation Jump to search

Countable is a possible Turing tarpit (see talk page) based on Iterate's accumulative model.

Memory

Countable consists of a set of accumulators, which can be created, incremented, and read from, with no additional interactions. All accumulators can store a single positive integer from 0 to infinity.

Commands

n and x refer to a numeric value, which can be a positive integer or infinity. Dereferencing may be done by prefixing a value with one or more a's. Registers 0 and infinity are valid registers.

Command Action
x+n Increment accumulator x by n. n must be a positive integer, and may be omitted if it is equal to 1.
x*n< ... > Repeat the inner contents n times, with an optional label x. Multiple loops may share a label, and the label may be dynamic.
x& Jump to the end of label x if you are inside it, skipping to the next iteration of the loop.
x@ (Optional) Read a byte, storing it in accumulator x.
%n (Optional) Output n modulo 256 as a byte.

Examples

Cat

1+2         // This will be used to track the current accumulator.
1*1<        // Outer loop to act as a breaking mechanism
  2*∞<      // Actual read-write loop
    a1@     // Store input into the current accumulator
    *aa1<   // If that input isn't zero...
      %aa1  // Print it
      1+1   // Update the pointer to point to the next empty accumulator
      2&    // Skip the break
    >
    1&      // If the input is zero, break
  >
>

Decrement

1+VALUE   // Where VALUE is any numeric value
1*a2<     // Increment a2 to equal a1 minus one
  *a3<    // Doesn't run on the first step, since a3 == 0 then
    2+1   // Increment a2
    1&    // Skip more increments of a3
  >
  3+1     // Set a3 to 1
>

Subtraction

5+VALUE1 // Value 1
1+VALUE2 // Value 2
2+5      // Value tracker
3+6      // Flag tracker
4+7      // Result tracker

*a1<       // Decrement loop
  1*aa2<
    *aa3<
      a4+1
      1&
    >
    a3+1
  >
  2+2
  3+2
  4+2
>

/*
initial
flag
result -> initial
          flag
          result -> initial
                    flag
                    result -> ...
                               */

Kolakoski sequence

1+3 // Current digit
2+3 // End of stack
3+1 // Kolakoski digit 3 (2 is stored as 1 for ease of processing)
%49 %50 // 1, 2
*∞<
  1*1<
    *aa1< // if the current digit is 2...
      *aa2< // if the last digit is 2...
        2+2  // set next 2 digits to 1
        1&
      >     // else...
      *2<   // if the last digit is 1...
        2+1  // set next 2 digits to 2
        a2+1 // ^^^
      >
      1&
    >      // else...
    *1<   // if the current digit is 1...
      *aa2< // if the last digit is 2...
        2+1  // set next digits to 1
        1&
      >     // else if the last digit is 1...
      2+1    // set next digits to 2
      a2+1   // ^^^
    >
  >
  a1+49 // move the current digit to its corresponding character
  %aa1  // print it
  1+1   // advance to the next digit
>

Interpreter