Challenge
You have one string of input bytes, output only the last byte in it.
Rules
Your submission may be a program or function outputting the last byte in the input which
- is either a string, stdin or command-line arguments, and
- is non-empty.
I was trying to solve this with brainfuck, however all languages are allowed to participate. This is code-golf.
Examples
"?" -> "?"
"29845812674" -> "4"
-
5\$\begingroup\$ Welcome, I changed your question to fit our format more properly (note this is what the sandbox is for, usually). However in its current state the challenge is very easy (also in bf), so not sure about that. \$\endgroup\$ბიმო– ბიმო2019年03月17日 19:11:34 +00:00Commented Mar 17, 2019 at 19:11
-
14\$\begingroup\$ I vote against closing; it may be trivial, but that doesn't make it offtopic \$\endgroup\$MilkyWay90– MilkyWay902019年03月17日 22:30:05 +00:00Commented Mar 17, 2019 at 22:30
-
10\$\begingroup\$ @ბიმო We have a consensus not to edit off-topic questions to make them on-topic which I think would have applied here. \$\endgroup\$Laikoni– Laikoni2019年03月18日 07:19:13 +00:00Commented Mar 18, 2019 at 7:19
-
2\$\begingroup\$ What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example? \$\endgroup\$kepe– kepe2019年03月18日 18:28:41 +00:00Commented Mar 18, 2019 at 18:28
-
2\$\begingroup\$ @FireCubez Yes, ASCII only \$\endgroup\$jean– jean2019年03月18日 18:42:55 +00:00Commented Mar 18, 2019 at 18:42
116 Answers 116
Attache, 4 bytes
Last
Try it online! (If the input could be a list of characters, &/S could work.)
Alternatives
5 bytes: `@&-1
8 bytes: &/S@List
10 bytes: `@«_,-1»
10 bytes: Fold!Right
10 bytes: `@<~_,-1~>
10 bytes: `^^&:Right
10 bytes: {Right^^_}
11 bytes: Get«_,-1»
11 bytes: Get<~_,-1~>
12 bytes: `@«_,#_-1»
12 bytes: `@<~_,#_-1~>
13 bytes: Get«_,#_-1»
13 bytes: Get<~_,#_-1~>
-
5\$\begingroup\$ :| wtf so many alternatives \$\endgroup\$ASCII-only– ASCII-only2019年03月18日 00:19:31 +00:00Commented Mar 18, 2019 at 0:19
-
2\$\begingroup\$ @ASCII-only Least I could do on a simple challenge like this :p \$\endgroup\$Conor O'Brien– Conor O'Brien2019年03月18日 00:41:40 +00:00Commented Mar 18, 2019 at 0:41
-
\$\begingroup\$ Print
Lastinputted byte. The programs contents fit with the challenge \$\endgroup\$MilkyWay90– MilkyWay902019年03月19日 23:53:53 +00:00Commented Mar 19, 2019 at 23:53
x86-16 machine code, 2 bytes
As @CodyGray correctly points out, taking input as a string and output to a register removes the bulk of the standalone program version.
Input string is in SI, length in CX and output character is in AL:
F3 AC REPZ LODSB ; start at memory location pointer in SI, put next value in AL,
; loop CX number of times. The last char will be in AL when done.
Or 4 bytes as a "Pascal string" (length is prepended to beginning of string):
AC LODSB ; first byte is string length
91 XCHG AX, CX ; move length to CX for loop
F3 AC REPZ LODSB ; start at memory location pointer in SI, put next value in AL,
; loop CX number of times. The last char will be in AL when done.
Or 5 bytes as a "C string" (zero/null terminated), input in DI:
F2 AE REPNZ SCASB ; scan for value in AL (0), end when found and advance DI
8A 45 FE MOV AL, [DI-2] ; DI is now two bytes ahead of last, put value of DI-2 into AL
x86-16 machine code, IBM PC DOS, (削除) 12 (削除ここまで) (削除) 11 (削除ここまで) 10 bytes
Or as complete program as IBM PC DOS executable. Input is from command line, output is to console.
B3 80 MOV BL, 80H ; BX to DOS PSP at 80H
8A 07 MOV AL, BYTE PTR[BX] ; get command line tail length
D7 XLAT ; AL = [BX+AL]
B4 0E MOV AH, 0EH ; PC BIOS write to screen function
CD 10 INT 10H ; display
C3 RET ; exit to DOS
Output:
-
\$\begingroup\$ Although this certainly gets style points, from a strict golfing point of view, it's worth noting that you are allowed to write functions that return the result in a register. So, this can get a lot shorter. You can trivially eliminate 4 bytes, and a rewrite could shrink it down even further. By the way, is that screenshot from an emulator? Which one? \$\endgroup\$Cody Gray– Cody Gray2019年03月19日 04:31:56 +00:00Commented Mar 19, 2019 at 4:31
-
\$\begingroup\$ @CodyGray, oh absolutely, the code to take input from command line and output to console is nearly all of it. Yeah, I could say "input string in
SI, length inCXoutput char is inAL" and then I think the only code that would be necessary isREPZ LODSB(2 bytes) and we'd be done. Of course this approach wouldn't be how you do it if you were coding for efficiency, not size. Your point is very well taken though, I'll post it also as a function that does the meat of the work. \$\endgroup\$640KB– 640KB2019年03月19日 15:04:20 +00:00Commented Mar 19, 2019 at 15:04
Brainf***, 7 bytes
,[>,]<.
-
\$\begingroup\$ ideone.com/XoJLD0 It still doesn't work ;( \$\endgroup\$jean– jean2019年03月17日 20:35:05 +00:00Commented Mar 17, 2019 at 20:35
-
\$\begingroup\$ @jean Try it here. (Honestly, I didn't even know ideone did BF). \$\endgroup\$SuperJedi224– SuperJedi2242019年03月17日 20:38:56 +00:00Commented Mar 17, 2019 at 20:38
-
\$\begingroup\$ Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;( \$\endgroup\$jean– jean2019年03月17日 20:45:26 +00:00Commented Mar 17, 2019 at 20:45
-
\$\begingroup\$ @jean ideone seems to use
-1as the EOF.+[>,+]<-.should work \$\endgroup\$Jo King– Jo King2019年03月17日 21:21:55 +00:00Commented Mar 17, 2019 at 21:21 -
\$\begingroup\$ @Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit? \$\endgroup\$jean– jean2019年03月17日 21:59:06 +00:00Commented Mar 17, 2019 at 21:59
INTERCAL, (削除) 270 (削除ここまで) (削除) 258 (削除ここまで) (削除) 247 (削除ここまで) (削除) 246 (削除ここまで) 245 bytes
DO,1<-#1PLEASECOMEFROM#2DOWRITEIN,1DO.1<-,1SUB#1DO.5<-#1$.1~#256DO.2<-.3DO(1)NEXTPLEASE.2<-!3~#15'$.3~#240PLEASE.2<-!2~#15'$.2~#240PLEASE.2<-!2~#15'$.2~#240DO(1010)NEXTDO,1SUB#1<-.3DOREADOUT,1(1)DO(1002)NEXTDO(1009)NEXTDO.3<-.3~#255(2)DOFORGET#1
-8 thanks to 鳴神裁四点一号 removing DOGIVEUP to terminate by NEXT stack explosion, opening up another -4 changing a PLEASE to DO.
-11 removing some grouping from the bit-reversing expression from hell. It seems that binary operators generally act right-associative in C-INTERCAL, though having no precedence among themselves.
-1 trying something else for bit reversal--definitely expected more savings than that! A more principled approach might be able to do it in two steps unless there's some obvious invariant I'm missing, but I'm too tired to take a stab at that just yet.
-1 thanks again to 鳴神裁四点一号, using a "computed" COME FROM where the computed label just so happens to be a constant. Looks like I wasn't reading enough tips!
Writing this was... interesting. I was thinking I might want to use INTERCAL to INTERCALate, but I'm a bit less sure now.
DO ,1<-#1 PLEASE NOTE We want the input array to only have space for one element, so it will only take one at a time
DO COME FROM (2)
DO WRITE IN ,1 PLEASE NOTE If this is the first byte of the input, it'll write its value... but if not, it'll write the
previous value minus its value mod 256.
DO .1<-,1SUB#1
DO .5<-#1$!1~#256' PLEASE NOTE .5 is 3 if the input is 256, 2 otherwise
DO .2<-.3
DO (1) NEXT
PLEASE NOTE If we're here, we've found the end of the input. Now, we need to print it back out... C-INTERCAL's
array I/O, in order to determine what it will actually print, subtracts the value it's going to print from the
previous one (still mod 256, and with the previous value defaulting to 0), and then reads the bits of the byte
backwards. So in order to go from the value we want to display to the value we need to feed into READ OUT, we
reverse the bits and then subtract from 256. Rather than select the bits out individually and mingle them all
in one expression, I mingle the back and front halves of the byte until it adds up to a reversal.
DO .2 <- !3~#15' $ !3~#240'
DO .2 <- !2~#15' $ !2~#240'
DO .2 <- !2~#15' $ !2~#240'
DO (1010) NEXT PLEASE NOTE .1 already has 256 in it, which is very convenient for when you need to subtract .2 from 256.
DO ,1SUB#1 <- .3 PLEASE NOTE If we just read .3 out, we'd get a Roman numeral instead of the correct output.
DO READ OUT ,1
DON'T GIVE UP PLEASE NOTE Logical end of program. However, if we don't gracefully terminate here, nothing more is output,
and the FORGET can't keep up with the NEXTs.
(1) DO (1002) NEXT PLEASE NOTE that that line in syslib does 1001 next, which pops .5 entries off the next-stack and returns
control flow to the last one, such that if .5 is 2 flow will come back here, but if it's 3 then it'll go back
to the line that nexted to this one.
Here we add .1 and .2 into .3, then truncate it to a byte before looping back (while managing the next-stack
responsibly so the program doesn't disappear into the black lagoon for any input over 79 (?) bytes)
DO (1009) NEXT
DO .3<-.3~#255
(2) DO FORGET #1
-
1\$\begingroup\$ DOGIVEUP can be removed to golf off 8 bytes because program halts by stack overflow and output is unchanged \$\endgroup\$IY5dVSjABEeV– IY5dVSjABEeV2022年10月28日 12:05:04 +00:00Commented Oct 28, 2022 at 12:05
-
1\$\begingroup\$ 245 bytes \$\endgroup\$IY5dVSjABEeV– IY5dVSjABEeV2025年03月12日 11:26:31 +00:00Commented Mar 12 at 11:26
MATL, 2 bytes
0)
MATL uses 1-based modular indexing so this solution grabs the element in the 0-th position of the input which is the same as the last since the 0 wraps around to the end.
Try it out at MATL Online
Explanation
% Implicitly grab the input
0 % Push the literal 0 to the stack
) % Use this zero to grab the character at the end of the string
% Implicitly display the result
-
\$\begingroup\$ I'd have gone for
J)... \$\endgroup\$Sanchises– Sanchises2019年03月18日 06:48:15 +00:00Commented Mar 18, 2019 at 6:48
-
\$\begingroup\$ I feel dumb, how are you calling this without declaring it to a variable? \$\endgroup\$Nathan Dimmer– Nathan Dimmer2019年03月22日 14:12:18 +00:00Commented Mar 22, 2019 at 14:12
-
\$\begingroup\$ I looked at your TIO, but it doesn’t make much sense... What are you doing in your header? \$\endgroup\$Nathan Dimmer– Nathan Dimmer2019年03月22日 14:14:53 +00:00Commented Mar 22, 2019 at 14:14
-
2\$\begingroup\$ @Bobawob For your first question, anonymous lambdas are allowed for answers (I call it using by assigning the lambda to the variable
ein the header). For your second question, the header ise=\, which basically meanse=lambda x:x[-1]\$\endgroup\$MilkyWay90– MilkyWay902019年03月22日 20:14:56 +00:00Commented Mar 22, 2019 at 20:14 -
\$\begingroup\$ Note that in my above comment, there is not supposed to be a trailing space in
e=\but Markdown escapes the code character so I have to add a trailing space \$\endgroup\$MilkyWay90– MilkyWay902019年03月22日 20:16:51 +00:00Commented Mar 22, 2019 at 20:16 -
\$\begingroup\$ That’s really cool! Thank you! \$\endgroup\$Nathan Dimmer– Nathan Dimmer2019年03月27日 14:03:23 +00:00Commented Mar 27, 2019 at 14:03
Javascript, 14 bytes
a=>a.slice(-1)
-
\$\begingroup\$ I tried my best to find a shorter way but to my surprise I don't think this can be improved, unless there is a funky way to reverse a string in under 8 bytes, before calling
[0]. Or maybe if there is a short way to get array length. Different approach:a=>[...a].pop()(15bytes) \$\endgroup\$Matsyir– Matsyir2019年09月26日 14:15:54 +00:00Commented Sep 26, 2019 at 14:15 -
\$\begingroup\$ @Matsyir
a=>/.$/.exec(a)also 15 \$\endgroup\$l4m2– l4m22021年04月13日 18:27:31 +00:00Commented Apr 13, 2021 at 18:27
Mornington Crescent, 389 Bytes
Even a task as simple as this presents an interesting optimisation challenge when riding the London Underground.
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take Central Line to Holborn
Take Piccadilly Line to Heathrow Terminals 1, 2, 3
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Parsons Green
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent
Visiting Mile End station allows you to take a substring from the end of the input - but to chop just 1 character, you need to generate the integer 1 somehow. Rather than doing any arithmetic, the fastest method turns out to be to parse it from the station name "Heathrow Terminals 1, 2, 3".
To bypass that, an alternate strategy for this challenge would be to reverse the input, read the character code for the now first byte, and then turn that back into a char to output - but this approach takes 12 bytes longer. (Although there are fewer trips needed, so the tickets would be cheaper.)
-
1\$\begingroup\$ Another alternative:
_\\$\endgroup\$user96495– user964952020年08月24日 03:01:47 +00:00Commented Aug 24, 2020 at 3:01 -
1\$\begingroup\$ +1 for a happy symbol \$\endgroup\$user– user2020年08月29日 15:04:16 +00:00Commented Aug 29, 2020 at 15:04
Java 11+
Input from STDIN, (削除) 71 (削除ここまで) 61 bytes
-10 bytes thanks to OlivierGrégoire
v->{var x=System.in;x.skip(x.available()-1);return x.read();}
Try it online!
Function Argument, 25 bytes
s->s.charAt(s.length()-1)
-
\$\begingroup\$ You could add the code for program argument to have all three options. :) Too bad OP specifically asks for Strings, otherwise
s->s[s.length-1]would have been enough with achar[]parameter-type. \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2019年03月18日 10:47:32 +00:00Commented Mar 18, 2019 at 10:47 -
\$\begingroup\$ 61 bytes. \$\endgroup\$Olivier Grégoire– Olivier Grégoire2019年03月19日 13:03:06 +00:00Commented Mar 19, 2019 at 13:03
-
\$\begingroup\$ @OlivierGrégoire just now seeing your answer 2 years later. Thanks. \$\endgroup\$Benjamin Urquhart– Benjamin Urquhart2021年04月13日 16:19:52 +00:00Commented Apr 13, 2021 at 16:19
Bash + coreutils, 8 bytes
tail -c1
Input is from stdin, output is to stdout.
Turing Machine But Way Worse, 391 bytes
1 0 1 1 0 0 0
0 0 0 1 1 0 0
1 1 1 1 0 0 0
0 1 0 1 2 0 0
1 2 1 1 0 0 0
0 2 0 1 3 0 0
1 3 1 1 0 0 0
0 3 0 1 4 0 0
1 4 1 1 0 0 0
0 4 0 1 5 0 0
1 5 1 1 0 0 0
0 5 0 1 6 0 0
1 6 1 1 0 0 0
0 6 0 1 7 0 0
1 7 1 1 0 0 0
0 7 0 1 8 0 0
1 8 1 1 0 0 0
0 8 0 0 9 0 0
0 9 0 0 a 0 0
0 a 0 0 b 0 0
0 b 0 0 c 0 0
0 c 0 0 d 0 0
0 d 0 0 e 0 0
0 e 0 0 f 0 0
0 f 0 0 h 0 0
0 h 0 0 g 0 0
0 g 0 0 0 1 1
1 g 1 0 0 1 1
EXPLANATION
Detect eight zero bits (which will occur at the end of the input, since TMBWW uses an infinite tape of bits.)
1 1 1 1 0 0 0
0 1 0 1 2 0 0
1 2 1 1 0 0 0
0 2 0 1 3 0 0
1 3 1 1 0 0 0
0 3 0 1 4 0 0
1 4 1 1 0 0 0
0 4 0 1 5 0 0
1 5 1 1 0 0 0
0 5 0 1 6 0 0
1 6 1 1 0 0 0
0 6 0 1 7 0 0
1 7 1 1 0 0 0
0 7 0 1 8 0 0
1 8 1 1 0 0 0
0 8 0 0 9 0 0
-------------
When eight 0 bits are detected, move back to the final byte of the input and print it out while halting the program.
0 9 0 0 a 0 0
0 a 0 0 b 0 0
0 b 0 0 c 0 0
0 c 0 0 d 0 0
0 d 0 0 e 0 0
0 e 0 0 f 0 0
0 f 0 0 h 0 0
0 h 0 0 g 0 0
0 g 0 0 0 1 1
1 g 1 0 0 1 1
TI-BASIC (TI-84), 10 bytes
sub(Ans,length(Ans),1
Gets the last character in the input string.
Input is in Ans.
Output is in Ans and is automatically printed out.
Excel, 10 bytes
Pretty much equivalent to @remoel's VBA answer:
=RIGHT(A1)
-
\$\begingroup\$ Why bother with
pure? Isn'tlastenough? \$\endgroup\$dfeuer– dfeuer2019年03月19日 07:22:34 +00:00Commented Mar 19, 2019 at 7:22 -
\$\begingroup\$ I assumed that the output must be a string too, but you're right, OP is only talking about "bytes". \$\endgroup\$flawr– flawr2019年03月19日 08:41:42 +00:00Commented Mar 19, 2019 at 8:41
Befunge-93, 12 (削除) 15 (削除ここまで) bytes
:1+_p1-,@>~#
Thanks to @Jo King for golfing off 3 bytes.
Alternate 15 byte version that is less messy:
~:1+#v!_
@,$<
Taking strings as input in Befunge isn't the easiest. If there were a single command to take in multiple characters, it would be as simple as reading the string, popping/printing the top character, and exiting.
-
\$\begingroup\$ Actually,
$$instead ofp1should work without the warning for the same amount of bytes \$\endgroup\$Jo King– Jo King2019年03月18日 00:46:22 +00:00Commented Mar 18, 2019 at 0:46
Jelly, 1 byte
Ṫ
Not the most difficult challenge in Jelly...
Note this accepts the input as a string; if the input could be interpreted otherwise (e.g. a number, a list), then it the argument will need to be quoted (e.g. "123456" or "[123,197]"). Alternatively this can be seen as a link that takes a byte array and returns the last member of that array, in accordance with PPCG standard rules.
Thanks to @MilkyWay90 and @ბიმო for pointing this out.
-
\$\begingroup\$ -1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA) \$\endgroup\$MilkyWay90– MilkyWay902019年03月17日 22:01:54 +00:00Commented Mar 17, 2019 at 22:01
-
\$\begingroup\$ @MilkyWay90: Doesn't need to be a full program, probably this will work as a Jelly function taking a string. But then again I don't know Jelly, so I might be wrong. \$\endgroup\$ბიმო– ბიმო2019年03月17日 22:16:07 +00:00Commented Mar 17, 2019 at 22:16
-
\$\begingroup\$ Okay, I'll try seeing whether or not it will work as a link \$\endgroup\$MilkyWay90– MilkyWay902019年03月17日 22:16:53 +00:00Commented Mar 17, 2019 at 22:16
-
\$\begingroup\$ @ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?) \$\endgroup\$MilkyWay90– MilkyWay902019年03月17日 22:17:48 +00:00Commented Mar 17, 2019 at 22:17
-
\$\begingroup\$ You can just define the T as a link and make it input a string, removing the need for "" in your input. \$\endgroup\$MilkyWay90– MilkyWay902019年03月18日 23:00:06 +00:00Commented Mar 18, 2019 at 23:00
APL+WIN, 4 bytes
̄1↑⎕
Prompt for input string and select last byte.
-
1\$\begingroup\$ 3 byte solution ⊃⌽⍞ \$\endgroup\$rak1507– rak15072020年10月02日 13:01:47 +00:00Commented Oct 2, 2020 at 13:01
Emotion, 5 bytes
😶👉😃😨👿
Explanation
😶 Push a copy of the first stack value.
👉 Push the length of the first stack value interpreted as a string.
😃 Push literal 1
😨 Push the difference of the second and first stack values.
👿 Push the character of the second stack value at the index of the top stack value.
-
\$\begingroup\$ in your readme, 1. i think "to emoji" should be "from emoji" 2. if it should be "from emoji" then emotinomicon and emojicode are a thing already \$\endgroup\$ASCII-only– ASCII-only2019年03月18日 10:24:44 +00:00Commented Mar 18, 2019 at 10:24
-
\$\begingroup\$ Actually what you're looking at is output from a compiler, which can also be accessed via the online interface. \$\endgroup\$Quantum64– Quantum642019年03月18日 14:45:07 +00:00Commented Mar 18, 2019 at 14:45
-
\$\begingroup\$ Isn't each emoji more than one byte? I'd think they'd be two bytes at least. \$\endgroup\$Kyle Delaney– Kyle Delaney2019年03月18日 20:18:03 +00:00Commented Mar 18, 2019 at 20:18
-
\$\begingroup\$ Emotion uses a custom code page. See quantum64.github.io/EmotionBuilds/1.1.0//… \$\endgroup\$JPeroutek– JPeroutek2019年03月18日 20:53:47 +00:00Commented Mar 18, 2019 at 20:53
Cascade, 9 bytes
?a|,
;.]^
Pretty happy with this, as it is only 3 bytes longer than my cat program
Expanded
?
^;.
| |a
] |
a ,|
This essentially just loops through pushing input characters into the a stack until EOF is reached. Then it outputs the item at the top of the a stack using .a.
Rust, (削除) 25 (削除ここまで) (削除) 16 (削除ここまで) 10 bytes
|s|s.pop()
Try it on the Rust Playground!
An anonymous function that takes in a mutable String and outputs the char at the end of the string. Minus a lot of bytes, thanks to madlaina
-
\$\begingroup\$ The
.unwrap()call isn't necessary as per this meta post. Also, if you use the closure in a function that requires a specific signature, the compiler can do a better job at type deduction and you can leave the:Stringout: example \$\endgroup\$madlaina– madlaina2020年08月14日 15:25:10 +00:00Commented Aug 14, 2020 at 15:25 -
\$\begingroup\$ @madlaina thanks, I was testing with let bindings, and I had to be explicit there. \$\endgroup\$Aiden4– Aiden42020年08月14日 20:15:39 +00:00Commented Aug 14, 2020 at 20:15
Notepad, (削除) 9 (削除ここまで) (削除) 5 (削除ここまで) 4 keystrokes
Assuming the cursor is at the end of the file.
[LeftArrow][Shift-Home][Backspace]
I know it is not a language, but I'm posting just for fun.
-1 by Steve Bennett
-
\$\begingroup\$ The input is one line, according to the challenge specs. -6 keystrokes:
[LeftArrow][Ctrl-Backspace]\$\endgroup\$user96495– user964952020年09月07日 10:11:31 +00:00Commented Sep 7, 2020 at 10:11 -
\$\begingroup\$ @hi. Doesn't work on my notepad. Ctrl-Backspace just adds an unprintable character, which I suspect is
\x7f. \$\endgroup\$TwilightSparkle– TwilightSparkle2020年09月07日 13:10:48 +00:00Commented Sep 7, 2020 at 13:10 -
\$\begingroup\$ @hi. I don't see anything in the specs about it only being one line of input \$\endgroup\$Jo King– Jo King2020年09月07日 14:00:28 +00:00Commented Sep 7, 2020 at 14:00
-
1\$\begingroup\$ I guess it depends on the platform, but wouldn't you do [LeftArrow] [Shift-Home] [Backspace]? 4 keystrokes. \$\endgroup\$Steve Bennett– Steve Bennett2025年03月29日 10:18:17 +00:00Commented Mar 29 at 10:18
-
\$\begingroup\$ @SteveBennett Indeed, apparently I've forgotten the Home key at that time. \$\endgroup\$TwilightSparkle– TwilightSparkle2025年03月29日 14:45:52 +00:00Commented Mar 29 at 14:45
SmileBASIC, 16 bytes
INPUT S$?POP(S$)
Twig, 37 bytes
This just uses a simple "extract 1 char from the end and print it" aproach.
{%macro a(a)%}{{a[-1:1]}}{%endmacro%}
It was really easy to do, and test, but was fun!
To use it, you have to put it on a .twig file and import it:
{% import 'a.twig' as a %}
{{ a.a("string") }} {# should display "g" #}
You can test it on https://twigfiddle.com/aa19wd (testcases included)
-
\$\begingroup\$ Ok, that's the first time I see a Twig golf. \$\endgroup\$Ven– Ven2019年03月18日 16:49:23 +00:00Commented Mar 18, 2019 at 16:49
-
\$\begingroup\$ @Ven I've been doing it for quite a while. Here's an example: codegolf.stackexchange.com/a/174040 and here's another one: codegolf.stackexchange.com/a/166800 (I have a few more, but well) \$\endgroup\$Ismael Miguel– Ismael Miguel2019年03月18日 16:59:38 +00:00Commented Mar 18, 2019 at 16:59