গাজর , 16 বাইট
$^//.{#}/S1//.$/
এটি অনলাইন চেষ্টা করুন!
ইনপুট ফর্ম্যাটটি হ'ল:
string
index
এবং প্রোগ্রামটি 1-সূচকযুক্ত।
ব্যাখ্যা
গাজরের বেশ কয়েকটি বৈশ্বিক পরিবর্তনশীল রয়েছে, প্রতিটি প্রকারের জন্য একটি: স্ট্রিং, ফ্লোট এবং অ্যারে (অন্যরা শীঘ্রই প্রয়োগ করা হবে)। প্রোগ্রামটি স্ট্রিং-মোডে শুরু হয়, যেখানে সমস্ত অপারেটর গ্লোবাল স্ট্রিং ভেরিয়েবলকে প্রভাবিত করবে। এবং আমি এই ভেরিয়েবলগুলিকে "স্ট্যাক" বলি।
(উদাহরণ ইনপুট 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","শেষে করতে পারতাম , তবে এটি কোনও ব্যাপার নয় কারণ আউটপুট এখনও দোভাষীটিতে একই দেখাচ্ছে।