75
\$\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

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=188005;
var OVERRIDE_USER=78850;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(d,e){return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){answers.push.apply(answers,d.items),answers_hash=[],answer_ids=[],d.items.forEach(function(e){e.comments=[];var f=+e.share_link.match(/\d+/);answer_ids.push(f),answers_hash[f]=e}),d.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){d.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),d.has_more?getComments():more_answers?getAnswers():process()}})}getAnswers();var SCORE_REG=function(){var d=String.raw`h\d`,e=String.raw`\-?\d+\.?\d*`,f=String.raw`[^\n<>]*`,g=String.raw`<s>${f}</s>|<strike>${f}</strike>|<del>${f}</del>`,h=String.raw`[^\n\d<>]*`,j=String.raw`<[^\n<>]+>`;return new RegExp(String.raw`<${d}>`+String.raw`\s*([^\n,]*[^\s,]),.*?`+String.raw`(${e})`+String.raw`(?=`+String.raw`${h}`+String.raw`(?:(?:${g}|${j})${h})*`+String.raw`</${d}>`+String.raw`)`)}(),OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(d){return d.owner.display_name}function process(){var d=[];answers.forEach(function(n){var o=n.body;n.comments.forEach(function(q){OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>")});var p=o.match(SCORE_REG);p&&d.push({user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link})}),d.sort(function(n,o){var p=n.size,q=o.size;return p-q});var e={},f=1,g=null,h=1;d.forEach(function(n){n.size!=g&&(h=f),g=n.size,++f;var o=jQuery("#answer-template").html();o=o.replace("{{PLACE}}",h+".").replace("{{NAME}}",n.user).replace("{{LANGUAGE}}",n.language).replace("{{SIZE}}",n.size).replace("{{LINK}}",n.link),o=jQuery(o),jQuery("#answers").append(o);var p=n.language;p=jQuery("<i>"+n.language+"</i>").text().toLowerCase(),e[p]=e[p]||{lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p}});var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o){return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0});for(var l=0;l<j.length;++l){var m=jQuery("#language-template").html(),k=j[l];m=m.replace("{{LANGUAGE}}",k.lang).replace("{{NAME}}",k.user).replace("{{SIZE}}",k.size).replace("{{LINK}}",k.link),m=jQuery(m),jQuery("#languages").append(m)}}
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 

\$\endgroup\$
12
  • 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\$ Jul 9, 2019 at 19:22
  • 4
    \$\begingroup\$ @Belhenix Fewer than three unique characters allows solutions as simple as 121 for a great many languages. \$\endgroup\$ Jul 9, 2019 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\$ Jul 9, 2019 at 19:35
  • 3
    \$\begingroup\$ @Belhenix Whitespace is certainly possible, it has enough unique valid characters (space, linefeed, tab). \$\endgroup\$
    – bigyihsuan
    Jul 9, 2019 at 19:46
  • 3
    \$\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\$ Jul 10, 2019 at 14:10

143 Answers 143

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

Haskell, 19 bytes


main=($LT)print--L

Try it online! Outputs LT<newline>.

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

C#, 71 bytes

public class P{public static void Main(){System.Console.Write("pa}");}}

Try Online
I don't think I need to explain anything here

\$\endgroup\$
1
  • \$\begingroup\$ The program should output the last, middle, and first characters, in that order. \$\endgroup\$ Jul 12, 2022 at 9:44
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\$
2
\$\begingroup\$

6502, 17/21 bytes

6502: 17 bytes if running in zero page

For initial testing I used Py65, a 6502-based microcomputer simulator written in Python. Starting Py65 with the command-line parameter -o ff moves the character output port to zero page address $FF, shaving three bytes from the code.

The program must be loaded and run at $0000, to guarantee outputing the correct three characters (in order) from the program with values 00 B5 A5.

Here are the program bytes and their respective disassembly view in Py65:

.mem 0000:0010
0000:  a5  10  85  ff  a9  11  4a  aa  b5  00  85  ff  a5  00  85  ff  00

.d 0000:0010
$0000  a5 10     LDA $10
$0002  85 ff     STA $ff
$0004  a9 11     LDA #$11
$0006  4a        LSR A
$0007  aa        TAX
$0008  b5 00     LDA $00,X
$000a  85 ff     STA $ff
$000c  a5 00     LDA $00
$000e  85 ff     STA $ff
$0010  00        BRK

6502: 21 bytes if running outside zero page

Four additional bytes are required to allow the program to run outside of zero page. Three of the those bytes are the change in the LDA (load accumulator) instructions from zero page to absolute addressing. The fourth is the addition of a NOP (no operation) instruction, to maintain an odd number of bytes in the program.

This version of the program must be loaded and run at $0300, to guarantee outputing the correct three characters (in order) from the program with values 00 00 AD.

Here are the program bytes (character values) and their respective disassembly view:

.mem 0300:0314
0300:  ad  14  03  85  ff  a9  15  4a  aa  bd  00  03  85  ff  ad  00  03  85
0312:  ff  ea  00

.d 0300:0314
$0300  ad 14 03  LDA $0314
$0303  85 ff     STA $ff
$0305  a9 15     LDA #$15
$0307  4a        LSR A
$0308  aa        TAX
$0309  bd 00 03  LDA $0300,X
$030c  85 ff     STA $ff
$030e  ad 00 03  LDA $0300
$0311  85 ff     STA $ff
$0313  ea        NOP
$0314  00        BRK

6502: 21 bytes if running on an Apple II

We've come this far, so let's plop this baby on an Apple II. I don't normally tote around my Apple //c anymore, so I used a2ix on my Android phone.

Instead of sending characters to an addressed port, they will go to COUT (character output), a routine in system ROM.

$0300 is the usual spot for small assembly routines, so that's where I'll enter and list it. Running it yields a flashing space (60), inverse N (0E), and a normal " (A2). On the Apple II, ASCII characters are remapped across the 256-character range to achieve different character effects in text mode.

*300: A2 14 20 0E 03 A9 15 4A AA 20 0E 03 A2 00 BD 00 03 20 ED FD 60

*300L

0300-   A2 14       LDX   #$14
0302-   20 0E 03    JSR   $030E
0305-   A9 15       LDA   #$15
0307-   4A          LSR
0308-   AA          TAX
0309-   20 0E 03    JSR   $030E
030C-   A2 00       LDX   #$00
030E-   BD 00 03    LDA   $0300,X
0311-   20 ED FD    JSR   $FDED
0314-   60          RTS

Relocating this to a free area of zero page (good luck!) would not yield any byte savings. While the absolute indexed LDA (load accumulator) at $030E could be switched to its zero page indexed counterpart to save one byte, an NOP (no operation) would have to be added to avoid additional code to support print two middle characters.

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

05AB1E, 5 bytes

×'×3×

Try it online!

×   push a string of nothing, repeated nothing times (in other words, push an empty string)
'×  push "×"
3×  push "×", repeated 3 times
    implicitly print top of stack
\$\endgroup\$
2
\$\begingroup\$

AWK, 17 bytes

BEGIN{print"}iB"}

Try it online!

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

naz, 28 24 bytes

0a9a3a9m3a2o0a0a0a0a0m2o

Explanation

0a9a3a9m3a2o # Output "o" twice
0a0a0a0a     # Padding bytes
0m2o         # Output "0" twice

Original 28-byte solution: 0a9a3a9m3a1o0a0a0a9s5s1o0m2o

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

Brainetry, 181 bytes

This program starts and ends with an upper case L and also has it in the middle of its source code. This golfed version is based off of the program that comes after it.

To try this online, follow this repl.it link, paste my source code in the btry/replit.btry file and hit the green "Run" button.

L b
a b c d
a b c d e f g h
a b c d
a b c
a b c d e f g h
a b c d e
a b c
a b c d e f g h L
a b
a b
a b c d
a b c d
a b c d e f g h i
a b c
a b c d e f g
a b c d e f g
a b c d e f L

The verbose version also starts and ends with an uppercase L and has one of those in the exact middle of its source code.

Lo and
behold: this program has
a self referential property! This code prints its
first, middle and last
chars! How nice!
Of course I cheated a little and made
this program in such a
way that all
3 of those chars are the upper case L,
which I
also had
to properly place in
the middle of this
text to make sure they appeared in those positions.
A bit of
luck and a bit of mathematics allowed
me to accomplish this feat. Let me
check it... Woops, missed by one... LOL
\$\endgroup\$
2
\$\begingroup\$

Turing Machine Code, 29 bytes

0 * 2 r 1
1 * 1 r 2
2 * 0 * 2

Try it online!

Prints '210'.

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

Jelly, 4 bytes

5235

Try it online!

pretty simple, no explination needed

\$\endgroup\$
2
  • \$\begingroup\$ ah i see... i need to learn to read that English stuff 😅 \$\endgroup\$
    – Baby_Boy
    Sep 8, 2021 at 13:05
  • \$\begingroup\$ @AaronMiller general question what should i do if a question is not valid? do i delete or leave it? \$\endgroup\$
    – Baby_Boy
    Sep 8, 2021 at 13:06
2
\$\begingroup\$

Malbolge, 67 bytes

Outputs n D. Eventually I thought a space is really necessary.

D'`_$"\\[||98V6Bu@tOq<.'98*ZjE&fe {Ab~,v*)]xZvonsl2ponmfN+cba`ed]#n

Try it online!

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

GNU dc, 5 bytes

0p
n0

Try it online!

Pushes 0 to the stack, prints 0 with a new line, prints 0 without a new line and again pushes 0 to the stack.

n is a GNU implementation. Might not work with other versions.

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

Lexurgy, 15 bytes

This was surprisingly difficult. Outputs a>=a.

abc:
*=>a\>\=a
\$\endgroup\$
0
2
\$\begingroup\$

Pyramid Scheme, 115 bytes

   ^     ^
  / \   / \
 /out\ /out\
^-----^-----
-^   ^-
 -^ ^-
  -^-
  / \
 /chr\
^-----
-^
 -^
 / \
/32 \
-----  

Try it online!

The middle character is the space after the ^ on the fifth line. Prints three spaces.

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

Zsh, 9 bytes

print ptp

Attempt This Online!

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

Pip, 7 bytes


R"R " 

Attempt This Online! (Note the trailing space)

Explanation

\nR"R "   ; Full program
\n        ; No-op
   "R "   ; The string "R "
  R       ; Reversed
          ; No-op
          ; Implicit output
          ; (with newline)
\$\endgroup\$
2
\$\begingroup\$

Itr, 5 characters (6 bytes)

×'×3×

online interpeter

Explanation

×'×3×
×     ; call × on the first two arguments (0 by default) and ignore the result
 '×   ; the character ×
   3× ; repeated 3 times
\$\endgroup\$
1
\$\begingroup\$

Elm 0.19, 11 bytes

f()="\"\\f"

Prints "\f. See it working here.

\$\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\$
0
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\$
1
  • \$\begingroup\$ @jimmy23013 ok should be fixed now \$\endgroup\$ Jul 9, 2019 at 15:44
1
\$\begingroup\$

Haskell, 17 bytes

main=putStr"\"Sm"

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Identical with Damien's Haskell solution posted almost 2 hour 50 minutes earlier. \$\endgroup\$
    – manatwork
    Jul 10, 2019 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\$
1
\$\begingroup\$

Gema, 13 characters

\A=l\\\\@fail

Try it online!

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

Brachylog, 7 bytes

"w\\""w

Try it online!

Thanks to Shaggy for correcting this to comply with the challenge specification.

Boring string literal, except thanks to the weird way Brachylog string literals work, the escaped backslash also still escapes the quote afterwards, so it's not actually that boring.

\$\endgroup\$
2
  • \$\begingroup\$ Ah, you're right, I didn't read the spec closely enough. Thanks! \$\endgroup\$ Jul 9, 2019 at 20:11
  • 1
    \$\begingroup\$ Coincidentally, I'd just added your original version as an alternative to my Japt solution - scrolled down and thought I'd found a polyglot! \$\endgroup\$
    – Shaggy
    Jul 9, 2019 at 20:37
1
\$\begingroup\$

Japt, 7 bytes

''ixi''

Try it

''ixi''
''          :Literal "'"
  i         :Prepend
   x        :  Literal "x" (any lowercase letter would work. Except i, of course)
    i       :  Prepend
     ''     :    Literal "'"

Alternatives

"\"ww"w

Try it


Riii'R

Try it

"Q\""+Q

Try it

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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