59
\$\begingroup\$

The challenge is simple: Print the last, middle, and first character of your program's source code, in that order.

The middle character is defined as follows, assuming a source length of n characters, and 1-indexing:

  • If n is even, print the n/2-th and n/2 + 1-th character. (abcdef == cd)
  • If n is odd, print (n-1)/2 + 1-th character. (abcde == c)

Rules

  • Given no input, print the last, middle, and first character in your source code, in the form [last][middle][first]. This will be 3-4 characters long.
  • Output must not contain any trailing whitespace. However, if whitespace is a first, middle, or last character, it must be printed as such.
  • Source code must be n >= 3 characters long.
  • Code must consist of >= 3 unique characters.
  • Standard loopholes are forbidden.
  • This is , so shortest solution in characters wins.

Samples

# Form: [code] --> [output]
xyz --> zyx
abcd --> dbca
1 --> # not allowed: too short
abcde --> eca
aaabb --> # not allowed: not enough unique characters
System.out.print("S;pr"); --> ;prS
this is a test --> ts t
123[newline]45 --> 53[newline]1

Challenge Proposal

\$\endgroup\$
  • 6
    \$\begingroup\$ Maybe it's only me, but "Code must consist of >= 3 unique characters." suggests all characters of the program should be unique, while you only require to have at least 3 distinct characters. \$\endgroup\$ – Grzegorz Oledzki Jul 9 at 19:22
  • 4
    \$\begingroup\$ @Belhenix Fewer than three unique characters allows solutions as simple as 121 for a great many languages. \$\endgroup\$ – Khuldraeseth na'Barya Jul 9 at 19:32
  • 2
    \$\begingroup\$ If anyone can find a stack-based language that uses - for negation and implicitly prints with a linefeed, \n1- is a three-byter. My search has so far been fruitless. \$\endgroup\$ – Khuldraeseth na'Barya Jul 9 at 19:35
  • 3
    \$\begingroup\$ @Belhenix Whitespace is certainly possible, it has enough unique valid characters (space, linefeed, tab). \$\endgroup\$ – bigyihsuan Jul 9 at 19:46
  • 2
    \$\begingroup\$ Can't change it now with 58 answers, but requiring "first letter of code must be different from last letter of code" would have ruled out a lot of trivial answers, including the current top answer. That may have been the intent of ">= 3 unique characters", but that requirement isn't actually very hard. \$\endgroup\$ – manassehkatz Jul 10 at 14:10

96 Answers 96

3
\$\begingroup\$

33, 9 bytes

a"a\\a"pa

The a's do nothing here, they're essentially NOPs in this code to make it shorter. My original thought was "p\\\""p, but that's 8 bytes, so it needs to print another \, making it 10 bytes "p\\\\\""p

This is a language I did create, but I made it legitimately, so I hope it's within the rules.

\$\endgroup\$
3
\$\begingroup\$

C (gcc), 21 bytes


main(){puts("}u");;}

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Print the last, middle, and first character of your program's source code, in that order. You're printing first, middle, last! \$\endgroup\$ – wastl Jul 9 at 13:53
  • 1
    \$\begingroup\$ oops, I just realized that. \$\endgroup\$ – Johan du Toit Jul 9 at 13:54
  • 1
    \$\begingroup\$ If there is an even number of characters, you need two middle characters. (sorry ...) \$\endgroup\$ – wastl Jul 9 at 14:03
2
\$\begingroup\$

Java 8, 11 bytes (as lambda function)

v->'"'+"'v"

Outputs "'v.

Try it online.

Java 8, 67 bytes (as full program)

interface M{static void main(String[]ar){System.out.print("}ni");}}

Outputs }ni.

Note the ar instead of a as argument. Otherwise the middle part had to be in, but printing that would make the size odd again, which would cause a paradox-loop..

Try it online.

\$\endgroup\$
  • 2
    \$\begingroup\$ @racraman Please don't go edit other peoples answers. If you have a golf to suggest, leave a comment stating so. Also, your golf on my answer was incorrect. Your code would output vv", but it's supposed to output it in reverse, so it should have output "vv. \$\endgroup\$ – Kevin Cruijssen Jul 11 at 10:18
2
\$\begingroup\$

R, 11 bytes

cat("))c" )

Try it online!

Outputs ))c. Space added to make the number of characters odd: otherwise we would need to output 4 characters, and that would make the code longer anyway.

\$\endgroup\$
  • \$\begingroup\$ Is this allowed? tio.run/##K/r/3y/R7/9/AA If so, you can cut it down to 3 bytes... \$\endgroup\$ – Sumner18 Aug 20 at 14:33
  • \$\begingroup\$ @Sumner18 I don't think it's allowed, because the initial [1] in the output counts. And maybe the trailing newline as well... \$\endgroup\$ – Robin Ryder Aug 21 at 11:48
2
\$\begingroup\$

HQ9+ 4 characters

+AQ+

Explanation:

+ ; increment accumulator
A ; nop
Q ; print itself
+ ; increment accumulator
\$\endgroup\$
  • 1
    \$\begingroup\$ Code must consist of >= 3 distinct characters \$\endgroup\$ – Draco18s Jul 9 at 18:32
  • \$\begingroup\$ @Draco18s thanks, I missed that part of the rule. I think I fixed it \$\endgroup\$ – Helena Jul 9 at 18:54
2
\$\begingroup\$

Forth (gforth), 9 bytes

Prints an escape-supporting string.

.\"   ." 

Try it online


Also 9 bytes:

Prints three spaces.

 ."    " 

Try it online


9 bytes with Stack Underflow:

 ." .. ".

Try it online


The 2nd and 3rd solutions also work if you replace first quotations with ( and last quotes with ). Essentially, plenty of ways to do it in 9 bytes, but probably not any shorter.

Documentation

\$\endgroup\$
2
\$\begingroup\$

Charcoal, 7 bytes

←´←´´´X

Try it online! The final X could be any byte in the Charcoal code page except 0xFF and the two already in use. Works by printing the desired characters leftwards. Alternative approach, also 7 bytes:

←”y←←”y

Try it online! The final y could be any ASCII character but I picked y because of the symmetry. Works by printing two s leftwards so that the final character gets printed at the start of the output.

\$\endgroup\$
2
\$\begingroup\$

Forth (gforth), 13 bytes

: f ." ; :" ;

Try it online!

Code Explanation

: f         \ start a new word definition
  ." ; :" ; \ print "; :"
;           \ end the word definition
\$\endgroup\$
2
\$\begingroup\$

AppleScript, 4

1021

Outputs the last char (1), the middle chars (02), and the first char (1).

Any four-digit number with the same first and last digits and different middle digits works.

\$\endgroup\$
  • \$\begingroup\$ 2 Distinct characters are a requirement \$\endgroup\$ – Nick Kennedy Jul 9 at 13:42
  • 1
    \$\begingroup\$ @LuisfelipeDejesusMunoz Does this edit qualify? \$\endgroup\$ – a stone arachnid Jul 10 at 4:00
2
\$\begingroup\$

PowerShell, 7 bytes

Another trivial solution. The first and the last lines contains LF.


"`nn"

Try it online!


PowerShell, 9 bytes

non-trivial, no byte sequence hacks. The first line contains LF only. The second line starts with a space.


 echo hh

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Japt, 5 bytes

Inspired by my JavaScript solution.

N'a*N

Try it

\$\endgroup\$
  • 1
    \$\begingroup\$ Ah-ha! I knew there had to be a 5 byter! Nice work. \$\endgroup\$ – Shaggy Jul 11 at 21:04
2
\$\begingroup\$

Kotlin, 39 25 bytes

fun main(){print("}rf")
}

Try it online!

Edit: -14 bytes thanks to @daniero

\$\endgroup\$
  • \$\begingroup\$ main doesn't need parameters, you can drop 15 bytes \$\endgroup\$ – daniero Jul 10 at 18:42
  • \$\begingroup\$ @daniero Cool, didn't realize that - thanks! (Only dropped 14 bytes and added an extra new line because if otherwise id have to print 4 characters) Also kinda cool that just by chance it still had the same output \$\endgroup\$ – Quinn Jul 10 at 18:46
2
\$\begingroup\$

INTERCAL, 65 bytes

PLEASE,1<-#3DO,1SUB#1<-#246DON'TPARSE!!
DO READ OUT ,1
DO GIVE UP

Try it online!

Padding the second half of the program to make the output PPP seems to be shorter than printing multiple distinct characters.

PLEASE ,1 <- #3         Declare that the length of the uint16 array ,1 is 3.
DO ,1 SUB #1 <- #246    Make the first element of ,1 246. (The other elements are 0.)
DON'T PARSE!!           This statement is ignored and nonsense.
DO READ OUT ,1          Print ,1 using C-INTERCAL's "Turing Tape" I/O.
DO GIVE UP              End the program.

This one almost works for 35 bytes, but it prints a space before the first newline:


PLEASE       READ OUT#500DOGIVEUP

\$\endgroup\$
2
\$\begingroup\$

Stax, 5 bytes


.PPP

Run and debug it at staxlang.xyz!

The leading linefeed does nothing. .PP pushes the string PP, and the final P prints it with a trailing newline. The last character is P, the middle character is the first P, and the first character is a linefeed.

The implicit print's trailing linefeed invalidates the 4-byte solutions 1231 and .S.S (adapted from Weijun Zhou's quine).

\$\endgroup\$
2
\$\begingroup\$

Keg, 7 5 bytes

1\':'

This prints ''1, which are the respective characters.

No Try It Online available for Keg.

Here is an uninteresting 4-byte answer:

1231
\$\endgroup\$
  • \$\begingroup\$ Good to see Keg standing up to 05AB1E in code golf! \$\endgroup\$ – Jono 2906 Jul 11 at 23:44
  • \$\begingroup\$ would abca also work as an uninteresting answer? \$\endgroup\$ – Jono 2906 Jul 13 at 5:18
  • \$\begingroup\$ Yes. I am trying to keep this simple, so I will not add this to the answer. \$\endgroup\$ – A _ Jul 13 at 5:21
2
\$\begingroup\$

C++ (clang) (lambda expression), 17 bytes

[]{return "}n[";}

Try it online!


C++ (clang) (full program), 47 43 bytes


#import<ios>
int main() {std::puts("}n");}

Try it online!

 

Unfortunately had to leave an extra space in both of the solutions, to make them have an odd number of characters.

\$\endgroup\$
2
\$\begingroup\$

Python 3 12 13 bytes

input(r')ri')
\$\endgroup\$
2
\$\begingroup\$

Bitwise Cyclic Tag But Way Worse, 26 bytes

ÿ1111111122ÿ2000000002ÿ

Outputs ÿ ÿ ÿ. 26 bytes since ÿ is considered 2 bytes in UTF-8.

Try it Online!

\$\endgroup\$
2
\$\begingroup\$

Cubix, 9 bytes


oN/
@oo

Try it online!

Reasonably boring one. Since the newlines in the first, middle and last positions are ignored by the interpreter the code wraps onto the following cube. Spaces could be used as well. eg oS/ @oo

  o
N / @ o
  o

Watch it run

  • N Pushs 10 (newline) onto the stack.
  • / redirects around the cube.
  • ooo outputs the newline 3 times.
  • /@ redirects again and halts the program
\$\endgroup\$
2
\$\begingroup\$

Lost, 21 bytes

v<<<<<>>>>>
>%?"v>@"@

Outputs: v>@.

Try it online or verify that it's deterministic.

Explanation:

Explanation of the language in general:

Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that both the start position AND starting direction it travels in is completely random. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky.

A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up/north, down/south, left/west, or right/east.

In Lost you therefore want to lead everything to a starting position, so it'll follow the designed path you want it to. In addition, you'll usually have to clean the stack when it starts somewhere in the middle.

Explanation of the program:

All arrows, including the >v in the string, will lead the path towards the leading > on the second line. From there the program flow is as follows:

  • >: travel in an east/right direction
  • %: Put the safety 'off'. In a Lost program, an @ will terminate the program, but only when the safety is 'off'. When the program starts, the safety is always 'on' by default, otherwise a program flow starting at the exit character @ would immediately terminate without doing anything. The % will turn this safety 'off', so when we now encounter an @ the program will terminate (if the safety is still 'on', the @ will be a no-op instead).
  • ?: Clean the top value on the stack. In some program flows it's highly likely we have a partial string on the stack, so we use this to wipe the stack clean of that potential string.
  • ": Start a string, which means it will push the integer code-points of the characters used (rather similar as the Whitespace program).
  • v>@: Push the code-points for these characters, being 118 62 64 respectively
  • ": We're done pushing code-points of this string
  • @: Terminate the program if the safety is 'off' (which it is at this point). After which all the values on the stack will be output implicitly. Using the -A program argument flag these code-points will be output as characters instead.

Two things to note:

The top part could also have been v<<<<<<<< instead. Lost will wrap around to the other side when moving in a direction. So using v<<<<>>>> could be a slightly shorter path, and since it's the same byte-count anyway, why not use it. :)
Also, the first line contains an additional < and >. One of them is to avoid having the newline character as the middle of the program, which is rather difficult to output and would have only increased the byte-count. The second is to make the program length odd again, so we'd only have to output a single middle character instead of two.

\$\endgroup\$
1
\$\begingroup\$

JavaScript (Babel Node), 11 bytes

_=>(')\)_')

Try it online!

\$\endgroup\$
  • \$\begingroup\$ My approach: alert(")\"a") - sadly 2 Bytes longer with 13 Bytes \$\endgroup\$ – pixma140 Jul 9 at 14:26
  • \$\begingroup\$ 9 bytes using a similar trick you used in your PHP solution. \$\endgroup\$ – Oliver Jul 10 at 19:33
1
\$\begingroup\$

Elm 0.19, 11 bytes

f()="\"\\f"

Prints "\f. See it working here.

\$\endgroup\$
1
\$\begingroup\$

APL (Dyalog Unicode), 9 bytes

⎕←'''''⎕'

Try it online!

Both the last and middle characters are ', while the first is .

\$\endgroup\$
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 19 bytes


	OUTPUT = 'D='
END

Try it online!

Prints D=<newline>, using SNOBOL's trailing newline in OUTPUT.

D=

\$\endgroup\$
1
\$\begingroup\$

Lenguage, 292 2340 bytes

Thanks to Jimmy23013 for pointing out I need another 2048 bytes

2340 bytes of any character with the first, middle two and last characters being a null byte.

Prints 4 null characters.

Try it online in brainfuck

\$\endgroup\$
  • \$\begingroup\$ @jimmy23013 ok should be fixed now \$\endgroup\$ – Expired Data Jul 9 at 15:44
1
\$\begingroup\$

Haskell, 17 bytes

main=putStr"\"Sm"

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Identical with Damien's Haskell solution posted almost 2 hour 50 minutes earlier. \$\endgroup\$ – manatwork Jul 10 at 17:22
1
\$\begingroup\$

Retina 0.8.2, 7 bytes


01$*$$

Try it online! Retina 0.8.2 outputs a trailing newline by default, so the code starts with that. Conveniently, this also matches the default empty input, allowing the replace stage to get to work. It then suffices to come up with a string of even length > 2 that outputs the other 2 characters.

\$\endgroup\$
1
\$\begingroup\$

Retina, 7 bytes

((K`(`(

Try it online! Retina 1 does not output a trailing newline by default, but fortunately it has the K command which allows us to specify a constant string output. The grouping construct ( is used to increase the number of distinct characters to meet the minimum requirement.

\$\endgroup\$
1
\$\begingroup\$

Dodos, 22 bytes


	dot
	dot
0         0

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Runic Enchantments, 9 7 bytes

'@'':r@

Try it online!

-2 bytes by just using char literals. Outputs @''

\$\endgroup\$

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.