17
\$\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 .

Examples

"?" -> "?"
"29845812674" -> "4"
\$\endgroup\$
6
  • 5
    \$\begingroup\$ Welcome, I changed your question to fit our format more properly (note this is what the sandbox is for, usually). However in its current state the challenge is very easy (also in bf), so not sure about that. \$\endgroup\$ – ბიმო Mar 17 '19 at 19:11
  • 12
    \$\begingroup\$ I vote against closing; it may be trivial, but that doesn't make it offtopic \$\endgroup\$ – MilkyWay90 Mar 17 '19 at 22:30
  • 1
    \$\begingroup\$ @MillyWay I think most of the close votes were before the extensive edit by ბიმო \$\endgroup\$ – Sanchises Mar 18 '19 at 6:47
  • 10
    \$\begingroup\$ @ბიმო We have a consensus not to edit off-topic questions to make them on-topic which I think would have applied here. \$\endgroup\$ – Laikoni Mar 18 '19 at 7:19
  • 2
    \$\begingroup\$ What kind of string? Is it guaranteed to be ASCII only? Or should we handle UTF-8 (and how?) for example? \$\endgroup\$ – FireCubez Mar 18 '19 at 18:28

95 Answers 95

1 2 3
4
0
\$\begingroup\$

MathGolf, 2 bytes

┤Þ

Try it online.

Or alternatively:

Try it online.

Explanation:

┤   # Pop the left character of the (implicit) input-string loose to the stack
 Þ  # Only leave the top item of the stack, and discard everything else
    # (implicitly output the entire stack joined together)

b   # Push -1
 §  # Get the -1'th character of the (implicit) input-string
    # (0-based modulair similar as Python, so will index into the last character)
    # (implicitly output the entire stack joined together)
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 1 byte

θ

Try it online!

   # (implicit) push STDIN to stack
θ  # push last character of top of stack
   # (implicit) output top of stack to STDOUT
\$\endgroup\$
0
\$\begingroup\$

Rockstar, 30 bytes

listen to S
cut S
say S at S-1

Try it here (Code will need to be pasted in)

Or 51 bytes if we need to be able to handle newlines in the input:

listen to S
while S
listen to S

cut S
say S at S-1
\$\endgroup\$
0
\$\begingroup\$

CSASM v2.2.1.1, 46 bytes

func main:
in ""
push ^1
push ^0
substr
print
ret
end

Commented:

func main:
    ; Get the input
    in ""
    ; Get a substring of the input from (length - 1) to (length - 0)
    push ^1
    push ^0
    substr
    ; Print it
    print
    ret
end
\$\endgroup\$
0
\$\begingroup\$

Duocentehexaquinquagesimal, 3 bytes

t`F

Try it online!

\$\endgroup\$
1 2 3
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.