$^//.{#}/S1//.$/
Спробуйте в Інтернеті!
Формат введення є таким:
string
index
А програма 1-індексована.
Пояснення
Морква має кілька глобальних змінних, по одній для кожного типу: string, float та масив (інші мають бути реалізовані незабаром). Програма запускається в строковому режимі, де всі оператори впливатимуть на глобальну змінну рядків. І я називаю ці змінні "стеком".
(Приклад вхідних даних: 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","це наприкінці, але це не має значення, оскільки висновок все ще виглядає на інтерпретаторі.