Sadako

From Esolang
Jump to navigation Jump to search

Sadako was inspired by origami folding and uses a paper square with side lengths of 1 as storage. Each line starts with | ​ and is numbered top to bottom, where the first line is line 0. Commands on the same line are separated by  : .

Commands

   A -> B | Fold point A towards the user to point B
   A => B | Fold point A away from the user to point B
        ~ | Undo last fold
= V A B L | If the distance between points A and B equals V, jump to line L
> V A B L | Same as = but greater than V
< V A B L | Same as = but less than V
        ? | Take 1 bit of input. If it equals 0, skip the next command
    ! A B | Multiply the distance between points A and B by 1000, truncate it, and print it as an ASCII character
    . A B | Print the distance between points A and B
        [ | Comment (goes to end of line)

Paper folding

Initially, the square is labelled with the points:

A       B
 .-----.
 |     |
 |     |
 |     |
 |     |
 |     |
 '-----'
C       D

Whenever a new fold is made, all unlabelled intersections of 2 or more lines or unlabelled corners get labelled with the next unused letter. They are labelled from the top, going right, then down. Any time a point is created, it can't be removed without getting rid of the paper. Once point Z is created, point names continue with AA, AB, AC... BA, etc.

Example:

| A -> C : ~

This program creates a paper and folds it in half vertically, then undoes the fold. This generates 2 new points, E and F.

A       B
 .-----.
 |     |
 |     |
E|     |F
 |     |
 |     |
 '-----'
C       D

Example program: Truth-machine

| ? : = 0 A A 2
| . A B : = 0 A A 1
| . A A