$^//.{#}/S1//.$/
Pruébalo en línea!
El formato de entrada es como tal:
string
index
Y el programa está indexado en 1.
Explicación
Carrot tiene varias variables globales, una para cada tipo: string, float y array (otras se implementarán pronto). El programa comienza en modo cadena, donde todos los operadores afectarán la variable global de cadena. Y llamo a estas variables la "pila".
(Ejemplo de entrada: abcdef\n3)
$ Get the first line of the input and set the stack-string to this value
^ Exit caret-mode
stack-string = "abcdef"
/ Operator (behaves differently depending on the argument)
/.{#}/ And the argument to this operator is a regex, so this program gets the matches of this regex into the stack-array
. Any character
{#} Pops a line from the input. So now this evaluates to # of any character where # is the second line of the input (in this case, 3)
stack-array = ["abc"]
And now we just need to get the last character in this string, but first
S1 Join the array on the number 1 and set this to the stack-string. Because the array only contains one element, the number 1 does not appear in the stack-string.
stack-string = "abc"
/ Operator; because the argument is a regex, this retrieves the matches of the regex:
/.$/ Get the last character in the string
stack-array = ["c"]
Ahora esto devuelve una matriz de un elemento que contiene una cadena de longitud uno, pero se muestra como una cadena en el sitio web.
Si realmente quisiéramos dar el resultado como una cadena, podríamos hacerlo fácilmente S","al final, pero no importa porque la salida todavía se ve igual en el intérprete.