$^//.{#}/S1//.$/
Experimente online!
O formato de entrada é o seguinte:
string
index
E o programa é 1 indexado.
Explicação
O Carrot possui várias variáveis globais, uma para cada tipo: string, float e array (outras a serem implementadas em breve). O programa inicia no modo de sequência, onde todos os operadores afetam a variável de sequência global. E eu chamo essas variáveis de "pilha".
(Exemplo 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"]
Agora isso retorna uma matriz de um elemento contendo uma sequência de comprimento um, mas é mostrada como uma sequência no site.
Se realmente quiséssemos fornecer o resultado como uma string, poderíamos fazê-lo facilmente S","no final, mas isso não importa, porque a saída ainda parece a mesma no intérprete.