77
\$\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\$ Commented 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\$ Commented 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\$ Commented Jul 9, 2019 at 19:35
  • 3
    \$\begingroup\$ @Belhenix Whitespace is certainly possible, it has enough unique valid characters (space, linefeed, tab). \$\endgroup\$
    – bigyihsuan
    Commented 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\$ Commented Jul 10, 2019 at 14:10

144 Answers 144

1 2 3 4
5
1
\$\begingroup\$

BRASCA, 5 bytes

9C9$9

Try it!

Explanation

9            - Push 9
 C           - Set implicit output to number mode
  9          - Push 9
   $         - Swap the two nines
    9        - Push 9
<implicit>   - Output stack
\$\endgroup\$
1
\$\begingroup\$

Vyxal D, 5 bytes


 ‛‛‛

Try it Online!

Note the trailing space and newline.

Simply pushes ‛‛, and prints with trailing newline.

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

Python 3, 13 bytes

print( ') p')

The last character is ')', the middle is number 7, a space and the first is the letter 'p'.

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

Julia 1.0, 13 bytes

most python answers work with julia too, but here are a couple very julian 13-byters

"s" |>show;""
"t|\""|>print

Try it online!

\$\endgroup\$
1
+100
\$\begingroup\$

Vyxal, 7 bytes

No flags used.

9 99J₴9

Explanation

9        - Push 9
  99     - Push 99
    J₴   - Concatenate and print
      9  - Pushes another 9, but it never gets used.

Try it Online!

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

Pari/GP, 13 bytes

print1(")("p)

Try it online!

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

Microscript II, 10 bytes

Welcome to Backslash Hell

"\"\\\\\""

I suspect that a shorter version is possible.

\$\endgroup\$
1
  • \$\begingroup\$ Would ` " a " ` with surrounding spaces be valid? \$\endgroup\$ Commented Jan 19, 2023 at 5:40
1
\$\begingroup\$

Flobnar, 7 bytes

0..0#@0

Try it online!

The character that is easiest to print is the digit 0. 5 bytes is impossible because it mandates three zero digits and a @ at one of the two positions (2nd or 4th), which makes the program print 0 only once. For 7 bytes, we skip a 0 with # and print zero twice using . (explicit decimal output); the third copy of 0 is produced as the value that @ evalautes to.

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

Thunno, \$7\log_{256}(96)\approx\$ 5.76 bytes



Z" rr

Attempt This Online!

Port of Kevin Cruijssen's 05AB1E answer.

Explanation

\n\nZ" rr  
\n\n       # no-ops
    Z" r   # 2-char string: " r"
        r  # reverse to get "r "
           # implicit output with newline 
\$\endgroup\$
1
\$\begingroup\$

Go, 25 bytes

func()string{return"}nf"}

Attempt This Online!

Function which returns a string.

Go, 35 bytes

import."fmt"
func f(){Print("} i")}

Attempt This Online!

Function which prints to STDOUT.

Go, 51 bytes

package main
import."fmt"
func main(){Print(`}
p`)}

Attempt This Online!

Full program which prints to STDOUT.

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

Python REPL, 5 bytes

122-1

yields 121.

This probably works with many other interactive environments as well, but this is the shortest I could think of.

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

Desmoslang, 9 Bytes

1OOO1ETG1

Outputs 111

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

Swift 5.9, 13 bytes


print (") ")

This is basically a Swift version of this Python answer by @TFeld. Prints the last character ")", the middle character " " (a space), and the first character "\n" (a newline, printed thanks to print(_:separator:terminator:)'s default terminator of "\n").

\$\endgroup\$
0
\$\begingroup\$

Pxem, Filename: 9 bytes + Content: 0 bytes = 9 bytes.

  • Filename: O.ooo.o.O
  • Content: empty
\$\endgroup\$
0
\$\begingroup\$

abcn, 15 bytes

a120gxgxnba98gx

Explanation :

a120                  --> sets stack at 120
gx                    --> convert to ASCII and print (120 ==> x) as you can see x is last char
gx                    --> convert stack 120 again to ASCII and print `x` mid char (7th) is x 
                      --> as well (a120gxg make 7 and nba98gx make 7 so we print x)
b                     --> stack set to -1 (useless just made so we print x twice and 
                      --> not have to add more bytes)
a98                   --> add to stack 98 (giving us 97)
gx                    --> convert to ASCII and print (97 == a) a is first char

prints xxa which is the right answer

\$\endgroup\$
0
\$\begingroup\$

Java (JDK), 9 bytes

$->"  $" 

Try it online!

\$\endgroup\$
4
0
\$\begingroup\$

CLC-INTERCAL, 67 bytes.

Outputs 1#D. It was difficult to adjest program length. Eventually I decided to do \#9; this caused no side effects.

DO;1<-#9\#9DO;1SUB#1<-#100DO;1SUB#2<-#374DO;1SUB#3<-#276DOREADOUT;1

Copy and paste to try it online!

\$\endgroup\$
0
\$\begingroup\$

FerNANDo, 53 bytes

Outputs aaa, but is it accepted...?

a a a
z a a z z z z a
z a a z z z z a
z a a z z z z a

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Ly, 9 bytes

'o:oo"'"o

Try it online!

I had some more interesting versions (IMO anyway), but they were longer. :)

 'o         - push "o" on the stack
   :        - duplicate top of stack
    oo      - print both "o" chars
      "'"   - load a doublequote on the stack
         o  - print it

Prints output oo"

\$\endgroup\$
0
\$\begingroup\$

DipDup, 7 bytes

a[aaa]a

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python 3, 15 15 bytes

print("  p")   

Try it online!

Previous answer(Incorrect)

print("pp ")

The answer is no longer pp (◞‸◟)

\$\endgroup\$
2
  • \$\begingroup\$ The question asks for last middle first, not first middle last. \$\endgroup\$ Commented May 11, 2022 at 20:00
  • \$\begingroup\$ @AndersKaseorg Thanks for pointing out, I have made the necessary changes \$\endgroup\$
    – Saphereye
    Commented May 12, 2022 at 2:45
0
\$\begingroup\$

Pascal, 41 characters

NB: Despite appearing that way the source code has no trailing newline:

program p(output);begin write('.gp')end .
\$\endgroup\$
0
\$\begingroup\$

Thunno 2, 5 bytes


` rr

Attempt This Online!

Port of Kevin Cruijssen's 05AB1E answer. Prints r \n.

Alternative 5 bytes:


12£1

Attempt This Online!

Port of Kevin Cruijssen's alternative 05AB1E answer. Prints 12\n.

\$\endgroup\$
0
\$\begingroup\$

COBOL, 67 B

The OpenCOBOL implementation does not seem to process non-lines (i. e. a character sequence that is not concluded by a newline character). Therefore the COBOL source code contains a newline character. However, I did not achieve printing a leading newline character (there was a space I could not get rid of). So I extended the source code with some syntactically acceptable junk. The 01 is not followed by a newline character.

000000 PROGRAM-ID.P.PROCEDURE DIVISION.DISPLAY"1I0"NO ADVANCING.
01

Output: 1I0

\$\endgroup\$
1 2 3 4
5

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.