[Question]
  [
[Klein](https://github.com/Wheatwizard/Klein) is a 2D language I have designed that can be embedded on 12 different topological surfaces. A Klein program can be run on different surfaces by changing the command line arguments.
The topology determines where the instruction pointer goes when it goes off the edge of the program. When moving off of the edge the ip will jump to an edge with the matching color, and will maintain its position relative to the arrow, i.e. the pointer will conserve its distance from the arrow head.
For example topology `000`, the topology used by most 2D languages, causes the instruction pointer to wrap around to the other side when if moves off an edge.
# Task
The task is pretty simple, write a Klein program that when run will output the topology it is run in. The individual numbers may be separated by spaces. (e.g. `000` and `0 0 0` are both permissible output). You may choose to either use or ignore the `-A` command line flag it will not cost you bytes if you use it.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest answer will be the winner.
[Here](https://tio.run/##jY5BDoIwEEXXzCkmE3dGoCw1MXoCDgAmIBQhNJ1GuuH0tS0uWLhwFj8vr/MnfbbL6FzXWryiYbW@FNt0VhoGfqPFSSPleU4hRUgRWQQW0YvoRfQi@iL6Ivoi@sL7C/YMyTRghXTwTw9I7Cg1ym5kb@yZsDGrHVljxsZms5KT3jI169bZfzB0qIFEqkX@e@RXf5igZy2dIy6ZqlsNR9yGAOCLWO6YAP0u1e50/wA) is a online test driver that can be used to test all of the topologies at once. To run in integer mode remove the `-A`.
  
[Answer]
# ~~52~~ 48 bytes
```
./@$0<$
21\./01
..>..!\
@
.<..<\
20//\11
@01$00@
```
[Try it online!](https://tio.run/##BcGxDcAwCATA/reIRP08rpHFILQpokTZv8N373c//wy9TGlY0XQFyE1ejQKTzMaSe0egFCbVzEg6 "Klein – Try It Online")
[Test Driver](https://tio.run/##jc7BDoIwDAbgM32KunDu2h2VkL2HmIg6hLBsRHfh6RHGxYMHL3@ar/mb3tp3vyz3NmGNU/Tz08dEow/QxRcmHAIqZlZbypaSZ9lmyS7ZJbtkN9lNdpPdrH7CR4Ri6PCMqlxXFyhS7wK6ex9XSUeF12lOfQyo45T06N0Q9qRp3jvfD24ddYXC@bf798ivfjfAIwa3LKRtyVUJRhrSLEBUEx0asEAVUdWAYa0bEbAsJbP9AA "Bash – Try It Online")
## Explanation
In Klein the IP starts in the top left corner going right. The first step I wanted my program to do was to send the IP off the top of the program to determine the first and third bit. The IP would reenter the program as follows depending on the topology:
```
             ^
            I|P
            ./.....
201, 211 -->.......<-- 100, 110
            .......
            .......
            .......
200, 210 -->.......<-- 101, 111
            .......
             ^   ^
             |   |
            000 001
            010 011
```
I decided that the my program would record the third bit of the topology before the second bit but swap them (using `$`) before the end. To that end I added code to push the first and third bits of each topology at the IP's points of entry described above.
```
./.....
21...01
.......
.......
.......
20...11
.0...0.
```
Next I focused on the topologies with `1` or `2` as their first bit. I decided to recombine them and send them off on the side not connected to the north side so I could determine their second bit.
```
                      ./.....
                      21\./01
                      ..>....--> 200, 201, 210, 211
                      .......
100, 101, 110, 111 <--....<..
                      20/.\11
                      .0...0.
                        ^ ^
                        | |
                        / \
                      110 100
                      111 101
                      210 200
                      211 201
```
Conveniently this regrouped the topologies by their second bit so I could push that to the stack.
```
./.....
21\./01
..>....
.......
....<..
20/.\11
.01.00.
```
After that I just needed to swap the second and third bit and have the program terminate.
```
./.$...
21\./01
..>....
@......
....<..
20//\11
.01$00.
```
Now that the topologies with `1` or `2` as their first bit worked, I could focus on making the topologies with `0` give the correct output. The first step was recombining them so that they could be separated into two groups based on their second bit.
```
                      ./.$...
                      21\./01
                      ..>....<-- 010, 011
                      @......
000, 001, 010, 011 <--.<..<<.<-- 000, 001
                      20//\11
                      .01$00.
```
I first focused on those topologies with `1` as their second bit. These presented a challenge because for them the IP was on a line already used by the topologies with `2` as their first bit. Since it would be tricky to fit more than one instruction on that line (a single instruction can be jumped using the `!` instruction) and I was running low on space as a whole, I decided to redirect the IP off that line and reuse an existing `1` instruction to push the second bit.
```
./.$...
21\./01
..>..!\
@......
.<..<<.
20//\11
.01$00.
```
Now all that was left to do for the topologies with `1` as their second bit was to fix the order of the second and third bit and terminate.
```
       ^
       |
 ./.$..$
 21\./01
 ..>..!\
 @......
 .<..<<.
 20//\11
 @01$00@
 ^     ^
 |     |
011   010
```
Lastly remained the topologies with `0` as their second bit. There was not much space left in the program with the largest unused space being on the top line so it was there that I redirected the IP for the topologies with `0` as their second bit.
```
./.$.<$
21\./01
..>..!\
@......
.<..<\.
20//\11
@01$00@
```
I still needed to push `0` for the second bit and fix the order of the second and third bit as well as terminate the program. Fortunately, I was able to reuse an existing `$` instruction so the `0` and `@` instructions could fit in the remaining spaces.
```
./@$0<$
21\./01
..>..!\
@......
.<..<\.
20//\11
@01$00@
```
Finally the nops can be stripped from the ends of lines to get the final program.
[Answer]
# ~~116~~ ~~88~~ ~~86~~ ~~77~~ ~~69~~ ~~61~~ ~~60~~ ~~59~~ ~~58~~ ~~54~~ ~~53~~ 50 bytes
```
\2..@2
/1\<$00
/>!..>!
0//
@0$10@1
011\.<0
\.<@>1@
```
[Try it online!](https://tio.run/##jc@xDsIgEAbgufcUV9IZ7hjVNLyHNWlVahsJEMvSp68UFwcHlz@Xj/yX4zos07bdhoQtxuDWhwtJPp2HMbww4exREJHYk/fkMvM@c3EuzsW5uC6ui@viOvsR7wGqecQziiY/XaBKk/Vob1PIkg4C@7imKXhUISb1dHb2n5Rx/XS@D9w7oofKusX@u@RXf5zhHrzdtk5LaTQo7k4NEai2lrKtgZQCQw2TYcj/7uSJIIdp2bwB)
[Answer]
# ~~44 41 40 38~~ 37 bytes
```
\\1.>2
/0./
@./$(\
$>0!>
11$/10
[[email protected]](/cdn-cgi/l/email-protection)
```
[Try it online!](https://tio.run/##y85Jzcz7/z8mxlDPzohL30BPn8tBT19FI4ZLxc5A0Y7L0FBF39CAS0XPQc/w////BgYGAA "Klein – Try It Online")
[Test driver.](https://tio.run/##jc6xDoMgEAbg2XuKK2HoBBxjmxjfozbRKlZTAqSy@PRUcOnQocufy3f5L/fo1zmloY9YY/B2e1ofxcs6mPwbIy4OmVKK5aScVGbKMxWn4lSciuviurgurne/4uihWia8IeP76g5VnI1DM8x@l3hh2IUtzt6h9CHKlzWLO1KE7eh8P5g7rIPK2NX8e@RXf1pg9M6k1LYkag1SCQmNkPzcAq/VqQYiLkkBF42gDw "Bash – Try It Online")
Uses a 6 by 6 square. The shortest I could get with an 8 by 8 square is [38 bytes](https://tio.run/##jc4xDoMwDAXQGZ/CRBmYAs7YVoh7NJWgEAoiSlDJwulTEpYOHbp8Wc/6lp/dNoXQdx5rXJ3ZX8Z5sRgLo3ujx9kiq6qKxaSYlGaKMyWn5JScksvkMrlMLg@/4uAgm0e8I@PH6gGZn7RF3U/uEH9h2K67n5zF0q2@XIye7Zli3c/O94Oxw1rItNn0v0d@9ccZBmd1CKo5ni2AeN4ICaWqVMlvBQBvap7XoEjkivIP) if anyone wants to try improving it.
### Explanation:
One the first pass-through the code encodes the first two numbers for the prefixes `0` and `1`. For `2`, it encodes the third number then the first.
```
     201  200
     211  210
       |  |
       v  v
   -> \\1.>2
 IP<- /../..  <- 000, 001
      ...$..
      .>0...
      .1..10  <- 010, 011
      ....1.
       ^  ^
       |  |
     100  110
     101  111
```
Then we pass the IPs through the third edge to decide the final number. We combine the IPs with the same prefix.
```
     201  200
     211  210
       |  |
       v  v
   -> \\1.>2  -> 0,2 or 1,2
 IP<- /../..  <- 000, 001
      ...$..
      .>0!>.  -> 1
      .1./10  <- 010, 011
      ....1.
       ^ |^
       | v|
       | 0|
     100  110
     101  111
```
For the `0` and `1` prefixes, they both come out the top edge to decide the third number.
```
     201  200
     211  210
       |  |
       |10|
       vvvv
   -> \\1.>2  -> 2
 IP<- /0./..  <- 000, 001
      @./$..
      .>0!>.  -> 1
      .1./10  <- 010, 011
      ....1.
       ^ |^
       | v|
       | 0|
     100  110
     101  111
```
For the `2` prefix, the IPs come out the corners from the bottom edge.
```
     201  200
     211  210
       |  |
       |10|
       vvvv
   -> \\1.>2  -> 2
 IP<- /0./..  <- 000, 001
      @./$(\
      $>0!>.  -> 1
      11$/10  <- 010, 011
      [[email protected]](/cdn-cgi/l/email-protection).
      ^^ |^^
      || v||
      1| 0|0
     100  110
     101  111
```
Both edges swap the first and third number, push the second number and swaps it with the third to get the correct order.
]