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

124 Answers 124

1
\$\begingroup\$

Pyth, 5 bytes


10 1

Prints 10 followed by a newline. Try it online!

Newlines normally print the next result followed by a newline, but at the start of a program it is essentially a no-op. 10 is the literal value, which is printed followed by a newline. The space before the 1 suppresses the usual implicit printing, so the final 1 is ignored.

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

Boolfuck, 29 21 bytes

;;;;;;;;;;;;;;;;;+

Outputs 3 null characters

Thanks to Jo King for the improved solution!

Try it online!

BitChanger, 23 bytes

<<<<<<<<<<}<<<}<}<}<

Very similar to the Boolfuck one: uses the fact the null characters require no bit changing to output with tape-based bit output

How it works:

           Used as it is simple to output
<<<<<<<<<< Moves over to one left of the I/O bit
}           Sets the I/O bit to one, for output
<<<         Moves over to the bit that performs I/O
}<}<}       Sets it to one 3 times, to output 3 null characters
<          I used < to waste one byte so it could be an odd number of bytes

Try it Online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Sure it matched the requirement “Code must consist of >= 3 unique characters.”? \$\endgroup\$
    – manatwork
    Jul 12 '19 at 16:08
  • \$\begingroup\$ Oh yeah, fixed it \$\endgroup\$
    – EdgyNerd
    Jul 12 '19 at 16:45
  • \$\begingroup\$ Oh, didn’t realise that. Does it auto fill the last byte of output to 8 bits? \$\endgroup\$
    – EdgyNerd
    Jul 13 '19 at 7:55
1
\$\begingroup\$

Octave, 15 bytes

fprintf(')(f' )

Try it online!

As far as I know, using fprintf is the only method of out that doesn't come with extraneous output.

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

Python 2, 12 bytes 11 bytes

Placeholder to make the leading newline visible

print"\"t"
\$\endgroup\$
4
  • 1
    \$\begingroup\$ This is 12 bytes and hence is even, so you must print the 6th and 7th character of your code, which is ' ' and '"' so you should print " "p not " p like you currently do. Also please consider adding a link to e.g. Try It Online. \$\endgroup\$ Jul 15 '19 at 10:19
  • 1
    \$\begingroup\$ It also prints an extra newline, which is not allowed. \$\endgroup\$
    – jimmy23013
    Jul 15 '19 at 11:50
  • \$\begingroup\$ This 11 byte solution may be valid. Do you agree? @jimmy23013 \$\endgroup\$ Jul 15 '19 at 14:27
  • \$\begingroup\$ @ExpiredData Yes it works. \$\endgroup\$
    – jimmy23013
    Jul 15 '19 at 14:51
1
\$\begingroup\$

Rust (closure), 9 bytes

|| ";;|";

Try it online!


Rust (full program), 25 bytes

fn main(){print!("}}if")}

Try it online!

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

Pip, 15 bytes

O"}"xxL1{O"1O"}

Needs more golfing

Try it online!

Pip, 9 bytes


O"nn"x
n

shorter version with newline

Try it online!

Pip, 8 bytes

1x000Oh1

another one

Try it online!

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

Ohm v2, 5 bytes

…Lo…L

Try it online!

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

ink, 5 bytes


/a//

Prints /a and a newline

Try it online!

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

DOS COM x86 binary

% xxd test.com
00000000: 31c9 4b88 2f80 ffef 75f8 8007 30b4 028a  1.K./...u...0...
00000010: 17cd 2180 3f00 7503 e905 00fe 0fe9 f3ff  ..!.?.u.........
00000020: b402 8a17 cd21 8007 20b4 028a 17cd 2190  .....!.. .....!.
00000030: cd20 4b53 20                             . KS
\$\endgroup\$
1
\$\begingroup\$

x86-64 (Mac OS), 35 bytes

b8 04 00 00 02 bf 01 00 00 00 48 be 20 00 00 00
00 00 00 00 ba 03 00 00 00 0f 05 48 31 c0 c3 00
b8 00 b8

can be disassembled to:

[bits 64]

section .text
  global _main

_main:
  mov rax, 0x2000004
  mov rdi, 1
  mov rsi, x
  mov rdx, 3
  syscall
  xor rax, rax
  ret

section .data
  x: db 184, 0, 184

and compiled with:

$ nasm -fmacho64 FILE.asm
$ ld -fSystem FILE.asm

then run

$ ./a.out
<0xb8><0x00><0xb8>
\$\endgroup\$
1
\$\begingroup\$

Python 3, 13 bytes

print(')\'p')

Try it online!

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

Python 3, 13 bytes

This should suffice. Although it has a new line at the end of the output. There is a space in between print and '(' to make the total count of characters odd.

print (')(p')

Try it online!

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

W, 5 bytes


'+:+

Explanation

     % Newline (no-op)
'+   % The addition operator
  :+ % Multiply the character twice
     % Print with a newline
```
\$\endgroup\$
1
\$\begingroup\$

7, 11 characters

57125574032

Try it online!

Prints 255.

Explanation:

The program pushes 5|7255|4632 onto the frame (which starts with ||). Then, the last section of the frame (4632) is executed.

4 swaps the last two sections, and adds another bar between them. The frame is now ||5|4632||7255.

6 pacifies the last section of the frame by converting the active commands 7255 (shown in bold) to their passive equivalents 1255, and removing the bar before it. The frame now looks like ||5|4632|1255.

3 outputs the last section of the frame (1255) and discards the last two sections. The initial 1 means "print the rest unchanged", so 255 is printed. Then, the last two sections are discarded, leaving ||5 on the frame.

2 duplicates the last section of the frame, leaving ||5|5. There are no more characters left on the command list, so the last section of the frame (5) is executed.

5 moves the last section of the frame (which is another 5) to the start of the command list to be executed immediately, and then discards it. This leaves ||5 on the frame.

This happens again, leaving 5 on the command list and | on the frame.

The last 5 moves the last section of the frame (i.e. nothing) to the command list, leaving an empty command list and an empty frame. This causes the program to exit successfully.

Notes:

  • The 57 at the beginning and the 2 at the end are included because without them, one of the first, middle, or last characters would have been a 7, and printing 7 is hard.

  • The program can fit into 4 bytes, but the question asks to minimize characters.

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

Turing Machine Code, 29 bytes

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

Try it online!

Prints '210'.

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

Python 3, 13 bytes

print(")\"p")

Try It Online!

Having " as the middle char is lucky, because then I can balance the parity of the code because it requires an escape sequence.

There's a few more Python 3 13-byters, so I imagine this is the shortest possible solution. I don't there's a shorter solution with exit(), which prints to STDERR.

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

Width, 7 bytes

GAPSfeW

Try it online!

Outputs through STDERR.

I used a G to start the string. The ID of G is 39, which turns into eW. The ID of W is 55, which turns into AP. Then I just used Ai which is 50, and checked how close it was to A, saw it became R, then used Sf, which is 51, and becomes S.

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

Grok, 11 bytes

iq i`  wwwq        # Prints "q i"
\$\endgroup\$
1
\$\begingroup\$

Scratch, 23 bytes

when gf clicked
say[wcw
\$\endgroup\$
1
\$\begingroup\$

Racket, 15 bytes

(display "(y)")

Try it online!

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

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\$
1
\$\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\$
0
\$\begingroup\$

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

  • Filename: O.ooo.o.O
  • Content: empty
\$\endgroup\$
0
\$\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\$
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\$

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.