$^//.{#}/S1//.$/
Попробуйте онлайн!
Формат ввода таков:
string
index
И программа 1-х проиндексирована.
объяснение
Carrot имеет несколько глобальных переменных, по одной для каждого типа: string, float и array (другие будут реализованы в ближайшее время). Программа запускается в строковом режиме, где все операторы влияют на глобальную строковую переменную. И я называю эти переменные «стеком».
(Пример входных данных: 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"]
Теперь это возвращает массив из одного элемента, содержащий строку длины один, но он отображается в виде строки на веб-сайте.
Если бы мы действительно хотели дать результат в виде строки, мы могли бы легко сделать это S","в конце, но это не имеет значения, потому что выходные данные на интерпретаторе все равно выглядят одинаково.