!?:[*l+].
オンラインでお試しください!
説明:
まず、タートルリードはグリッドベースであり、タートルの事柄があります。カメが左、上、下、右に移動できるグリッドセルがあり、グリッドセルに物事を書き込むことができます。
[the first grid cell the turtle starts on is marked with a *]
! input the string into the string variable
? input the number into the number variable
: this command takes the number variable and moves right that many.
hence this moves right by the amount inputted
[* ] this is an `until` loop. the * there means that `until` the turtle ends the loop
on a grid cell with * written on it (that is, the first cell), it will execute
the code inside again and again
l+ the code inside the while loop. the `l` moves the turtle left, and the +
increments the string pointer. the string pointer is used with the string var;
when you want to write something from the string, you use `.`, which writes
the pointed char. the pointed char is the n-th character of the string, n being
the value of the string pointer. this code will execute until the l moves
the turtle back on to the origin cell. since we moved right by the number
inputted, this will increase the string pointer (which starts at 1)
by the amount inputted.
. write the pointed char, which was dealt with in the previous comment.
if 0 is inputted, turtle stayed on the origin square, and executed none
of the loop, and turtle writes the first char of string input.
if 1 is inputted, turtle moved one right, moved one left and incremented
string pointer once, which means the second char is written. and so on.
[the char of input has been written over the origin square]
[implicitly the grid is outputted, which has spaces and blank lines taken out]
[this is the requested char outputted, plus an unavoidable trailing newline
due to how I made the interpreter. sue me]