60
\$\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-Reinstate Monica Jul 10 at 14:10

96 Answers 96

1
\$\begingroup\$

Gaia, 5 bytes


⌋ ”⌋

Try it online!

The is just there as a no-op.

            % helper function
⌋ ”⌋         % main function: push "⌋ " and convert to lowercase
            % then implicitly print with trailing newline
\$\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\$
  • \$\begingroup\$ Ah, you're right, I didn't read the spec closely enough. Thanks! \$\endgroup\$ – Unrelated String Jul 9 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 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\$
1
\$\begingroup\$

HTML, 4 bytes

^db^

^<X>_<X>^

I'm not sure if this is cheating... Really.

First one also worked as PHP or Text.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's my bad that not creating a page for txeT before this challenge... \$\endgroup\$ – tsh Jul 10 at 3:01
1
\$\begingroup\$

Lua, 31 13 bytes

print (')(p')

Prints )(p

Try it online!

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

dc, 9 characters

[PP]P91aP

Sample run:

bash-5.0$ dc -e '[PP]P91aP'
PP[

Try it online!

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

MarioLANG, 53 bytes

+>(-[!)
+"===#+
++
++
++
++
++
 +
)!)  <...
=#==="==+

Try it online!

Output: +++. The 27th character is one of the + characters in the second column of the code.

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

cQuents, 8 bytes

1#11,2&1

Try it online!

Outputs 11,1.

Explanation

1             Prepend 1 to the output
 #11,2        Default input is `11, 2`
      &       Output as many terms as the last input, comma seperated
       1      Each term equals 1

So first 1 is prepended, then the input becomes 11,2. Then, we output 2 terms comma separated, which is 1,1, so the final output is 11,1.

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

PowerShell, 8 7 bytes


' D'  

Try it online!

Notice the two spaces after the last quote. Forgot that using implicit output puts a newline afterwards. Fixing that saved a byte though.

Alternative 7 byte solution with 3 unique chars by mazzy


"`"`""

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Actually, 1231 doesn't work since PowerShell outputs a trailing newline by default. 1231 only works in languages with implicit output without trailing newline. \$\endgroup\$ – Kevin Cruijssen Jul 9 at 17:06
  • 1
    \$\begingroup\$ @KevinCruijssen Yeah, didn't even think about that even though my current answer takes it into account. Purge inbound. \$\endgroup\$ – Veskah Jul 9 at 17:15
  • 2
    \$\begingroup\$ it seems to me that the output should be '''LF for this source code \$\endgroup\$ – mazzy Jul 10 at 5:56
  • 1
    \$\begingroup\$ @mazzy One day I'll post an answer that's up to spec. \$\endgroup\$ – Veskah Jul 10 at 12:04
  • 2
    \$\begingroup\$ nice. 7 bytes, 3 unique chars :) \$\endgroup\$ – mazzy Jul 10 at 14:48
1
\$\begingroup\$

Wolfram Language (Mathematica), 9 bytes


Print@nn

Try it online!

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

PHP, 11 bytes

<?=';\\<';;

Try it online!

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

Perl 5, 11 bytes

say "\"\\s"

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ This violates the rule "Output must not contain any trailing whitespace. However, if whitespace is a first, middle, or last character, it must be printed as such." \$\endgroup\$ – Chris Jul 11 at 12:29
  • \$\begingroup\$ @Abigail That still breaks the same rule about trailing whitespace. \$\endgroup\$ – Chris Jul 30 at 10:24
1
\$\begingroup\$

BitCycle, 5 bytes


11!1

Try it online!

Outputs 11 with a trailing newline. Only the first pair of 1s is actually printed.

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

LOLCODE, 27 bytes

HAI 1
VISIBLE "E H"
KTHXBYE

Try it online!

Trivial answer in LOLCODE. The 14th character is the space just before the string literal.

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

Perl 5, 11 bytes


 say '; ';

Try it online!

Note the initial newline and the trailing space. Outputs

; 

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

Bash, 9 11 9 bytes

First attempt:

echo e\ o

Output

e o

Second attempt:

echo -n e-e

Output:

e-e

Third attempt


echo  oo

Note the leading newline and the double space

Output:

oo

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to codegolf.se. It should print in the order of the last, middle and first character, o e for your current code. \$\endgroup\$ – jimmy23013 Jul 10 at 15:19
  • 2
    \$\begingroup\$ Also “Output must not contain any trailing whitespace.” I'm afraid your contains, actually outputs 4 characters instead of 3. \$\endgroup\$ – manatwork Jul 10 at 15:26
  • \$\begingroup\$ Now is correct, but became exact copy of Grzegorz Oledzki's Bash solution posted yesterday. \$\endgroup\$ – manatwork Jul 11 at 13:06
1
\$\begingroup\$

SmileBASIC, 7 bytes

?":b?":

Output: :b?

(Probably works in most BASIC dialects) The middle character can be anything except ", LF, and CR.

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

F#, 13 bytes (characters)

So many esoteric languages that seem to be made specifically for code golfing… let's try a terse but 'normal' language like F#, where the following line (without a trailing newline) has 13 characters (13 bytes if the source file is saved as ANSI text):

printf"\"\"p"

Output:

""p
\$\endgroup\$
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\$

Zsh, 9 bytes



<<<\<\<

Try it online!

Hexdump, with first/middle/last bytes highlighted:

00000000: 0a0a 3c3c 3c5c 3c5c 3c                   ..<<<\<\<
          F^        M^        L^                   ^   ^   ^

Output is <<[newline].

\$\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\$
  • 1
    \$\begingroup\$ Sure it matched the requirement “Code must consist of >= 3 unique characters.”? \$\endgroup\$ – manatwork Jul 12 at 16:08
  • \$\begingroup\$ Oh yeah, fixed it \$\endgroup\$ – EdgyNerd Jul 12 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 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\$
1
\$\begingroup\$

Python 2, 12 bytes 11 bytes

Placeholder to make the leading newline visible

print"\"t"
\$\endgroup\$
  • 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\$ – Expired Data Jul 15 at 10:19
  • 1
    \$\begingroup\$ It also prints an extra newline, which is not allowed. \$\endgroup\$ – jimmy23013 Jul 15 at 11:50
  • \$\begingroup\$ This 11 byte solution may be valid. Do you agree? @jimmy23013 \$\endgroup\$ – Expired Data Jul 15 at 14:27
  • \$\begingroup\$ @ExpiredData Yes it works. \$\endgroup\$ – jimmy23013 Jul 15 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\$

Haskell, 19 bytes


main=($LT)print--L

Try it online! Outputs LT<newline>.

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

ink, 5 bytes


/a//

Prints /a and a newline

Try it online!

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

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.