| Bytes | Lang | Time | Link |
|---|---|---|---|
| 012 | Raku Perl 6 rakudo | 250417T215207Z | xrs |
| 004 | Notepad | 200829T143729Z | Twilight |
| 011 | Javascript ES6? | 250329T085150Z | Steve Be |
| 040 | SAKO | 250329T073053Z | Acrimori |
| 008 | AWK | 250313T204614Z | xrs |
| 245 | INTERCAL | 190319T071158Z | Unrelate |
| 000 | Thunno 2 t | 230607T071841Z | The Thon |
| 012 | AArch64 machine code | 221028T175920Z | EasyasPi |
| 006 | ARM Thumb machine code | 221028T182840Z | EasyasPi |
| 010 | JavaScript Node.js | 221028T115048Z | 鳴神裁四点一号 |
| 057 | nroff | 221019T050741Z | 鳴神裁四点一号 |
| nan | Fig | 220929T172346Z | Seggan |
| 001 | Vyxal | 221010T131141Z | DialFros |
| 008 | Standard ML | 220929T161405Z | qwr |
| nan | 220929T154622Z | bigyihsu | |
| 002 | MAWP | 220929T152535Z | Dion |
| 011 | Brainfuck | 220929T115644Z | Joao-3 |
| 036 | M4 | 220929T055213Z | 鳴神裁四点一号 |
| 002 | MATL | 190317T210238Z | Suever |
| 011 | Factor | 220220T000847Z | chunes |
| 002 | J | 220219T213550Z | sinvec |
| 007 | APOL | 220216T134844Z | Ginger |
| 004 | Julia | 220216T125740Z | MarcMush |
| 048 | dotcomma | 201002T095957Z | Dorian |
| 003 | Duocentehexaquinquagesimal | 210416T174625Z | Makonede |
| 006 | vim | 210413T172112Z | Ray |
| nan | 190317T192114Z | Benjamin | |
| 002 | Regex | 210321T223715Z | emanresu |
| 046 | CSASM v2.2.1.1 | 210321T220906Z | absolute |
| 030 | Rockstar | 200924T142325Z | Shaggy |
| 001 | Pyth | 200929T015913Z | Scott |
| 008 | Labyrinth | 200929T005658Z | Bubbler |
| 013 | Marbelous | 200924T163840Z | jonatjan |
| 001 | 05AB1E | 200924T161037Z | Makonede |
| 002 | MathGolf | 200831T144056Z | Kevin Cr |
| 004 | Pip | 200831T020658Z | Razetime |
| 006 | Scala | 200829T150229Z | user |
| 002 | Arn | 200815T044629Z | ZippyMag |
| 010 | Rust | 200813T184314Z | Aiden4 |
| 014 | Flurry | 200813T101539Z | Bubbler |
| 002 | Integral | 200813T095745Z | user9649 |
| 002 | MAWP | 200813T091421Z | Razetime |
| 009 | Ruby pl | 200207T012025Z | Value In |
| 002 | Burlesque | 200207T011015Z | DeathInc |
| 003 | GolfScript | 200205T163037Z | Mathgeek |
| 002 | x8616 machine code | 190317T213037Z | 640KB |
| 002 | APL Dyalog Unicode | 200203T081341Z | Bubbler |
| 038 | naz | 200203T013346Z | sporebal |
| 001 | Pushy | 200114T153416Z | FlipTack |
| 003 | GolfScript | 200114T141040Z | user8505 |
| 639 | BrainFlakcr | 190926T134553Z | Dorian |
| 768 | Scratch 3.0 | 190928T084553Z | lyxal |
| 1514 | Caboose | 190928T041500Z | user8505 |
| 389 | Mornington Crescent | 190927T234422Z | Alevya |
| 007 | Perl 5 | 190926T192242Z | rpGYNay0 |
| 018 | MarioLANG | 190926T182023Z | Dorian |
| 024 | Clojure | 190927T042317Z | Lucky |
| 011 | Zsh | 190927T050519Z | roblogic |
| 023 | TSQL | 190926T184319Z | BradC |
| 009 | Cascade | 190925T192243Z | Edgex42 |
| 164 | Commodore 8bit BASIC CBM/PET | 190917T125846Z | Shaun Be |
| 010 | Triangular | 190917T125321Z | squid |
| 001 | Keg | 190915T142144Z | user8505 |
| 013 | Pepe | 190513T052736Z | u-ndefin |
| 034 | C | 190323T212119Z | qookie |
| 031 | C gcc | 190331T102358Z | Natural |
| 004 | Haskell | 190324T184201Z | univalen |
| 016 | Python 3 | 190322T140722Z | Nathan D |
| 008 | F# | 190318T234733Z | Ciaran_M |
| 011 | Seed | 190319T230828Z | kungfush |
| 004 | Haskell | 190317T200615Z | flawr |
| 008 | LiveScript | 190318T164737Z | Ven |
| 009 | Retina | 190319T004436Z | Sara J |
| 001 | Japt h | 190318T225912Z | Shaggy |
| 035 | R | 190318T203657Z | Chthonyx |
| 017 | Forth gforth | 190318T201038Z | reffu |
| 041 | Chip z | 190318T154036Z | Phlarx |
| 008 | C# 8.0 | 190318T161250Z | Arcanox |
| 017 | BinaryEncoded Golfical | 190318T145210Z | SuperJed |
| 005 | Runic Enchantments | 190318T144748Z | Draco18s |
| 001 | Japt h | 190318T135322Z | Oliver |
| 042 | Turing Machine Code | 190318T001748Z | SuperJed |
| 011 | IBM/Lotus Notes Formula | 190318T110932Z | ElPedro |
| 054 | Whitespace | 190318T111047Z | Kevin Cr |
| 010 | Excel | 190318T101909Z | Wernisch |
| nan | Python 3 | 190317T225429Z | Mrwerdo |
| 012 | VBA Excel | 190318T084212Z | remoel |
| 005 | Emotion | 190318T074921Z | Quantum6 |
| 004 | APL+WIN | 190318T053024Z | Graham |
| 013 | Bash | 190317T220202Z | brokenfo |
| 037 | Twig | 190318T024723Z | Ismael M |
| 010 | TIBASIC TI84 | 190317T204443Z | absolute |
| 001 | Japt | 190318T014817Z | dana |
| 011 | C# Visual C# Interactive Compiler | 190318T001400Z | dana |
| 005 | Befunge98 | 190318T005135Z | Jo King |
| 003 | Scratch 3.0 | 190318T004626Z | Silas Re |
| 024 | Batch | 190318T000411Z | Neil |
| 004 | Attache | 190318T001757Z | Conor O& |
| 011 | Perl 6 | 190317T234040Z | Jo King |
| 115 | C# .NET Core | 190317T233742Z | Stackstu |
| 081 | C# .NET Core | 190317T233448Z | Stackstu |
| 013 | PHP | 190317T233435Z | 640KB |
| 001 | Jelly | 190317T203047Z | Nick Ken |
| 391 | Turing Machine But Way Worse | 190317T222138Z | MilkyWay |
| 008 | Bash + coreutils | 190317T222011Z | pizzapan |
| 012 | Befunge93 | 190317T202148Z | JPeroute |
| 006 | Cubix | 190317T212052Z | MickyT |
| 001 | 05AB1E | 190317T211934Z | Emigna |
| 016 | SmileBASIC | 190317T211844Z | 12Me21 |
| 002 | ><> | 190317T211551Z | Emigna |
| 016 | Wolfram Language Mathematica | 190317T204651Z | shrap |
| 011 | PowerShell | 190317T202400Z | GMills |
| 014 | Javascript | 190317T193038Z | SuperJed |
| 014 | Python 3 | 190317T192900Z | MilkyWay |
| 007 | Brainf*** | 190317T192240Z | SuperJed |
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
Javascript (ES6?) 11 bytes
s=>s.at(-1)
SAKO, 40 bytes
PODPROGRAM:S(*T)
CALKOWITE:*T
LINIA
WROC
This is suprisingly trivial in SAKO, as last character in a string is always a newline.
Full programme version, 58 bytes
CALKOWITE:*T
BLOK(9):T
1)CZYTAJWIERSZ:T
LINIA
STOP1
KONIEC
Reads from STDIN and prints to STDOUT.
Without newline version, 83 bytes
PODPROGRAM:S(*T)
CALKOWITE:*T,I
I=0
1)I=I+1
GDYT(I)=58:2,INACZEJ1
2)S()=T(I-1)
WROC
This solution is returns second to last character.
AWK, 8 bytes
1,$0=$NF
1, # always print even if answer is zero
$0= # set default output
$NF # last field in line
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
Thunno 2 t, 0 bytes
That's right: no bytes. The t flag does all the work.
Or 1 byte flagless:
t
Built-in for last item.
AArch64 machine code, 12 bytes
20 8c c0 28 e3 ff ff 35 c0 03 5f d6
Commented assembly
.globl lastchar
// Input: x1: null terminated UTF-32 string
// Output: w0: last char in string
// char32_t lastchar(int dummy, const char32_t *str);
lastchar:
.Lloop:
// load two chars, advance by one char
// w0 = *x1++; w3 = *x1;
ldp w0, w3, [x1], #4
// loop if w3 was not zero (null terminator)
cbnz w3, .Lloop
// return
// result is in w0
ret
This can be called from C using a dummy parameter to put the null terminated UTF-32 string in x1.
char32_t lastchar(int dummy /* x0 */, const char32_t *ptr /* x1 */);
I don't usually do AArch64 because it isn't very compact at 4 bytes per instruction and almost always longer than Thumb, but this particular solution is really elegant even if it is larger than the equivalent Thumb code by 2 bytes (it's solely because of the return instruction being 2 bytes) (Thumb does better with ptr+length though)
ARM Thumb machine code, 6 bytes
01 39 40 5c 70 47
Commented assembly:
.syntax unified
.arch armv7-a
.thumb
.globl lastchar
.thumb_func
// C-callable function
// Input:
// - r0: String of ASCII (not utf-32)
// - r1: Length of string
// Output:
// - r0: Char
// int lastchar(const char *ptr, uint32_t length);
lastchar:
// It's literally ptr[length - 1]
// Subtract 1 from the length since ARM can't do [reg, reg, offset]
subs r1, #1
// load ptr[length]
ldrb r0, [r0, r1]
// return in r0
bx lr
I mean it is literally return ptr[length - 1], there isn't much to explain. The function is callable using the C convention, using byte string + length (not null-terminated UTF-32 like most of my solutions):
int lastchar(const char *ptr, uint32_t length);
ARM Thumb machine code, 10 bytes
This is the "equivalent Thumb code" I mentioned on my aarch64 answer. It is much less elegant.
01 c9 0b 68 00 2b fb d1 70 47
Commented assembly:
.syntax unified
.arch armv7-a
.thumb
.globl lastchar
.thumb_func
// C-callable function
// Input:
// - r1: Null terminated UTF-32LE string
// Output:
// - r0: Char
// char32_t lastchar(int dummy, const char32_t *str);
lastchar:
.Lloop:
// load 1 char, advance pointer
ldmia r1!, {r0}
// Load next char into temp
ldr r3, [r1]
// compare and loop if r3 wasn't a null terminator
cmp r3, #0
bne .Lloop
// return in r0
bx lr
This uses the same function signature, taking a null terminated UTF-32 string and a dummy parameter to put str in r1:
char32_t lastchar(int dummy /* r0 */, const char32_t *str /* r1 */);
In an ideal world, the direct equivalent could be done:
lastchar:
.Lloop:
ldrd r0, r3, [r1], #4
cbnz r3, .Lloop
bx lr
But unfortunately:
ldrdwill bus error if the pointer is not 8 byte aligned (even with unaligned access support), and advancing the pointer by 4 will end up unaligned.ldmiaalways advanced by4 * NumRegisterscbnzcan only branch forwards
JavaScript (Node.js), 10 bytes
Assumes every byte is a letter one of 0 through 9.
Is this justified?
s=>s%10+""
nroff, 57 bytes
.de F
.ds X \\$1
.length L \\*X
.substring X \\nL
\\*X
..
Usage
.F "41382239"
.F "e"
.F "what"
.F " a "
.F "b c"
How it works
.de F \" define macro F
.ds X \\$1 \" store 1st argument to string variable X
\" I had to do so because arguments are not in variable, but
\" can be obtained via requests only
.length L \\*X \" store length of X to register L
\" no numerical express to do so
.substring X \\nL \" 1-indexed. replace X with L-th to last substring
\\*X \" content of X
.. \" end of definition
Fig, \$1\log_{256}(96)\approx\$ 0.823 bytes
]
1-byters?? Seriously?? Why have that when you can have 0.823 bytes?? Literally "grab last char of (implicit) input."
Standard ML, 8 bytes
There are two common ways of string processing: char lists and strings. In both cases, the underlying char is an 8 bit value using "extended ASCII".
For char lists:
hd o rev
I'm not sure why List.last isn't top-level, but that works too.
For strings, convert to List and use explode:
hd o rev o explode
Brainfuck, 11 bytes
,>+[-,>+]<.
Explained:
,> [ ,> ] get input
+ - + sentinels
<. output last non-NUL byte (NUL doesn't count, doesn't it?)
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
APOL, 7 bytes
g(i -1)
About as simple as possible, just gets the last character of the input string.
dotcomma, 48 bytes
[[[],],][.[[[,.][.[,]].,][[,].[,]].]][,[,].[,.]]
Because dotcomma is queue-based, you can't easily access the last character. My solution is to reverse the input and then output the first character of it.
Code:
# reverse the input
[[[],],] mark the end with 0 0
[.[ while there are characters in input
[[,.] put a character on the recursion stack
[.[,]] go to reverse section
.,] save the character in the reverse section
[[,].[,]] go to input section
.]]
[ # get first character and delete all others
,[,] delete 0 and append the next character (last of input) to the end of the queue
.[,.] delete everything until we reach a 0
]
implicitly output the queue
dotcomma (experimental), 17 bytes
[,][[],][.[,.]].,
I marked this "experimental" because the language dotcomma is still very young and I don't know if this is intentional behaviour. If you pass input as a list of strings it reverses each string, so you only need to extract the first letter.
[,] put first character on recursion stack
[[],] put 0 (end of queue marker) on queue
[.[,.]] delete everything from queue
., write back character
vim, 6 bytes
VGJ$d^
Annotated
VGJ # join all lines
$ # move cursor to (before) last character
d^ # delete to beginning
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)
Regex, 2 bytes
.$
Matches character then end of string.
CSASM v2.2.1.1, 46 bytes
func main:
in ""
push ^1
push ^0
substr
print
ret
end
Commented:
func main:
; Get the input
in ""
; Get a substring of the input from (length - 1) to (length - 0)
push ^1
push ^0
substr
; Print it
print
ret
end
Rockstar, 30 bytes
listen to S
cut S
say S at S-1
Try it here (Code will need to be pasted in)
Or 51 bytes if we need to be able to handle newlines in the input:
listen to S
while S
listen to S
cut S
say S at S-1
Labyrinth, 8 bytes
,);.@
"(
,)(" Loop until EOF (-1): push a char input, increment, then decrement
;.@ On EOF, discard top, print the last char, and halt
Marbelous, 13 bytes
@0
00
]]..
@0
Marbelous is a language based on marble machines
@n(nfrom0toZ) is a portal which teleport the marble to another portal with the same value00-FFinitiate a marble with this value]]passing marble take value of next input byte if there is one, else the marble is diverted to the right..is a noop- marbles going out of the board to the bottom are implicitly outputed
05AB1E, 1 byte
θ
# (implicit) push STDIN to stack
θ # push last character of top of stack
# (implicit) output top of stack to STDOUT
MathGolf, 2 bytes
┤Þ
Or alternatively:
b§
Explanation:
┤ # Pop the left character of the (implicit) input-string loose to the stack
Þ # Only leave the top item of the stack, and discard everything else
# (implicitly output the entire stack joined together)
b # Push -1
§ # Get the -1'th character of the (implicit) input-string
# (0-based modulair similar as Python, so will index into the last character)
# (implicitly output the entire stack joined together)
Scala, 6 bytes
_.last
Not much to say here - it's just a function that takes a string (or really any iterable) and outputs its last element.
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
Flurry, 14 bytes
([]{(){}{}}{})
Run example
$ echo -n "?" | ./flurry -bnb -c "([]{(){}{}}{})"
?
$ echo -n "Hello world" | ./flurry -bnb -c "([]{(){}{}}{})"
d
-bnb flag means "print stack as chars, print nothing for return value, and take stdin as chars".
If the challenge were asking for "the last value from an integer array", I would use return value output and write 2 byte solution {} (pop the stack and return it). But since character I/O is required and the only way to output a char is via the stack, I had to manually empty the stack.
How it works
(
[] Stack height as Church numeral; Given 2 arguments `f` `x`,
a Church numeral `n` acts as "apply `f` `n` times to `x`"
{ Define f, with its argument pushed to the stack:
() K; Given two arguments, ignore the second
{} Pop; the argument
{} Pop; pop an extra item from the stack (ignored by K)
} End definition of f: Return its argument unchanged,
popping and discarding an item from the stack
{} Pop an item (last char)
At this point, the stack is empty and the value is the last char
) Push the result of the above
Ruby -pl, 9 bytes
Similar to the Perl solution, but chop doesn't return the last character in Ruby. (It instead returns the rest of the string without the last character.)
$_=$_[-1]
GolfScript, 3 bytes
Though there was already a Golfscript 3 byte solution, I figured I'd throw in the more general-purpose one.
)\;
Where ( is the front-uncon function (Golfscript treats strings as char arrays), \ swaps the string and char positions, and ; deletes the string, leaving only the last char.
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:
APL (Dyalog Unicode), 2 bytesSBCS
⊢/
The code taken literally means to "reduce by right argument function". It works like the following (basically like foldr1 (flip const) in Haskell):
⊢/ 'abcd'
→ 'a' ⊢ 'b' ⊢ 'c' ⊢ 'd'
→ 'a' ⊢ 'b' ⊢ 'd'
→ 'a' ⊢ 'd'
→ 'd'
This is an idiom for taking last element from a vector (or taking last element from each row of a multi-dimensional array).
naz, 38 bytes
2a2x1v1x1f1r3x1v2e2x2v1f0x1x2f2v1o0x1f
Works for any input string terminated with the control character STX (U+0002).
Explanation (with 0x commands removed)
2a2x1v # Set variable 1 equal to 2
1x1f1r3x1v2e2x2v1f # Function 1
# Read a byte of input
# Jump to function 2 if it equals variable 1
# Otherwise, store it in variable 2,
# then jump back to the start of the function
1x2f2v1o # Function 2
# Load variable 2 into the register and output it
1f # Call function 1
GolfScript, 3 bytes
The GolfScript = yields a decimal. That's pretty weird ... However, (luckily enough,) GolfScript supports slicing over a string, which allows me to slice the last item of the string.
-1>
Explanation
-1 # The last item
> # Choose everything in the string
# after the last item, including the last item
# this (obviously) yields the last item
Brain-Flak-cr, (6 bytes code + 3 bytes command line) = 9 bytes
({}<>)
Code:
The command line argument "-cr" means "use ASCII input and output" and "reverse the stack", so when you pop a value, the last byte of the input is popped, and when you push a value, it is pushed to the end.
{} pop a character
( ) and push it
<> on the other stack
implicitly output the current stack
Scratch 3.0, 7 blocks/68 bytes

or, as scratchblocks syntax
when gf clicked
ask()and wait
say(letter(length of(answer))of(answer
Did I mention this was done 100% on mobile? Because it was really hard making this, but I think it was worth it.
Caboose, 1514 bytes
Caboose hates me, because it does. There isn't any convenient string-indexing instruction in Caboose!
var a=input();print(a.endsWith(' ')and' 'or a.endsWith('!')and'!'or a.endsWith('"')and'"'or a.endsWith('#')and'#'or a.endsWith('$')and'$'or a.endsWith('%')and'%'or a.endsWith('&')and'&'or a.endsWith("'")and"'"or a.endsWith('(')and'('or a.endsWith(')')and')'or a.endsWith('*')and'*'or a.endsWith('+')and'+'or a.endsWith(',')and','or a.endsWith('-')and'-'or a.endsWith('.')and'.'or a.endsWith('/')and'/'or a.endsWith('0')and'0'or a.endsWith('1')and'1'or a.endsWith('2')and'2'or a.endsWith('3')and'3'or a.endsWith('4')and'4'or a.endsWith('5')and'5'or a.endsWith('6')and'6'or a.endsWith('7')and'7'or a.endsWith('8')and'8'or a.endsWith('9')and'9'or a.endsWith(':')and':'or a.endsWith(';')and';'or a.endsWith('<')and'<'or a.endsWith('=')and'='or a.endsWith('>')and'>'or a.endsWith('?')and'?'or a.endsWith('@')and'@'or a.endsWith('A')and'A'or a.endsWith('B')and'B'or a.endsWith('C')and'C'or a.endsWith('D')and'D'or a.endsWith('E')and'E'or a.endsWith('F')and'F'or a.endsWith('G')and'G'or a.endsWith('H')and'H'or a.endsWith('I')and'I'or a.endsWith('J')and'J'or a.endsWith('K')and'K'or a.endsWith('L')and'L'or a.endsWith('M')and'M'or a.endsWith('N')and'N'or a.endsWith('O')and'O'or a.endsWith('P')and'P'or a.endsWith('Q')and'Q'or a.endsWith('R')and'R'or a.endsWith('S')and'S'or a.endsWith('T')and'T'or a.endsWith('U')and'U'or a.endsWith('V')and'V'or a.endsWith('W')and'W'or a.endsWith('X')and'X'or a.endsWith('Y')and'Y'or a.endsWith('Z')and'Z'or a.endsWith('[')and'['or a.endsWith('\\')and'\\'or a.endsWith(']')and']'or'~');
If I add more constants, then Caboose will say that there are too many constants in the chunk. Fortunately it passes all test cases given. Basically it (tries to) check the last character against all characters in printable ASCII.
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.)
Perl 5, 7 bytes
$_=chop
This must be executed using the -pe flags.
Example
$ echo -n "abcd" | perl -pe '$_=chop'
d
Explanation
The -p flag wraps code inside a block that appears as:
while (<>) { ... ; print } whereas the '...' would include the code provided. The entire script would expand to:
while (<>) { $_ = chop ; print }
What I did here was set the context variable $_ to the return value of chop, which returns the last character of a string. Shortly after, print with no statements on its own will display the previously assigned context variable.
MarioLANG, 18 bytes
>,
"+
)[
!<(-
#==.
code:
> go right
, read input
+ increment it (because EOF = -1)
[ ignore the next command, if current cell = 0
< go to the left
! stop moving (Mario is now standing on the elevator (#),
which rides up to the elevator end (")
) go to the next memory cell
Mario is now at the starting position (>) and runs another round
until the end of input
else (if he ignored the "<" instruction)
( go one memory cell back (to the last inputted byte)
- decrement it, so it becomes the original value again
. print it
Clojure, 32 bytes 24 bytes
(print(last(read-line)))
(print ;; prints output
(last ;; get last character of input
(read-line))) ;; read input
T-SQL, 23 bytes
SELECT RIGHT(v,1)FROM i
Didn't see a SQL solution yet.
Input is via a pre-existing table \$i\$ with varchar field \$v\$, per our IO rules.
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.
Commodore 8-bit BASIC (CBM/PET, VIC-20, C64/TheC64Mini, C128, C16/+4) - byte count later
0inputa$:iflen(a$)thenprintright$(a$,1)
Simplified (without the sanity check):
0inputa$:?right$(a$,1)
There is a small limitation in that Commodore 8-bit BASIC the maximum length of a string is 255 characters, so any entry above that will cause an error.
Triangular, 10 bytes
(#~p../)?<
Pretty straight-forward; reads characters until it gets a null read, then prints the top of the stack.
Ungolfed:
(
# ~
p . .
/ ) ? <
--------------------------------------------
( Set a point to jump back to
~.< Read a character, change directions ("." is a no-op)
?)/ If ToS <= 0, skip next instruction and change directions; otherwise, jump back to "("
p# Pop the top value from the stack (the null input), then pop again and print that value
Keg, 1 byte
This is the exact thing that Keg was built for.
,
Explanation
# Push implicit string input
,# Output the last pushed character
# There is no implicit output since something was outputted
Pepe, 13 bytes
REEeREEEeReEe
Try it online! Disable "Separated by" check box below the input text box.
Explanation:
REEe # Input as string (stack R)
REEEe # Goto last char (stack R)
ReEe # Output char (stack R)
C, 36 35 34 bytes
x(char*v){printf(v+strlen(v)-1);}
Really simple stuff here. Nothing to ungolf either.
Saved one byte thanks to ceilingcat
Fixed the answer and saved another byte thanks to ASCII-only
Haskell, 4 bytes
last
Functions are allowed, right?
Also with IO (18 bytes):
main=interact$last
Python 3, 16 bytes
This is a pretty basic answer, but I think that it is the lowest Python 3 can go...
x=lambda a:a[-1]
F#, 14 8 bytes
Seq.last
-6 bytes thanks to aloisdg.
Strings are treated as sequences in F#, so you can use the Seq.last function to get the last character in it.
Seed, 11 bytes
5 370394306
The resulting Befunge-98 program ~2j@, was stolen borrowed from Jo King here, so credit to them for that.
LiveScript, 8 bytes
(.[*-1])
Explanation:
(.[*-1])
(.[*-1]) # "BIOP": operator section à la Haskell
.[ ] # Index into the implicit argument
*-1 # In [], "*" refers to the length
R, 35 bytes
Takes the input, splits it in to a list, outputs the last element of the list.
tail(strsplit(scan(,''),'')[[1]],1)
Forth (gforth), 17 bytes
: f 1- + 1 type ;
Explanation
Adds string-length - 1 to the string address and then prints a string of length 1 starting at that address.
Code Explanation
: f \ start a new word definition
1- \ subtract 1 from string length
+ \ add result to string address
1 type \ print string of length 1 starting at the new address
; \ end word definition
Chip -z, 41 bytes
S
>vvvvvv~t
ABCDEFG
|Zz||Zz
zbcZzfg
a de
Assumes that either the byte string does not contain zero (\0), or that it designates the end of the string.
Alternate solution (45 bytes):
azABZbczCDZdezEFZfgzG
S-^^----^^----^^----^~t
C# 8.0, 8 bytes
Requires .NET Core 3.0, which is in beta. This currently crashes the CLR due to a bug, but once the bug is fixed, this will run as expected and fulfill the challenge requirements.
s=>s[^1]
C# 8.0, Runs without crashing at time of writing, 22 bytes
s=>s.ToCharArray()[^1]
C# 8.0, Full Program, 78 bytes
using C=System.Console;class A{static void Main(){C.Write(C.ReadLine()[^1]);}}
Binary-Encoded Golfical, 17 bytes
Hex-dump of binary encoded file:
00 60 02 1b 1a 08 01 14
16 14 24 1d 0a 01 14 18
14
Original image:

Magnified 45x with colors labeled:

The original image (the tiny one, not the magnified version) can be run using the interpreter normally. The binary encoded file (of which a hexdump is included above) can either be transpiled back to the image version with the Encoder program included in the github repo, or run directly using the interpreter by adding the -x flag.
Runic Enchantments, 5 bytes
i1Z%@
Note that input handling in Runic has implicit conversion and breaks on spaces. \ denotes a literal space (works on newlines too) and numerical values are never strings.
Turing Machine Code, 72 42 bytes
Assumes an input with no empty cells (spaces). Thanks to ASCII-only for saving 30 bytes.
0 * * r 1
1 * * l 2
1 _ _ l halt
2 * _ r 0
Old version in 72 bytes:
0 * * r 0
0 _ * l 1
1 * * l 2
2 * _ l 2
2 _ _ r 3
3 _ _ r 3
3 * * * halt
IBM/Lotus Notes Formula, 11 bytes
@Right(i;1)
Computed field formula taking its input from editable field i
Whitespace, 54 bytes
[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate_0][T N
T S _Read_STDIN_as_character][T T T _Retrieve_input][S N
S _Duplicate][S S S T S T S N
_Push_10][T S S T _Subtract][N
T S S N
_If_0_Jump_to_Label_PRINT][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT][S N
N
_Discard_top][T N
S S _Print_as_character]
Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Since Whitespace can only take input as integer or character, we must add a trailing character to indicate we're done with the input-string after reading it character by character, for which I've used a newline.
Try it online (with raw spaces, tabs and new-lines only).
Example run: input = A2#
Command Explanation Stack Heap STDIN STDOUT STDERR
NSSN Create Label_LOOP []
SSSN Push 0 [0]
SNS Duplicate top (0) [0,0]
TNTS Read STDIN as character [0] {0:65} A
TTT Retrieve at heap address (0) [65] {0:65}
SNS Duplicate top (65) [65,65] {0:65}
SSSTSTSN Push 10 [65,65,10] {0:65}
TSST Subtract top two (65-10) [65,55] {0:65}
NTSSN If 0: Jump to Label_PRINT [65] {0:65}
NSNN Jump to Label_LOOP [65] {0:65}
SSSN Push 0 [65,0]
SNS Duplicate top (0) [65,0,0]
TNTS Read STDIN as character [65,0] {0:50} 2
TTT Retrieve at heap address (0) [65,50] {0:50}
SNS Duplicate top (50) [65,50,50] {0:50}
SSSTSTSN Push 10 [65,50,50,10] {0:50}
TSST Subtract top two (50-10) [65,50,40] {0:50}
NTSSN If 0: Jump to Label_PRINT [65,50] {0:50}
NSNN Jump to Label_LOOP [65,50] {0:50}
SSSN Push 0 [65,50,0]
SNS Duplicate top (0) [65,50,0,0]
TNTS Read STDIN as character [65,50,0] {0:35} #
TTT Retrieve at heap address (0) [65,50,35] {0:35}
SNS Duplicate top (35) [65,50,35,35] {0:35}
SSSTSTSN Push 10 [65,50,35,35,10] {0:35}
TSST Subtract top two (35-10) [65,50,35,25] {0:35}
NTSSN If 0: Jump to Label_PRINT [65,50,35] {0:35}
NSNN Jump to Label_LOOP [65,50,35] {0:35}
SSSN Push 0 [65,50,35,0]
SNS Duplicate top (0) [65,50,35,0,0]
TNTS Read STDIN as character [65,50,35,0] {0:10} \n
TTT Retrieve at heap address (0) [65,50,35,10] {0:10}
SNS Duplicate top (10) [65,50,35,10,10] {0:10}
SSSTSTSN Push 10 [65,50,35,10,10,10] {0:10}
TSST Subtract top two (10-10) [65,50,35,10,0] {0:10}
NTSSN If 0: Jump to Label_PRINT [65,50,35,10] {0:10}
NSSSN Create Label_PRINT [65,50,35,10] {0:10}
SNN Discard top [65,50,35] {0:10}
TNSS Print as character to STDOUT [65,50] {0:10} #
{0:10} error
Stops with the error: Exit not defined.
Excel, 10 bytes
Pretty much equivalent to @remoel's VBA answer:
=RIGHT(A1)
Python 3, 11 18 34 Bytes
import sys;print(sys.argv[-1][-1])
Usage via running the program as a python script on the command line. Input is provided as the last argument to the program.
VBA (Excel), 14 12 bytes
using Immediate Window and Cell A1 as input
Thanks @tsh
?[RIGHT(A1)] or ?Right([A1],1)
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.
APL+WIN, 4 bytes
¯1↑⎕
Prompt for input string and select last byte.
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)
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.
Befunge-98, 5 bytes
~2j@,
Explanation:
~ Take input
2j Skip next two instructions
~ Repeat until EOF, where it reflects
@, Print the last character and exit
Scratch 3.0, scratchblocks3 syntax
As a function, 61 bytes
define l
ask[]and wait
say(letter(length of(answer))of(answer
As a full program, 68 bytes
when gf clicked
ask[]and wait
say(letter(length of(answer))of(answer
Batch, 24 bytes
@set s=%1
@echo %s:~-1%
Takes input as a command-line argument. Note that arguments can't include special characters or spaces, but you can fake arguments with spaces in this case by preceding it with a ", which results in a single argument that begins with ", however there is no easy solution for arguments that include special characters. Batch can't easily read "all of stdin". To read up to but not including the first newline itself would however be a byte shorter:
@set/ps=
@echo %s:~-1%
Edit: A version that handles arbitrary characters in a (quoted) argument for 92 bytes:
@set s="%~1"
@set "s=%s:~-2,1%
@if "%s%"=="" (echo ^")else for %%s in ("%s%")do @echo %%~s
Explanation: The first line makes a copy of the argument in a variable and ensures that it is quoted. The second argument then takes the second last character (because the quote is now the last character). However, if that was also a quote then this results in an empty variable, so we need to special-case that and output a (quoted) quote. Otherwise, we still need to quote the character in case it is a special character as echoing "%s%" will echo the quotes and echoing %s% will actually interpret special characters, so the variable needs to be quoted to allow it to be parsed but then immediately unquoted so it can be printed. This is achieved using the for command. 86 bytes to read up to but not including the first newline from stdin while supporting special characters:
@set/ps=
@set "s=%s:~-1%
@if "%s%"=="" (echo ^")else for %%s in ("%s%")do @echo %%~s
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~>
Perl 6, 11 bytes
*.comb[*-1]
Anonymous Whatever lambda that takes a string, splits it into characters, and returns the last one.
C# (.NET Core), 115 bytes, console input
using C=System.Console;class M{static void Main(string[] a){int c=0,d;while((d=C.Read())>-1)c=d;C.Write((char)c);}}
This feels kinda janky, but it does work. Interestingly, I can't save any bytes with a for loop as the code stands.
C# (.NET Core), 81 bytes, command-line input
class M{static void Main(string[] a){System.Console.Write(a[0][a[0].Length-1]);}}
If you run this from an actual command line, you will need to wrap your string in quotes if it contains spaces.
PHP, 13 bytes
<?=$argn[-1];
Run with php -nF input is STDIN. Example:
$ echo 29845812674|php -nF lost.php
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.
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
Bash + coreutils, 8 bytes
tail -c1
Input is from stdin, output is to stdout.
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.
Cubix, 6 bytes
pA/@po
p
A / @ p
o
ATakes all the input/Redirect around the cubeppbring bottom of the stack to the top twiceo/@output as character, redirect and halt
SmileBASIC, 16 bytes
INPUT S$?POP(S$)
Javascript, 14 bytes
a=>a.slice(-1)
Brainf***, 7 bytes
,[>,]<.

