Print last inputted byte
$begingroup$
Challenge
You have one string of input bytes, output 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"
code-golf string
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
|
show 1 more comment
$begingroup$
Challenge
You have one string of input bytes, output 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"
code-golf string
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
4
$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$
– ბიმო
2 days ago
10
$begingroup$
I vote against closing; it may be trivial, but that doesn't make it offtopic
$endgroup$
– MilkyWay90
yesterday
1
$begingroup$
@MillyWay I think most of the close votes were before the extensive edit by ბიმო
$endgroup$
– Sanchises
yesterday
9
$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
yesterday
2
$begingroup$
What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example?
$endgroup$
– FireCubez
yesterday
|
show 1 more comment
$begingroup$
Challenge
You have one string of input bytes, output 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"
code-golf string
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
Challenge
You have one string of input bytes, output 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"
code-golf string
code-golf string
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
SuperJedi224
9,86013363
9,86013363
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
jeanjean
643
643
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
$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$
– ბიმო
2 days ago
10
$begingroup$
I vote against closing; it may be trivial, but that doesn't make it offtopic
$endgroup$
– MilkyWay90
yesterday
1
$begingroup$
@MillyWay I think most of the close votes were before the extensive edit by ბიმო
$endgroup$
– Sanchises
yesterday
9
$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
yesterday
2
$begingroup$
What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example?
$endgroup$
– FireCubez
yesterday
|
show 1 more comment
4
$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$
– ბიმო
2 days ago
10
$begingroup$
I vote against closing; it may be trivial, but that doesn't make it offtopic
$endgroup$
– MilkyWay90
yesterday
1
$begingroup$
@MillyWay I think most of the close votes were before the extensive edit by ბიმო
$endgroup$
– Sanchises
yesterday
9
$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
yesterday
2
$begingroup$
What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example?
$endgroup$
– FireCubez
yesterday
4
4
$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$
– ბიმო
2 days ago
$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$
– ბიმო
2 days ago
10
10
$begingroup$
I vote against closing; it may be trivial, but that doesn't make it offtopic
$endgroup$
– MilkyWay90
yesterday
$begingroup$
I vote against closing; it may be trivial, but that doesn't make it offtopic
$endgroup$
– MilkyWay90
yesterday
1
1
$begingroup$
@MillyWay I think most of the close votes were before the extensive edit by ბიმო
$endgroup$
– Sanchises
yesterday
$begingroup$
@MillyWay I think most of the close votes were before the extensive edit by ბიმო
$endgroup$
– Sanchises
yesterday
9
9
$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
yesterday
$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
yesterday
2
2
$begingroup$
What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example?
$endgroup$
– FireCubez
yesterday
$begingroup$
What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example?
$endgroup$
– FireCubez
yesterday
|
show 1 more comment
50 Answers
50
active
oldest
votes
1 2
next
$begingroup$
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~>
$endgroup$
4
$begingroup$
:| wtf so many alternatives
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
@ASCII-only Least I could do on a simple challenge like this :p
$endgroup$
– Conor O'Brien
yesterday
add a comment |
$begingroup$
Brainf***, 7 bytes
,[>,]<.
$endgroup$
$begingroup$
ideone.com/XoJLD0 It still doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean Try it here. (Honestly, I didn't even know ideone did BF).
$endgroup$
– SuperJedi224
2 days ago
$begingroup$
Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean ideone seems to use-1as the EOF.+[>,+]<-.should work
$endgroup$
– Jo King
yesterday
$begingroup$
@Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit?
$endgroup$
– jean
yesterday
|
show 3 more comments
$begingroup$
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
$endgroup$
$begingroup$
I'd have gone forJ)...
$endgroup$
– Sanchises
yesterday
add a comment |
$begingroup$
x86 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
IBM PC DOS, 8088 Assembly, 12 11 bytes
Or as complete program as IBM PC DOS executable. Input is from command line, output is to console.
D1 EE SHR SI, 1 ; SI to DOS PSP at 80H (SI is 0100H at runtime)
AC LODSB ; load command line length in AL
91 XCHG AX, CX ; move length to CX for loop
F3/ AC REPZ LODSB ; load next char into AL, repeat until CX = 0
B4 0E MOV AH, 0EH ; PC BIOS write to screen function
CD 10 INT 10H ; display
C3 RET ; exit to DOS
Output:

Download LAST.COM DOS executable (11 bytes)
$endgroup$
$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
16 hours ago
$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 inSI, 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$
– gwaugh
6 hours ago
$begingroup$
@CodyGray the screenshot is using PCE, which is what I primarily use for testing since it uses the actual PC BIOS ROMs and actual DOS. I build on MASM 1.1 on DOS 2.0. :)
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
Javascript, 14 bytes
a=>a.slice(-1)
$endgroup$
add a comment |
$begingroup$
Bash + coreutils, 8 bytes
tail -c1
Input is from stdin, output is to stdout.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
Haskell, 9 4 bytes
last
Try it online!
$endgroup$
$begingroup$
Why bother withpure? Isn'tlastenough?
$endgroup$
– dfeuer
13 hours ago
$begingroup$
I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".
$endgroup$
– flawr
12 hours ago
add a comment |
$begingroup$
Java 8
Input from STDIN, 71 bytes
v->{int i=0;for(;System.in.available()>0;i=System.in.read());return i;}
Try it online!
Function Argument, 25 bytes
s->s.charAt(s.length()-1)
$endgroup$
$begingroup$
You could add the code for program argument to have all three options. :) Too bad OP specifically asks for Strings, otherwises->s[s.length-1]would have been enough with acharparameter-type.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
61 bytes.
$endgroup$
– Olivier Grégoire
8 hours ago
add a comment |
$begingroup$
><>, 2 bytes
Using command line args
o;
Try it online!
><>, 11 bytes
Using stdin
~o;
/?(0:i
Try it online!
$endgroup$
add a comment |
$begingroup$
Cubix, 6 bytes
pA/@po
Try it online!
p
A / @ p
o
Watch it run
ATakes all the input
/Redirect around the cube
ppbring bottom of the stack to the top twice
o/@output as character, redirect and halt
$endgroup$
add a comment |
$begingroup$
Befunge-93, 12 15 bytes
:1+_p1-,@>~#
Try it online!
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.
$endgroup$
$begingroup$
Actually,$$instead ofp1should work without the warning for the same amount of bytes
$endgroup$
– Jo King
yesterday
add a comment |
$begingroup$
Jelly, 1 byte
Ṫ
Try it online!
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.
$endgroup$
$begingroup$
-1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)
$endgroup$
– MilkyWay90
yesterday
$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$
– ბიმო
yesterday
$begingroup$
Okay, I'll try seeing whether or not it will work as a link
$endgroup$
– MilkyWay90
yesterday
$begingroup$
@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)
$endgroup$
– MilkyWay90
yesterday
$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
22 hours ago
add a comment |
$begingroup$
PHP, 13 bytes
<?=$argn[-1];
Try it online!
Run with php -nF input is STDIN. Example:
$ echo 29845812674|php -nF lost.php
$endgroup$
add a comment |
$begingroup$
Python 3, 14 bytes
lambda x:x[-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 11 bytes
"$args"[-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 1 byte
¤
Try it online!
θ or ` would also work.
$endgroup$
add a comment |
$begingroup$
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)
$endgroup$
$begingroup$
Ok, that's the first time I see a Twig golf.
$endgroup$
– Ven
yesterday
$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
yesterday
add a comment |
$begingroup$
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.
Try it online!
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.
$endgroup$
– Stephen
yesterday
$begingroup$
Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.
$endgroup$
– Mrwerdo
yesterday
$begingroup$
This won't handle a newline in the input
$endgroup$
– Jo King
yesterday
1
$begingroup$
14
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
How about this?
$endgroup$
– Mrwerdo
yesterday
|
show 3 more comments
$begingroup$
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]);}}
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
The challenge mentions "output", so the last solution is probably the right one
$endgroup$
– Ven
yesterday
$begingroup$
Dang, you outdid my console answer by a lot. How does the ^1 work?
$endgroup$
– Stackstuck
yesterday
$begingroup$
It's the new Index type. Starting an index with a caret indicates it's from the end, i.e.array[^n]is the same asarray[array.Length - n]
$endgroup$
– briman0094
yesterday
$begingroup$
Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?
$endgroup$
– mortb
12 hours ago
1
$begingroup$
Found it: docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
$endgroup$
– mortb
12 hours ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 16 bytes
#~StringTake~-1&
Try it online!
$endgroup$
add a comment |
$begingroup$
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
Try it online!
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
$endgroup$
add a comment |
$begingroup$
Befunge-98, 5 bytes
~2j@,
Try it online!
Explanation:
~ Take input
2j Skip next two instructions
~ Repeat until EOF, where it reflects
@, Print the last character and exit
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 11 bytes
x=>x.Last()
Try it online!
$endgroup$
$begingroup$
you can use a function :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
OK - Ill update my answer :)
$endgroup$
– dana
yesterday
1
$begingroup$
uhm why is testcase in STDIN not footer
$endgroup$
– ASCII-only
yesterday
$begingroup$
Wow - It's been a while. Thanks for pointing that out ;)
$endgroup$
– dana
yesterday
1
$begingroup$
That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.
$endgroup$
– Ven
yesterday
|
show 3 more comments
$begingroup$
Japt, 1 byte
Ì
Try it online!
-1 byte thanks to Quintec!
$endgroup$
1
$begingroup$
1 byte
$endgroup$
– Quintec
yesterday
add a comment |
$begingroup$
APL+WIN, 4 bytes
¯1↑⎕
Prompt for input string and select last byte.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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
Try it online.
$endgroup$
1
$begingroup$
0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?
$endgroup$
– ASCII-only
yesterday
$begingroup$
oi pls reply :||
$endgroup$
– ASCII-only
yesterday
$begingroup$
wouldn't work in what way? I've tested it online
$endgroup$
– ASCII-only
yesterday
$begingroup$
@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.
$endgroup$
– SuperJedi224
yesterday
$begingroup$
Well, this is a simple challenge, don't think it needs more than one answer in any language :P
$endgroup$
– ASCII-only
yesterday
|
show 1 more comment
$begingroup$
R, 35 bytes
Takes the input, splits it in to a list, outputs the last element of the list.
tail(strsplit(scan(,''),'')[[1]],1)
Try it online!
$endgroup$
add a comment |
$begingroup$
INTERCAL, 270 bytes
DO,1<-#1PLEASECOMEFROM(2)DOWRITEIN,1DO.1<-,1SUB#1DO.5<-#1$!1~#256'DO.2<-.3DO(1)NEXTPLEASE.2<-'"!3~#1'$!3~#16'"$"!3~#4'$!3~#64'"'$'"!3~#2'$!3~#32'"$"!3~#8'$!3~#128'"'DO(1010)NEXTPLEASE,1SUB#1<-.3PLEASEREADOUT,1DOGIVEUP(1)DO(1002)NEXTDO(1009)NEXTDO.3<-.3~#255(2)DOFORGET#1
Try it online!
Writing this was... interesting. I was thinking I might want to use INTERCAL to INTERCALate, but I'm a bit less sure now.
Ungolfed and commented:
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. The nightmarish expression on the following line reverses the
bits the best way I could think to: individually select each one out and then mingle them all back
together. It may be possible to emulate the method used in cesspool.c, by using mingle and unary AND as a
substitute for binary AND where we can't afford for select to rearrange it, but it might end up longer...
DO .2 <- '"'.3~#1'$'.3~#16'"$"'.3~#4'$'.3~#64'"'$'"'.3~#2'$'.3~#32'"$"'.3~#8'$'.3~#128'"'
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
DO GIVE UP PLEASE NOTE End of program.
(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
$endgroup$
add a comment |
1 2
next
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
jean is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181627%2fprint-last-inputted-byte%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
50 Answers
50
active
oldest
votes
50 Answers
50
active
oldest
votes
active
oldest
votes
active
oldest
votes
1 2
next
$begingroup$
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~>
$endgroup$
4
$begingroup$
:| wtf so many alternatives
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
@ASCII-only Least I could do on a simple challenge like this :p
$endgroup$
– Conor O'Brien
yesterday
add a comment |
$begingroup$
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~>
$endgroup$
4
$begingroup$
:| wtf so many alternatives
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
@ASCII-only Least I could do on a simple challenge like this :p
$endgroup$
– Conor O'Brien
yesterday
add a comment |
$begingroup$
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~>
$endgroup$
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~>
answered yesterday
Conor O'BrienConor O'Brien
30.4k264162
30.4k264162
4
$begingroup$
:| wtf so many alternatives
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
@ASCII-only Least I could do on a simple challenge like this :p
$endgroup$
– Conor O'Brien
yesterday
add a comment |
4
$begingroup$
:| wtf so many alternatives
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
@ASCII-only Least I could do on a simple challenge like this :p
$endgroup$
– Conor O'Brien
yesterday
4
4
$begingroup$
:| wtf so many alternatives
$endgroup$
– ASCII-only
yesterday
$begingroup$
:| wtf so many alternatives
$endgroup$
– ASCII-only
yesterday
1
1
$begingroup$
@ASCII-only Least I could do on a simple challenge like this :p
$endgroup$
– Conor O'Brien
yesterday
$begingroup$
@ASCII-only Least I could do on a simple challenge like this :p
$endgroup$
– Conor O'Brien
yesterday
add a comment |
$begingroup$
Brainf***, 7 bytes
,[>,]<.
$endgroup$
$begingroup$
ideone.com/XoJLD0 It still doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean Try it here. (Honestly, I didn't even know ideone did BF).
$endgroup$
– SuperJedi224
2 days ago
$begingroup$
Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean ideone seems to use-1as the EOF.+[>,+]<-.should work
$endgroup$
– Jo King
yesterday
$begingroup$
@Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit?
$endgroup$
– jean
yesterday
|
show 3 more comments
$begingroup$
Brainf***, 7 bytes
,[>,]<.
$endgroup$
$begingroup$
ideone.com/XoJLD0 It still doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean Try it here. (Honestly, I didn't even know ideone did BF).
$endgroup$
– SuperJedi224
2 days ago
$begingroup$
Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean ideone seems to use-1as the EOF.+[>,+]<-.should work
$endgroup$
– Jo King
yesterday
$begingroup$
@Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit?
$endgroup$
– jean
yesterday
|
show 3 more comments
$begingroup$
Brainf***, 7 bytes
,[>,]<.
$endgroup$
Brainf***, 7 bytes
,[>,]<.
answered 2 days ago
SuperJedi224SuperJedi224
9,86013363
9,86013363
$begingroup$
ideone.com/XoJLD0 It still doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean Try it here. (Honestly, I didn't even know ideone did BF).
$endgroup$
– SuperJedi224
2 days ago
$begingroup$
Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean ideone seems to use-1as the EOF.+[>,+]<-.should work
$endgroup$
– Jo King
yesterday
$begingroup$
@Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit?
$endgroup$
– jean
yesterday
|
show 3 more comments
$begingroup$
ideone.com/XoJLD0 It still doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean Try it here. (Honestly, I didn't even know ideone did BF).
$endgroup$
– SuperJedi224
2 days ago
$begingroup$
Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean ideone seems to use-1as the EOF.+[>,+]<-.should work
$endgroup$
– Jo King
yesterday
$begingroup$
@Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit?
$endgroup$
– jean
yesterday
$begingroup$
ideone.com/XoJLD0 It still doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
ideone.com/XoJLD0 It still doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean Try it here. (Honestly, I didn't even know ideone did BF).
$endgroup$
– SuperJedi224
2 days ago
$begingroup$
@jean Try it here. (Honestly, I didn't even know ideone did BF).
$endgroup$
– SuperJedi224
2 days ago
$begingroup$
Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
Yes, in your link everything works fine. But online judge for this problem uses ideone where it doesn't work ;(
$endgroup$
– jean
2 days ago
$begingroup$
@jean ideone seems to use
-1 as the EOF. +[>,+]<-. should work$endgroup$
– Jo King
yesterday
$begingroup$
@jean ideone seems to use
-1 as the EOF. +[>,+]<-. should work$endgroup$
– Jo King
yesterday
$begingroup$
@Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit?
$endgroup$
– jean
yesterday
$begingroup$
@Jo King Sorry, but the input looks like: 29845812674[enter][EOF] how can I print the last digit?
$endgroup$
– jean
yesterday
|
show 3 more comments
$begingroup$
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
$endgroup$
$begingroup$
I'd have gone forJ)...
$endgroup$
– Sanchises
yesterday
add a comment |
$begingroup$
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
$endgroup$
$begingroup$
I'd have gone forJ)...
$endgroup$
– Sanchises
yesterday
add a comment |
$begingroup$
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
$endgroup$
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
edited yesterday
answered 2 days ago
SueverSuever
9,8421446
9,8421446
$begingroup$
I'd have gone forJ)...
$endgroup$
– Sanchises
yesterday
add a comment |
$begingroup$
I'd have gone forJ)...
$endgroup$
– Sanchises
yesterday
$begingroup$
I'd have gone for
J)...$endgroup$
– Sanchises
yesterday
$begingroup$
I'd have gone for
J)...$endgroup$
– Sanchises
yesterday
add a comment |
$begingroup$
x86 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
IBM PC DOS, 8088 Assembly, 12 11 bytes
Or as complete program as IBM PC DOS executable. Input is from command line, output is to console.
D1 EE SHR SI, 1 ; SI to DOS PSP at 80H (SI is 0100H at runtime)
AC LODSB ; load command line length in AL
91 XCHG AX, CX ; move length to CX for loop
F3/ AC REPZ LODSB ; load next char into AL, repeat until CX = 0
B4 0E MOV AH, 0EH ; PC BIOS write to screen function
CD 10 INT 10H ; display
C3 RET ; exit to DOS
Output:

Download LAST.COM DOS executable (11 bytes)
$endgroup$
$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
16 hours ago
$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 inSI, 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$
– gwaugh
6 hours ago
$begingroup$
@CodyGray the screenshot is using PCE, which is what I primarily use for testing since it uses the actual PC BIOS ROMs and actual DOS. I build on MASM 1.1 on DOS 2.0. :)
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
x86 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
IBM PC DOS, 8088 Assembly, 12 11 bytes
Or as complete program as IBM PC DOS executable. Input is from command line, output is to console.
D1 EE SHR SI, 1 ; SI to DOS PSP at 80H (SI is 0100H at runtime)
AC LODSB ; load command line length in AL
91 XCHG AX, CX ; move length to CX for loop
F3/ AC REPZ LODSB ; load next char into AL, repeat until CX = 0
B4 0E MOV AH, 0EH ; PC BIOS write to screen function
CD 10 INT 10H ; display
C3 RET ; exit to DOS
Output:

Download LAST.COM DOS executable (11 bytes)
$endgroup$
$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
16 hours ago
$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 inSI, 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$
– gwaugh
6 hours ago
$begingroup$
@CodyGray the screenshot is using PCE, which is what I primarily use for testing since it uses the actual PC BIOS ROMs and actual DOS. I build on MASM 1.1 on DOS 2.0. :)
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
x86 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
IBM PC DOS, 8088 Assembly, 12 11 bytes
Or as complete program as IBM PC DOS executable. Input is from command line, output is to console.
D1 EE SHR SI, 1 ; SI to DOS PSP at 80H (SI is 0100H at runtime)
AC LODSB ; load command line length in AL
91 XCHG AX, CX ; move length to CX for loop
F3/ AC REPZ LODSB ; load next char into AL, repeat until CX = 0
B4 0E MOV AH, 0EH ; PC BIOS write to screen function
CD 10 INT 10H ; display
C3 RET ; exit to DOS
Output:

Download LAST.COM DOS executable (11 bytes)
$endgroup$
x86 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
IBM PC DOS, 8088 Assembly, 12 11 bytes
Or as complete program as IBM PC DOS executable. Input is from command line, output is to console.
D1 EE SHR SI, 1 ; SI to DOS PSP at 80H (SI is 0100H at runtime)
AC LODSB ; load command line length in AL
91 XCHG AX, CX ; move length to CX for loop
F3/ AC REPZ LODSB ; load next char into AL, repeat until CX = 0
B4 0E MOV AH, 0EH ; PC BIOS write to screen function
CD 10 INT 10H ; display
C3 RET ; exit to DOS
Output:

Download LAST.COM DOS executable (11 bytes)
edited 5 hours ago
answered yesterday
gwaughgwaugh
1,838515
1,838515
$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
16 hours ago
$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 inSI, 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$
– gwaugh
6 hours ago
$begingroup$
@CodyGray the screenshot is using PCE, which is what I primarily use for testing since it uses the actual PC BIOS ROMs and actual DOS. I build on MASM 1.1 on DOS 2.0. :)
$endgroup$
– gwaugh
6 hours ago
add a comment |
$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
16 hours ago
$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 inSI, 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$
– gwaugh
6 hours ago
$begingroup$
@CodyGray the screenshot is using PCE, which is what I primarily use for testing since it uses the actual PC BIOS ROMs and actual DOS. I build on MASM 1.1 on DOS 2.0. :)
$endgroup$
– gwaugh
6 hours ago
$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
16 hours ago
$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
16 hours ago
$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 in CX output char is in AL" and then I think the only code that would be necessary is REPZ 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$
– gwaugh
6 hours ago
$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 in CX output char is in AL" and then I think the only code that would be necessary is REPZ 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$
– gwaugh
6 hours ago
$begingroup$
@CodyGray the screenshot is using PCE, which is what I primarily use for testing since it uses the actual PC BIOS ROMs and actual DOS. I build on MASM 1.1 on DOS 2.0. :)
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@CodyGray the screenshot is using PCE, which is what I primarily use for testing since it uses the actual PC BIOS ROMs and actual DOS. I build on MASM 1.1 on DOS 2.0. :)
$endgroup$
– gwaugh
6 hours ago
add a comment |
$begingroup$
Javascript, 14 bytes
a=>a.slice(-1)
$endgroup$
add a comment |
$begingroup$
Javascript, 14 bytes
a=>a.slice(-1)
$endgroup$
add a comment |
$begingroup$
Javascript, 14 bytes
a=>a.slice(-1)
$endgroup$
Javascript, 14 bytes
a=>a.slice(-1)
answered 2 days ago
SuperJedi224SuperJedi224
9,86013363
9,86013363
add a comment |
add a comment |
$begingroup$
Bash + coreutils, 8 bytes
tail -c1
Input is from stdin, output is to stdout.
$endgroup$
add a comment |
$begingroup$
Bash + coreutils, 8 bytes
tail -c1
Input is from stdin, output is to stdout.
$endgroup$
add a comment |
$begingroup$
Bash + coreutils, 8 bytes
tail -c1
Input is from stdin, output is to stdout.
$endgroup$
Bash + coreutils, 8 bytes
tail -c1
Input is from stdin, output is to stdout.
answered yesterday
pizzapants184pizzapants184
2,764716
2,764716
add a comment |
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
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.
edited yesterday
answered 2 days ago
TauTau
496210
496210
add a comment |
add a comment |
$begingroup$
Haskell, 9 4 bytes
last
Try it online!
$endgroup$
$begingroup$
Why bother withpure? Isn'tlastenough?
$endgroup$
– dfeuer
13 hours ago
$begingroup$
I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".
$endgroup$
– flawr
12 hours ago
add a comment |
$begingroup$
Haskell, 9 4 bytes
last
Try it online!
$endgroup$
$begingroup$
Why bother withpure? Isn'tlastenough?
$endgroup$
– dfeuer
13 hours ago
$begingroup$
I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".
$endgroup$
– flawr
12 hours ago
add a comment |
$begingroup$
Haskell, 9 4 bytes
last
Try it online!
$endgroup$
Haskell, 9 4 bytes
last
Try it online!
edited 12 hours ago
answered 2 days ago
flawrflawr
26.9k665188
26.9k665188
$begingroup$
Why bother withpure? Isn'tlastenough?
$endgroup$
– dfeuer
13 hours ago
$begingroup$
I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".
$endgroup$
– flawr
12 hours ago
add a comment |
$begingroup$
Why bother withpure? Isn'tlastenough?
$endgroup$
– dfeuer
13 hours ago
$begingroup$
I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".
$endgroup$
– flawr
12 hours ago
$begingroup$
Why bother with
pure? Isn't last enough?$endgroup$
– dfeuer
13 hours ago
$begingroup$
Why bother with
pure? Isn't last enough?$endgroup$
– dfeuer
13 hours ago
$begingroup$
I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".
$endgroup$
– flawr
12 hours ago
$begingroup$
I assumed that the output must be a string too, but you're right, OP is only talking about "bytes".
$endgroup$
– flawr
12 hours ago
add a comment |
$begingroup$
Java 8
Input from STDIN, 71 bytes
v->{int i=0;for(;System.in.available()>0;i=System.in.read());return i;}
Try it online!
Function Argument, 25 bytes
s->s.charAt(s.length()-1)
$endgroup$
$begingroup$
You could add the code for program argument to have all three options. :) Too bad OP specifically asks for Strings, otherwises->s[s.length-1]would have been enough with acharparameter-type.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
61 bytes.
$endgroup$
– Olivier Grégoire
8 hours ago
add a comment |
$begingroup$
Java 8
Input from STDIN, 71 bytes
v->{int i=0;for(;System.in.available()>0;i=System.in.read());return i;}
Try it online!
Function Argument, 25 bytes
s->s.charAt(s.length()-1)
$endgroup$
$begingroup$
You could add the code for program argument to have all three options. :) Too bad OP specifically asks for Strings, otherwises->s[s.length-1]would have been enough with acharparameter-type.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
61 bytes.
$endgroup$
– Olivier Grégoire
8 hours ago
add a comment |
$begingroup$
Java 8
Input from STDIN, 71 bytes
v->{int i=0;for(;System.in.available()>0;i=System.in.read());return i;}
Try it online!
Function Argument, 25 bytes
s->s.charAt(s.length()-1)
$endgroup$
Java 8
Input from STDIN, 71 bytes
v->{int i=0;for(;System.in.available()>0;i=System.in.read());return i;}
Try it online!
Function Argument, 25 bytes
s->s.charAt(s.length()-1)
edited 2 days ago
answered 2 days ago
Benjamin UrquhartBenjamin Urquhart
3057
3057
$begingroup$
You could add the code for program argument to have all three options. :) Too bad OP specifically asks for Strings, otherwises->s[s.length-1]would have been enough with acharparameter-type.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
61 bytes.
$endgroup$
– Olivier Grégoire
8 hours ago
add a comment |
$begingroup$
You could add the code for program argument to have all three options. :) Too bad OP specifically asks for Strings, otherwises->s[s.length-1]would have been enough with acharparameter-type.
$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
61 bytes.
$endgroup$
– Olivier Grégoire
8 hours ago
$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 a char parameter-type.$endgroup$
– Kevin Cruijssen
yesterday
$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 a char parameter-type.$endgroup$
– Kevin Cruijssen
yesterday
$begingroup$
61 bytes.
$endgroup$
– Olivier Grégoire
8 hours ago
$begingroup$
61 bytes.
$endgroup$
– Olivier Grégoire
8 hours ago
add a comment |
$begingroup$
><>, 2 bytes
Using command line args
o;
Try it online!
><>, 11 bytes
Using stdin
~o;
/?(0:i
Try it online!
$endgroup$
add a comment |
$begingroup$
><>, 2 bytes
Using command line args
o;
Try it online!
><>, 11 bytes
Using stdin
~o;
/?(0:i
Try it online!
$endgroup$
add a comment |
$begingroup$
><>, 2 bytes
Using command line args
o;
Try it online!
><>, 11 bytes
Using stdin
~o;
/?(0:i
Try it online!
$endgroup$
><>, 2 bytes
Using command line args
o;
Try it online!
><>, 11 bytes
Using stdin
~o;
/?(0:i
Try it online!
answered 2 days ago
EmignaEmigna
47k433142
47k433142
add a comment |
add a comment |
$begingroup$
Cubix, 6 bytes
pA/@po
Try it online!
p
A / @ p
o
Watch it run
ATakes all the input
/Redirect around the cube
ppbring bottom of the stack to the top twice
o/@output as character, redirect and halt
$endgroup$
add a comment |
$begingroup$
Cubix, 6 bytes
pA/@po
Try it online!
p
A / @ p
o
Watch it run
ATakes all the input
/Redirect around the cube
ppbring bottom of the stack to the top twice
o/@output as character, redirect and halt
$endgroup$
add a comment |
$begingroup$
Cubix, 6 bytes
pA/@po
Try it online!
p
A / @ p
o
Watch it run
ATakes all the input
/Redirect around the cube
ppbring bottom of the stack to the top twice
o/@output as character, redirect and halt
$endgroup$
Cubix, 6 bytes
pA/@po
Try it online!
p
A / @ p
o
Watch it run
ATakes all the input
/Redirect around the cube
ppbring bottom of the stack to the top twice
o/@output as character, redirect and halt
answered yesterday
MickyTMickyT
10.2k21637
10.2k21637
add a comment |
add a comment |
$begingroup$
Befunge-93, 12 15 bytes
:1+_p1-,@>~#
Try it online!
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.
$endgroup$
$begingroup$
Actually,$$instead ofp1should work without the warning for the same amount of bytes
$endgroup$
– Jo King
yesterday
add a comment |
$begingroup$
Befunge-93, 12 15 bytes
:1+_p1-,@>~#
Try it online!
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.
$endgroup$
$begingroup$
Actually,$$instead ofp1should work without the warning for the same amount of bytes
$endgroup$
– Jo King
yesterday
add a comment |
$begingroup$
Befunge-93, 12 15 bytes
:1+_p1-,@>~#
Try it online!
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.
$endgroup$
Befunge-93, 12 15 bytes
:1+_p1-,@>~#
Try it online!
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.
edited yesterday
answered 2 days ago
JPeroutekJPeroutek
37018
37018
$begingroup$
Actually,$$instead ofp1should work without the warning for the same amount of bytes
$endgroup$
– Jo King
yesterday
add a comment |
$begingroup$
Actually,$$instead ofp1should work without the warning for the same amount of bytes
$endgroup$
– Jo King
yesterday
$begingroup$
Actually,
$$ instead of p1 should work without the warning for the same amount of bytes$endgroup$
– Jo King
yesterday
$begingroup$
Actually,
$$ instead of p1 should work without the warning for the same amount of bytes$endgroup$
– Jo King
yesterday
add a comment |
$begingroup$
Jelly, 1 byte
Ṫ
Try it online!
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.
$endgroup$
$begingroup$
-1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)
$endgroup$
– MilkyWay90
yesterday
$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$
– ბიმო
yesterday
$begingroup$
Okay, I'll try seeing whether or not it will work as a link
$endgroup$
– MilkyWay90
yesterday
$begingroup$
@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)
$endgroup$
– MilkyWay90
yesterday
$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
22 hours ago
add a comment |
$begingroup$
Jelly, 1 byte
Ṫ
Try it online!
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.
$endgroup$
$begingroup$
-1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)
$endgroup$
– MilkyWay90
yesterday
$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$
– ბიმო
yesterday
$begingroup$
Okay, I'll try seeing whether or not it will work as a link
$endgroup$
– MilkyWay90
yesterday
$begingroup$
@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)
$endgroup$
– MilkyWay90
yesterday
$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
22 hours ago
add a comment |
$begingroup$
Jelly, 1 byte
Ṫ
Try it online!
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.
$endgroup$
Jelly, 1 byte
Ṫ
Try it online!
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.
edited yesterday
answered 2 days ago
Nick KennedyNick Kennedy
78137
78137
$begingroup$
-1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)
$endgroup$
– MilkyWay90
yesterday
$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$
– ბიმო
yesterday
$begingroup$
Okay, I'll try seeing whether or not it will work as a link
$endgroup$
– MilkyWay90
yesterday
$begingroup$
@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)
$endgroup$
– MilkyWay90
yesterday
$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
22 hours ago
add a comment |
$begingroup$
-1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)
$endgroup$
– MilkyWay90
yesterday
$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$
– ბიმო
yesterday
$begingroup$
Okay, I'll try seeing whether or not it will work as a link
$endgroup$
– MilkyWay90
yesterday
$begingroup$
@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)
$endgroup$
– MilkyWay90
yesterday
$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
22 hours ago
$begingroup$
-1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)
$endgroup$
– MilkyWay90
yesterday
$begingroup$
-1 Fails for any number (tio.run/##y0rNyan8///hzlX///83MTY1NjE1MQYA)
$endgroup$
– MilkyWay90
yesterday
$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$
– ბიმო
yesterday
$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$
– ბიმო
yesterday
$begingroup$
Okay, I'll try seeing whether or not it will work as a link
$endgroup$
– MilkyWay90
yesterday
$begingroup$
Okay, I'll try seeing whether or not it will work as a link
$endgroup$
– MilkyWay90
yesterday
$begingroup$
@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)
$endgroup$
– MilkyWay90
yesterday
$begingroup$
@ბიმო Seems to work (OP can you edit the answer so I can undo my downvote?)
$endgroup$
– MilkyWay90
yesterday
$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
22 hours ago
$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
22 hours ago
add a comment |
$begingroup$
PHP, 13 bytes
<?=$argn[-1];
Try it online!
Run with php -nF input is STDIN. Example:
$ echo 29845812674|php -nF lost.php
$endgroup$
add a comment |
$begingroup$
PHP, 13 bytes
<?=$argn[-1];
Try it online!
Run with php -nF input is STDIN. Example:
$ echo 29845812674|php -nF lost.php
$endgroup$
add a comment |
$begingroup$
PHP, 13 bytes
<?=$argn[-1];
Try it online!
Run with php -nF input is STDIN. Example:
$ echo 29845812674|php -nF lost.php
$endgroup$
PHP, 13 bytes
<?=$argn[-1];
Try it online!
Run with php -nF input is STDIN. Example:
$ echo 29845812674|php -nF lost.php
answered yesterday
gwaughgwaugh
1,838515
1,838515
add a comment |
add a comment |
$begingroup$
Python 3, 14 bytes
lambda x:x[-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 3, 14 bytes
lambda x:x[-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 3, 14 bytes
lambda x:x[-1]
Try it online!
$endgroup$
Python 3, 14 bytes
lambda x:x[-1]
Try it online!
answered 2 days ago
MilkyWay90MilkyWay90
543212
543212
add a comment |
add a comment |
$begingroup$
PowerShell, 11 bytes
"$args"[-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 11 bytes
"$args"[-1]
Try it online!
$endgroup$
add a comment |
$begingroup$
PowerShell, 11 bytes
"$args"[-1]
Try it online!
$endgroup$
PowerShell, 11 bytes
"$args"[-1]
Try it online!
answered 2 days ago
Gabriel MillsGabriel Mills
604213
604213
add a comment |
add a comment |
$begingroup$
05AB1E, 1 byte
¤
Try it online!
θ or ` would also work.
$endgroup$
add a comment |
$begingroup$
05AB1E, 1 byte
¤
Try it online!
θ or ` would also work.
$endgroup$
add a comment |
$begingroup$
05AB1E, 1 byte
¤
Try it online!
θ or ` would also work.
$endgroup$
05AB1E, 1 byte
¤
Try it online!
θ or ` would also work.
answered yesterday
EmignaEmigna
47k433142
47k433142
add a comment |
add a comment |
$begingroup$
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)
$endgroup$
$begingroup$
Ok, that's the first time I see a Twig golf.
$endgroup$
– Ven
yesterday
$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
yesterday
add a comment |
$begingroup$
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)
$endgroup$
$begingroup$
Ok, that's the first time I see a Twig golf.
$endgroup$
– Ven
yesterday
$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
yesterday
add a comment |
$begingroup$
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)
$endgroup$
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)
answered yesterday
Ismael MiguelIsmael Miguel
6,25211533
6,25211533
$begingroup$
Ok, that's the first time I see a Twig golf.
$endgroup$
– Ven
yesterday
$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
yesterday
add a comment |
$begingroup$
Ok, that's the first time I see a Twig golf.
$endgroup$
– Ven
yesterday
$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
yesterday
$begingroup$
Ok, that's the first time I see a Twig golf.
$endgroup$
– Ven
yesterday
$begingroup$
Ok, that's the first time I see a Twig golf.
$endgroup$
– Ven
yesterday
$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
yesterday
$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
yesterday
add a comment |
$begingroup$
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.
Try it online!
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.
$endgroup$
– Stephen
yesterday
$begingroup$
Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.
$endgroup$
– Mrwerdo
yesterday
$begingroup$
This won't handle a newline in the input
$endgroup$
– Jo King
yesterday
1
$begingroup$
14
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
How about this?
$endgroup$
– Mrwerdo
yesterday
|
show 3 more comments
$begingroup$
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.
Try it online!
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.
$endgroup$
– Stephen
yesterday
$begingroup$
Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.
$endgroup$
– Mrwerdo
yesterday
$begingroup$
This won't handle a newline in the input
$endgroup$
– Jo King
yesterday
1
$begingroup$
14
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
How about this?
$endgroup$
– Mrwerdo
yesterday
|
show 3 more comments
$begingroup$
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.
Try it online!
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
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.
Try it online!
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered yesterday
MrwerdoMrwerdo
1293
1293
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Mrwerdo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$begingroup$
This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.
$endgroup$
– Stephen
yesterday
$begingroup$
Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.
$endgroup$
– Mrwerdo
yesterday
$begingroup$
This won't handle a newline in the input
$endgroup$
– Jo King
yesterday
1
$begingroup$
14
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
How about this?
$endgroup$
– Mrwerdo
yesterday
|
show 3 more comments
$begingroup$
This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.
$endgroup$
– Stephen
yesterday
$begingroup$
Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.
$endgroup$
– Mrwerdo
yesterday
$begingroup$
This won't handle a newline in the input
$endgroup$
– Jo King
yesterday
1
$begingroup$
14
$endgroup$
– ASCII-only
yesterday
1
$begingroup$
How about this?
$endgroup$
– Mrwerdo
yesterday
$begingroup$
This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.
$endgroup$
– Stephen
yesterday
$begingroup$
This does not print anything or return anything from a function - snippets are not allowed, only functions or full programs.
$endgroup$
– Stephen
yesterday
$begingroup$
Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.
$endgroup$
– Mrwerdo
yesterday
$begingroup$
Ah I see, didn’t think about that when I though of the answer. Only thought about running it in the interpreter.
$endgroup$
– Mrwerdo
yesterday
$begingroup$
This won't handle a newline in the input
$endgroup$
– Jo King
yesterday
$begingroup$
This won't handle a newline in the input
$endgroup$
– Jo King
yesterday
1
1
$begingroup$
14
$endgroup$
– ASCII-only
yesterday
$begingroup$
14
$endgroup$
– ASCII-only
yesterday
1
1
$begingroup$
How about this?
$endgroup$
– Mrwerdo
yesterday
$begingroup$
How about this?
$endgroup$
– Mrwerdo
yesterday
|
show 3 more comments
$begingroup$
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]);}}
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
The challenge mentions "output", so the last solution is probably the right one
$endgroup$
– Ven
yesterday
$begingroup$
Dang, you outdid my console answer by a lot. How does the ^1 work?
$endgroup$
– Stackstuck
yesterday
$begingroup$
It's the new Index type. Starting an index with a caret indicates it's from the end, i.e.array[^n]is the same asarray[array.Length - n]
$endgroup$
– briman0094
yesterday
$begingroup$
Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?
$endgroup$
– mortb
12 hours ago
1
$begingroup$
Found it: docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
$endgroup$
– mortb
12 hours ago
add a comment |
$begingroup$
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]);}}
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
The challenge mentions "output", so the last solution is probably the right one
$endgroup$
– Ven
yesterday
$begingroup$
Dang, you outdid my console answer by a lot. How does the ^1 work?
$endgroup$
– Stackstuck
yesterday
$begingroup$
It's the new Index type. Starting an index with a caret indicates it's from the end, i.e.array[^n]is the same asarray[array.Length - n]
$endgroup$
– briman0094
yesterday
$begingroup$
Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?
$endgroup$
– mortb
12 hours ago
1
$begingroup$
Found it: docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
$endgroup$
– mortb
12 hours ago
add a comment |
$begingroup$
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]);}}
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
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]);}}
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered yesterday
briman0094briman0094
1212
1212
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
briman0094 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$begingroup$
The challenge mentions "output", so the last solution is probably the right one
$endgroup$
– Ven
yesterday
$begingroup$
Dang, you outdid my console answer by a lot. How does the ^1 work?
$endgroup$
– Stackstuck
yesterday
$begingroup$
It's the new Index type. Starting an index with a caret indicates it's from the end, i.e.array[^n]is the same asarray[array.Length - n]
$endgroup$
– briman0094
yesterday
$begingroup$
Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?
$endgroup$
– mortb
12 hours ago
1
$begingroup$
Found it: docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
$endgroup$
– mortb
12 hours ago
add a comment |
$begingroup$
The challenge mentions "output", so the last solution is probably the right one
$endgroup$
– Ven
yesterday
$begingroup$
Dang, you outdid my console answer by a lot. How does the ^1 work?
$endgroup$
– Stackstuck
yesterday
$begingroup$
It's the new Index type. Starting an index with a caret indicates it's from the end, i.e.array[^n]is the same asarray[array.Length - n]
$endgroup$
– briman0094
yesterday
$begingroup$
Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?
$endgroup$
– mortb
12 hours ago
1
$begingroup$
Found it: docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
$endgroup$
– mortb
12 hours ago
$begingroup$
The challenge mentions "output", so the last solution is probably the right one
$endgroup$
– Ven
yesterday
$begingroup$
The challenge mentions "output", so the last solution is probably the right one
$endgroup$
– Ven
yesterday
$begingroup$
Dang, you outdid my console answer by a lot. How does the ^1 work?
$endgroup$
– Stackstuck
yesterday
$begingroup$
Dang, you outdid my console answer by a lot. How does the ^1 work?
$endgroup$
– Stackstuck
yesterday
$begingroup$
It's the new Index type. Starting an index with a caret indicates it's from the end, i.e.
array[^n] is the same as array[array.Length - n]$endgroup$
– briman0094
yesterday
$begingroup$
It's the new Index type. Starting an index with a caret indicates it's from the end, i.e.
array[^n] is the same as array[array.Length - n]$endgroup$
– briman0094
yesterday
$begingroup$
Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?
$endgroup$
– mortb
12 hours ago
$begingroup$
Interesting! I always try to stay up to date with new C# features. Do you have any link / reference on that?
$endgroup$
– mortb
12 hours ago
1
1
$begingroup$
Found it: docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
$endgroup$
– mortb
12 hours ago
$begingroup$
Found it: docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0
$endgroup$
– mortb
12 hours ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 16 bytes
#~StringTake~-1&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 16 bytes
#~StringTake~-1&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 16 bytes
#~StringTake~-1&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 16 bytes
#~StringTake~-1&
Try it online!
answered 2 days ago
shrapshrap
1113
1113
add a comment |
add a comment |
$begingroup$
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
Try it online!
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
$endgroup$
add a comment |
$begingroup$
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
Try it online!
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
$endgroup$
add a comment |
$begingroup$
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
Try it online!
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
$endgroup$
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
Try it online!
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
answered yesterday
MilkyWay90MilkyWay90
543212
543212
add a comment |
add a comment |
$begingroup$
Befunge-98, 5 bytes
~2j@,
Try it online!
Explanation:
~ Take input
2j Skip next two instructions
~ Repeat until EOF, where it reflects
@, Print the last character and exit
$endgroup$
add a comment |
$begingroup$
Befunge-98, 5 bytes
~2j@,
Try it online!
Explanation:
~ Take input
2j Skip next two instructions
~ Repeat until EOF, where it reflects
@, Print the last character and exit
$endgroup$
add a comment |
$begingroup$
Befunge-98, 5 bytes
~2j@,
Try it online!
Explanation:
~ Take input
2j Skip next two instructions
~ Repeat until EOF, where it reflects
@, Print the last character and exit
$endgroup$
Befunge-98, 5 bytes
~2j@,
Try it online!
Explanation:
~ Take input
2j Skip next two instructions
~ Repeat until EOF, where it reflects
@, Print the last character and exit
answered yesterday
Jo KingJo King
25k359128
25k359128
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 11 bytes
x=>x.Last()
Try it online!
$endgroup$
$begingroup$
you can use a function :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
OK - Ill update my answer :)
$endgroup$
– dana
yesterday
1
$begingroup$
uhm why is testcase in STDIN not footer
$endgroup$
– ASCII-only
yesterday
$begingroup$
Wow - It's been a while. Thanks for pointing that out ;)
$endgroup$
– dana
yesterday
1
$begingroup$
That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.
$endgroup$
– Ven
yesterday
|
show 3 more comments
$begingroup$
C# (Visual C# Interactive Compiler), 11 bytes
x=>x.Last()
Try it online!
$endgroup$
$begingroup$
you can use a function :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
OK - Ill update my answer :)
$endgroup$
– dana
yesterday
1
$begingroup$
uhm why is testcase in STDIN not footer
$endgroup$
– ASCII-only
yesterday
$begingroup$
Wow - It's been a while. Thanks for pointing that out ;)
$endgroup$
– dana
yesterday
1
$begingroup$
That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.
$endgroup$
– Ven
yesterday
|
show 3 more comments
$begingroup$
C# (Visual C# Interactive Compiler), 11 bytes
x=>x.Last()
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 11 bytes
x=>x.Last()
Try it online!
edited yesterday
answered yesterday
danadana
1,511167
1,511167
$begingroup$
you can use a function :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
OK - Ill update my answer :)
$endgroup$
– dana
yesterday
1
$begingroup$
uhm why is testcase in STDIN not footer
$endgroup$
– ASCII-only
yesterday
$begingroup$
Wow - It's been a while. Thanks for pointing that out ;)
$endgroup$
– dana
yesterday
1
$begingroup$
That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.
$endgroup$
– Ven
yesterday
|
show 3 more comments
$begingroup$
you can use a function :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
OK - Ill update my answer :)
$endgroup$
– dana
yesterday
1
$begingroup$
uhm why is testcase in STDIN not footer
$endgroup$
– ASCII-only
yesterday
$begingroup$
Wow - It's been a while. Thanks for pointing that out ;)
$endgroup$
– dana
yesterday
1
$begingroup$
That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.
$endgroup$
– Ven
yesterday
$begingroup$
you can use a function :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
you can use a function :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
OK - Ill update my answer :)
$endgroup$
– dana
yesterday
$begingroup$
OK - Ill update my answer :)
$endgroup$
– dana
yesterday
1
1
$begingroup$
uhm why is testcase in STDIN not footer
$endgroup$
– ASCII-only
yesterday
$begingroup$
uhm why is testcase in STDIN not footer
$endgroup$
– ASCII-only
yesterday
$begingroup$
Wow - It's been a while. Thanks for pointing that out ;)
$endgroup$
– dana
yesterday
$begingroup$
Wow - It's been a while. Thanks for pointing that out ;)
$endgroup$
– dana
yesterday
1
1
$begingroup$
That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.
$endgroup$
– Ven
yesterday
$begingroup$
That's not how I understand it. I understand that it should print the last non-empty character. We need to ask OP.
$endgroup$
– Ven
yesterday
|
show 3 more comments
$begingroup$
Japt, 1 byte
Ì
Try it online!
-1 byte thanks to Quintec!
$endgroup$
1
$begingroup$
1 byte
$endgroup$
– Quintec
yesterday
add a comment |
$begingroup$
Japt, 1 byte
Ì
Try it online!
-1 byte thanks to Quintec!
$endgroup$
1
$begingroup$
1 byte
$endgroup$
– Quintec
yesterday
add a comment |
$begingroup$
Japt, 1 byte
Ì
Try it online!
-1 byte thanks to Quintec!
$endgroup$
Japt, 1 byte
Ì
Try it online!
-1 byte thanks to Quintec!
edited yesterday
answered yesterday
danadana
1,511167
1,511167
1
$begingroup$
1 byte
$endgroup$
– Quintec
yesterday
add a comment |
1
$begingroup$
1 byte
$endgroup$
– Quintec
yesterday
1
1
$begingroup$
1 byte
$endgroup$
– Quintec
yesterday
$begingroup$
1 byte
$endgroup$
– Quintec
yesterday
add a comment |
$begingroup$
APL+WIN, 4 bytes
¯1↑⎕
Prompt for input string and select last byte.
$endgroup$
add a comment |
$begingroup$
APL+WIN, 4 bytes
¯1↑⎕
Prompt for input string and select last byte.
$endgroup$
add a comment |
$begingroup$
APL+WIN, 4 bytes
¯1↑⎕
Prompt for input string and select last byte.
$endgroup$
APL+WIN, 4 bytes
¯1↑⎕
Prompt for input string and select last byte.
answered yesterday
GrahamGraham
2,55678
2,55678
add a comment |
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
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.
answered yesterday
Kevin CruijssenKevin Cruijssen
40.8k566210
40.8k566210
add a comment |
add a comment |
$begingroup$
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
Try it online.
$endgroup$
1
$begingroup$
0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?
$endgroup$
– ASCII-only
yesterday
$begingroup$
oi pls reply :||
$endgroup$
– ASCII-only
yesterday
$begingroup$
wouldn't work in what way? I've tested it online
$endgroup$
– ASCII-only
yesterday
$begingroup$
@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.
$endgroup$
– SuperJedi224
yesterday
$begingroup$
Well, this is a simple challenge, don't think it needs more than one answer in any language :P
$endgroup$
– ASCII-only
yesterday
|
show 1 more comment
$begingroup$
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
Try it online.
$endgroup$
1
$begingroup$
0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?
$endgroup$
– ASCII-only
yesterday
$begingroup$
oi pls reply :||
$endgroup$
– ASCII-only
yesterday
$begingroup$
wouldn't work in what way? I've tested it online
$endgroup$
– ASCII-only
yesterday
$begingroup$
@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.
$endgroup$
– SuperJedi224
yesterday
$begingroup$
Well, this is a simple challenge, don't think it needs more than one answer in any language :P
$endgroup$
– ASCII-only
yesterday
|
show 1 more comment
$begingroup$
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
Try it online.
$endgroup$
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
Try it online.
edited yesterday
answered yesterday
SuperJedi224SuperJedi224
9,86013363
9,86013363
1
$begingroup$
0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?
$endgroup$
– ASCII-only
yesterday
$begingroup$
oi pls reply :||
$endgroup$
– ASCII-only
yesterday
$begingroup$
wouldn't work in what way? I've tested it online
$endgroup$
– ASCII-only
yesterday
$begingroup$
@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.
$endgroup$
– SuperJedi224
yesterday
$begingroup$
Well, this is a simple challenge, don't think it needs more than one answer in any language :P
$endgroup$
– ASCII-only
yesterday
|
show 1 more comment
1
$begingroup$
0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?
$endgroup$
– ASCII-only
yesterday
$begingroup$
oi pls reply :||
$endgroup$
– ASCII-only
yesterday
$begingroup$
wouldn't work in what way? I've tested it online
$endgroup$
– ASCII-only
yesterday
$begingroup$
@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.
$endgroup$
– SuperJedi224
yesterday
$begingroup$
Well, this is a simple challenge, don't think it needs more than one answer in any language :P
$endgroup$
– ASCII-only
yesterday
1
1
$begingroup$
0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?$endgroup$
– ASCII-only
yesterday
$begingroup$
0 * * r 1/1 * * l 2/1 _ _ l halt/2 * _ r 0?$endgroup$
– ASCII-only
yesterday
$begingroup$
oi pls reply :||
$endgroup$
– ASCII-only
yesterday
$begingroup$
oi pls reply :||
$endgroup$
– ASCII-only
yesterday
$begingroup$
wouldn't work in what way? I've tested it online
$endgroup$
– ASCII-only
yesterday
$begingroup$
wouldn't work in what way? I've tested it online
$endgroup$
– ASCII-only
yesterday
$begingroup$
@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.
$endgroup$
– SuperJedi224
yesterday
$begingroup$
@ASCII-only It turns out you're correct, and I was simply misinterpreting the way your program actually worked. I think it's different enough that you can post it as a different answer if you want to.
$endgroup$
– SuperJedi224
yesterday
$begingroup$
Well, this is a simple challenge, don't think it needs more than one answer in any language :P
$endgroup$
– ASCII-only
yesterday
$begingroup$
Well, this is a simple challenge, don't think it needs more than one answer in any language :P
$endgroup$
– ASCII-only
yesterday
|
show 1 more comment
$begingroup$
R, 35 bytes
Takes the input, splits it in to a list, outputs the last element of the list.
tail(strsplit(scan(,''),'')[[1]],1)
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 35 bytes
Takes the input, splits it in to a list, outputs the last element of the list.
tail(strsplit(scan(,''),'')[[1]],1)
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 35 bytes
Takes the input, splits it in to a list, outputs the last element of the list.
tail(strsplit(scan(,''),'')[[1]],1)
Try it online!
$endgroup$
R, 35 bytes
Takes the input, splits it in to a list, outputs the last element of the list.
tail(strsplit(scan(,''),'')[[1]],1)
Try it online!
answered yesterday
CT HallCT Hall
42110
42110
add a comment |
add a comment |
$begingroup$
INTERCAL, 270 bytes
DO,1<-#1PLEASECOMEFROM(2)DOWRITEIN,1DO.1<-,1SUB#1DO.5<-#1$!1~#256'DO.2<-.3DO(1)NEXTPLEASE.2<-'"!3~#1'$!3~#16'"$"!3~#4'$!3~#64'"'$'"!3~#2'$!3~#32'"$"!3~#8'$!3~#128'"'DO(1010)NEXTPLEASE,1SUB#1<-.3PLEASEREADOUT,1DOGIVEUP(1)DO(1002)NEXTDO(1009)NEXTDO.3<-.3~#255(2)DOFORGET#1
Try it online!
Writing this was... interesting. I was thinking I might want to use INTERCAL to INTERCALate, but I'm a bit less sure now.
Ungolfed and commented:
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. The nightmarish expression on the following line reverses the
bits the best way I could think to: individually select each one out and then mingle them all back
together. It may be possible to emulate the method used in cesspool.c, by using mingle and unary AND as a
substitute for binary AND where we can't afford for select to rearrange it, but it might end up longer...
DO .2 <- '"'.3~#1'$'.3~#16'"$"'.3~#4'$'.3~#64'"'$'"'.3~#2'$'.3~#32'"$"'.3~#8'$'.3~#128'"'
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
DO GIVE UP PLEASE NOTE End of program.
(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
$endgroup$
add a comment |
$begingroup$
INTERCAL, 270 bytes
DO,1<-#1PLEASECOMEFROM(2)DOWRITEIN,1DO.1<-,1SUB#1DO.5<-#1$!1~#256'DO.2<-.3DO(1)NEXTPLEASE.2<-'"!3~#1'$!3~#16'"$"!3~#4'$!3~#64'"'$'"!3~#2'$!3~#32'"$"!3~#8'$!3~#128'"'DO(1010)NEXTPLEASE,1SUB#1<-.3PLEASEREADOUT,1DOGIVEUP(1)DO(1002)NEXTDO(1009)NEXTDO.3<-.3~#255(2)DOFORGET#1
Try it online!
Writing this was... interesting. I was thinking I might want to use INTERCAL to INTERCALate, but I'm a bit less sure now.
Ungolfed and commented:
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. The nightmarish expression on the following line reverses the
bits the best way I could think to: individually select each one out and then mingle them all back
together. It may be possible to emulate the method used in cesspool.c, by using mingle and unary AND as a
substitute for binary AND where we can't afford for select to rearrange it, but it might end up longer...
DO .2 <- '"'.3~#1'$'.3~#16'"$"'.3~#4'$'.3~#64'"'$'"'.3~#2'$'.3~#32'"$"'.3~#8'$'.3~#128'"'
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
DO GIVE UP PLEASE NOTE End of program.
(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
$endgroup$
add a comment |
$begingroup$
INTERCAL, 270 bytes
DO,1<-#1PLEASECOMEFROM(2)DOWRITEIN,1DO.1<-,1SUB#1DO.5<-#1$!1~#256'DO.2<-.3DO(1)NEXTPLEASE.2<-'"!3~#1'$!3~#16'"$"!3~#4'$!3~#64'"'$'"!3~#2'$!3~#32'"$"!3~#8'$!3~#128'"'DO(1010)NEXTPLEASE,1SUB#1<-.3PLEASEREADOUT,1DOGIVEUP(1)DO(1002)NEXTDO(1009)NEXTDO.3<-.3~#255(2)DOFORGET#1
Try it online!
Writing this was... interesting. I was thinking I might want to use INTERCAL to INTERCALate, but I'm a bit less sure now.
Ungolfed and commented:
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. The nightmarish expression on the following line reverses the
bits the best way I could think to: individually select each one out and then mingle them all back
together. It may be possible to emulate the method used in cesspool.c, by using mingle and unary AND as a
substitute for binary AND where we can't afford for select to rearrange it, but it might end up longer...
DO .2 <- '"'.3~#1'$'.3~#16'"$"'.3~#4'$'.3~#64'"'$'"'.3~#2'$'.3~#32'"$"'.3~#8'$'.3~#128'"'
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
DO GIVE UP PLEASE NOTE End of program.
(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
$endgroup$
INTERCAL, 270 bytes
DO,1<-#1PLEASECOMEFROM(2)DOWRITEIN,1DO.1<-,1SUB#1DO.5<-#1$!1~#256'DO.2<-.3DO(1)NEXTPLEASE.2<-'"!3~#1'$!3~#16'"$"!3~#4'$!3~#64'"'$'"!3~#2'$!3~#32'"$"!3~#8'$!3~#128'"'DO(1010)NEXTPLEASE,1SUB#1<-.3PLEASEREADOUT,1DOGIVEUP(1)DO(1002)NEXTDO(1009)NEXTDO.3<-.3~#255(2)DOFORGET#1
Try it online!
Writing this was... interesting. I was thinking I might want to use INTERCAL to INTERCALate, but I'm a bit less sure now.
Ungolfed and commented:
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. The nightmarish expression on the following line reverses the
bits the best way I could think to: individually select each one out and then mingle them all back
together. It may be possible to emulate the method used in cesspool.c, by using mingle and unary AND as a
substitute for binary AND where we can't afford for select to rearrange it, but it might end up longer...
DO .2 <- '"'.3~#1'$'.3~#16'"$"'.3~#4'$'.3~#64'"'$'"'.3~#2'$'.3~#32'"$"'.3~#8'$'.3~#128'"'
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
DO GIVE UP PLEASE NOTE End of program.
(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
edited 13 hours ago
answered 14 hours ago
Unrelated StringUnrelated String
1,241110
1,241110
add a comment |
add a comment |
1 2
next
jean is a new contributor. Be nice, and check out our Code of Conduct.
jean is a new contributor. Be nice, and check out our Code of Conduct.
jean is a new contributor. Be nice, and check out our Code of Conduct.
jean is a new contributor. Be nice, and check out our Code of Conduct.
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181627%2fprint-last-inputted-byte%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
$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$
– ბიმო
2 days ago
10
$begingroup$
I vote against closing; it may be trivial, but that doesn't make it offtopic
$endgroup$
– MilkyWay90
yesterday
1
$begingroup$
@MillyWay I think most of the close votes were before the extensive edit by ბიმო
$endgroup$
– Sanchises
yesterday
9
$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
yesterday
2
$begingroup$
What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example?
$endgroup$
– FireCubez
yesterday