-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
Hello, World!^
The program starts in c^rrot mode where every character is pushed to the stack. The ^
at the end is to signify the end of c^rrot mode. The ^
can be removed in this case and still produce the same results. At the end of the program, the stack is printed implicitly.
#
In c^rrot mode, there are some special characters, like #
. The #
is always replaced with the input. Here in this example, the ^
at the end is removed since it is not necessary.
#^A +
note trailing space
First we set the stack to the input using #^
. Then we use A
to convert the stack mode to array (A
is the only operator that accepts an argument) and split on spaces. After that, we sum up all the elements by using +
. When in array mode and when a space
is given as argument to the +
operator, all the elements in the array are summed.
$^F+$
the input numbers are separated by a newline
$
in c^rrot mode pops the first value from the input array. See The Language#Input. After that, this value is converted to a number using F
. Then we add it with $
, the next value in the input array. The operator can be modified for other operations such as subtraction, addition, multiplication and division.
Note: an alternative at 1 more byte can be found in the earlier example. See Examples#Sum-of-all-inputs. However, this example can not only sum just 2 numbers, but any number of them.
*^*9^
^*9
The stack is set to *
. And then 9 more copies of this are appended to the result by *9
. This gives us the first row of the 10 by 10 grid of asterisks. Next we append a newline using ^\n^
(\n
represents the newline). Then we duplicate this again by 9 more times to get all 10 rows of the asterisks.