Pick
Pick is an esolang invented by User:None1. It is based on randomly picking stuff.
Data storage
Pick has a set of unbounded unsigned integers, and three unbounded unsigned accmulators A, B and C.
Initially, the set is empty, and the accumulators are zero.
C
C is a special accumulator that acts like a clock. After an instruction is executed, C is decremented by one, unless it is zero.
Commands
Commands and arguments are case-insensitive.
PICK
Pick a number evenly from the set, make A the value picked and remove it from the set.
If the set is empty, A is set to zero.
PUT
Put the value of A into the set, if the value of A already exists, nothing happens.
COPY
Copy the value of B to A.
INC
Increment B.
DEC
Decrement B.
COMP and LABEL
Unlike the commands above, COMP takes arguments:
COMP label label1
Compare A and B, if they're not equal, jump to label, otherwise label1.
LABEL takes an argument too:
LABEL x
Defines a label named x.
CLOCK and JMP
CLOCK takes an argument:
CLOCK x
Set the accumulator C to x.
JMP takes arguments too, but it can take one or two arguments:
JMP label label1
If the C is zero, jump to label, otherwise label1.
JMP label
Jump to label no matter what.
Optional commands
INP
Input B, whether as integer or ASCII depends on the implementation.
OUT
Output B, whether as integer or ASCII depends on the implementation.
Comments
Use #
for comments.
Examples
HI!
Needs optional commands.
INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC INC OUT INC OUT DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC DEC OUT
Cat program
Needs optional commands.
INP LABEL repeat OUT INP COMP repeat halt LABEL halt
Brute force search algorithm
This algorithm uses brute force to check for the presence of a number equal to the value of B in the set.
It is impossible to iterate over all the elements in the set. However, imagine you have a large pile of books. You want to find a book, but it is hard work to check them one by one. You just pick a book at random and check if it is the book you want. If it is, you have found the book (put it back so that the pile is not changed), otherwise you put it back and pick another one.
However, this process cannot go on forever. If you've picked too many books and can't find the book you want, just claim that it's not in the pile. Sometimes the claim might be wrong, but lots of trial and error will reduce this probability exponentially to almost zero, so we can ignore it.
In this algorithm we do the same thing: pick a value evenly, check if it is equal to the value of B, if it is, then the value of B is found. We choose a large number as a threshold (e.g.: 200000) and if the number of trials reaches the threshold, then we claim that it is not found.
CLOCK 1000000 # set threshold LABEL trial PICK # randomly pick a value PUT # put it back JMP notfound notyet # If you've tried too many times than claim that it is not found LABEL notyet COMP trial found # If it is not equal then try again LABEL found # Code that is done if it is found JMP end LABEL notfound # Code that is done if it is not found LABEL end
Computational class
Turing complete, as it can be translated from brainbool:
Everyone knows that a set is the same as a bool tape: If a number exists then the corresponding cell is 1, otherwise 0.
The accumulator B can be used as the pointer, so <
and >
can be translated to INC
and DEC
.
We can check the value of a cell using the brute force search algorithm above. Then [
and ]
can be implemented easily.
As for +
, its function is the same as this pseudocode:
if cell is not 0 then set cell to 0 otherwise set cell to 1 end
We already know how to check the value of a cell. To set a cell to 0, you just have to change the algorithm a little bit:
CLOCK 1000000 # set threshold COPY # copy so that we won't get other values into the set with put commands LABEL trial PUT # put it back PICK # randomly pick a value JMP notfound notyet # If you've tried too many times than claim that it is not found LABEL notyet COMP trial found # If it is not equal then try again LABEL found # Code that is done if it is found JMP end LABEL notfound # Code that is done if it is not found LABEL end
The changed algorithm doesn't put the value back if it is found, thus deletes the value.
To set a cell to 1, you can simply use COPY
and then PUT
.
As for ,
and .
, we don't need I/O to be Turing complete.