Challenge:

In the programming language of your choice, take no input and output your programming language's name.

Fair enough, right?

Restrictions:

  • You can't use any character that is included in your programming language's name in your code. E.g., if I use Batch, I must not use the chars 'B' 'a' t' 'c' 'h' in my code. Note that this is case sensitive. I can still use the char 'b' because it's different from 'B'.
  • You can have "junk output" before or after the name of the language
  • Version number doesn't count as part of the name of the language. E.g., I can use the number 3 in the code in my answer if it's in Python 3
  • The output of the programming language name is not case sensitive.
  • Brute-forcing all possible letter combinations and hoping you get your language name is forbidden.

Example outputs: (let's say my programming language is called Language) (✔ if valid, else ✖)

  • Language
  • Body language is a type of non-verbal communication in which physical behavior, as opposed to words, is used to express or convey information. Such behavior includes facial expressions, body posture, gestures, eye movement, touch and the use of space.
  • Language 2.0 - © 1078 AD some company
  • foobar

This is thus shortest code wins.

  • 7
    The rule about case sensitive restrictions is very ambiguous. Which is the correct orthography: BASIC Basic or basic? I'm pretty sure I can find examples for all three. – Level River St Jan 24 '17 at 23:47
  • 6
    Obligatory "Just having your code be blank but have a flag like --version isn't allowed"? – Value Ink Jan 25 '17 at 0:00
  • 80
    Have case-insensitive output while banning the language name case-sensitively allows boring solutions that just output the language name case-swapped. – xnor Jan 25 '17 at 0:47
  • 2
    Does the output need to go to the screen/be printed, or can it be returned as well? – simbabque Jan 25 '17 at 13:48
  • 8
    You made a mistake by allowing users to output junk data. All they have to do is use a language where the compiler include the name whenever there's an error. It's cool but not the challenge I was hoping for – Lynob Jan 26 '17 at 8:23

114 Answers 114

Outputs to STDERR

Outputting to STDERR is now at +33/-21 as an allowed default, which is positive but contested. This is a CW answer to collect answers that just invoke an error in a language where error messages includes the language name.

Haskell, 1 byte

1

Error:

Parse error: naked expression at top level
Perhaps you intended to use TemplateHaskell

Lua, 1 byte

1

Error:

lua: .code.tio:1: syntax error near <eof>

(file name is unimportant)

Batch, 1 byte

~

Error:

'~' is not recognized as an internal or external command,
operable program or batch file.

tinylisp, 5 bytes

(c()1

Error:

Error: cannot cons to Int in tinylisp

R, 1 byte

)

Error:

Error: unexpected ')' in ")"

Java bytecode, 0 bytes

Error:

Exception in thread "main" java.lang.ClassFormatError: Truncated class file

Groovy, 1 byte

a

Note that a can be replaced with any other character

Error:

groovy.lang.MissingPropertyException: No such property: a ...

MATLAB, 1 byte

\

Error:

Error: Unexpected MATLAB operator.

PHP, 3 bytes

<?=

Error:

PHP Parse error:  syntax error, unexpected end of file in /home/runner/.code.tio on line 1

CJam, 1 byte

/

Error:

/
^
RuntimeException: The stack is empty
Java exception:
java.lang.RuntimeException: The stack is empty
    at net.aditsu.cjam.CJam.pop(CJam.java:75)
    at net.aditsu.cjam.Op2.run(Op2.java:10)
    at net.aditsu.cjam.Block.run(Block.java:304)
    at net.aditsu.cjam.CJam.runCode(CJam.java:210)
    at net.aditsu.cjam.CJam.main(CJam.java:240)

Twig, 2 bytes

Twig is a template language written in PHP. It's possible that this is a polyglot.

{{
{%
{#

Error:

PHP Fatal error:  Uncaught exception 'Twig_Error_Syntax' with message [...] in [...][...]:n:
Stack trace:
#0 [...]

The message varies depending on which program you choose.

S.I.L.O.S, 2 bytes

x+

Try it online! Trivially invokes undocumented behavior. Silos is the name of the language.

Python, 6 bytes

pYTHON

As the character restriction is case insensitive, and the output doesn't have to be in the correct case, this is a valid answer. The error message it produces is something like this:

Traceback (most recent call last):
  File ".code.tio", line 1, in <module>
    pYTHON
NameError: name 'pYTHON' is not defined

Try it online! (outputs to 'debug' tab)

JavaScript, 10 bytes

jAVAsCRIPT

This produces the following error message or similar in all environments:

ReferenceError: jAVAsCRIPT is not defined

QBIC, 6 bytes

?b(12)

In 6 bytes, we can put QBIC encountered error: 9 on the screen, signifying an out-of-bounds error.

ForceLang, 2 bytes

()

Error produced:

Exception in thread "main" lang.exceptions.IllegalInvocationException: null is not a function.
    at lang.ForceLang.parse(ForceLang.java:99)
    at lang.ForceLang.main(ForceLang.java:129)

Pip, 5 bytes

1~`[`

(Note: this works in the current version as of this writing, 0.17.09.01. No guarantees the interpreter won't change to handle this error differently in the future.)

Tries to regex match with a syntactically invalid pattern. The error produced will look something like this:

Traceback (most recent call last):
  File "/opt/pip/pip.py", line 221, in <module>
    pip(interactive=False)
  File "/opt/pip/pip.py", line 206, in pip
    state.executeProgram(tree, args)
  File "/opt/pip/execution.py", line 56, in executeProgram
    returnVal = self.functionCall(mainFunction, cmdLineArgs)
  File "/opt/pip/execution.py", line 368, in functionCall
    returnVal = self.getRval(returnExpr)
  File "/opt/pip/execution.py", line 235, in getRval
    expr = self.evaluate(expr)
  File "/opt/pip/execution.py", line 213, in evaluate
    result = opFunction(*args)
  File "/opt/pip/execution.py", line 1134, in FIRSTMATCH
    matchObj = regex.asRegex().search(str(string))
  File "/opt/pip/ptypes.py", line 175, in asRegex
    self._compiled = re.compile(pyRegex)
  File "/usr/lib64/python3.6/re.py", line 233, in compile
    return _compile(pattern, flags)
  File "/usr/lib64/python3.6/re.py", line 301, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib64/python3.6/sre_compile.py", line 562, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib64/python3.6/sre_parse.py", line 855, in parse
    p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib64/python3.6/sre_parse.py", line 416, in _parse_sub
    not nested and not items))
  File "/usr/lib64/python3.6/sre_parse.py", line 765, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/usr/lib64/python3.6/sre_parse.py", line 416, in _parse_sub
    not nested and not items))
  File "/usr/lib64/python3.6/sre_parse.py", line 523, in _parse
    source.tell() - here)
sre_constants.error: unterminated character set at position 8
  • 17
    Isn't the empty string contained in the language's name? :D – mbomb007 Jan 25 '17 at 15:08
  • 20
    The C and R ones are clever. – DLosc Jan 26 '17 at 7:10
  • 2
    @mbomb007 but it's not a character, therefore it's not a character included in the language's name. – immibis Jan 27 '17 at 4:26
  • The PHP version can be disabled, if I'm not mistaken. Using something like <?? will be more effective and can't be disabled. – Ismael Miguel Jan 27 '17 at 14:29
  • 5
    "Java bytecode, 0 bytes". First time I see Java triumphing above ALL of those other languages mentioned. :) – Kevin Cruijssen Jul 3 '17 at 11:26

SmileBASIC, 11 bytes

sPsET.,1474

Equivalent to SPSET 0,1474. Sets sprite 0 to definition 1474, which is the SmileBASIC logo.

Screenshot

MATL, 1 byte

Y

Output is through STDERR, which is allowed by default.

The output from the offline compiler is

Error using matl_parse (line 339)
MATL error while parsing: Y not recognized at position 1
Error in matl (line 234)
    S = matl_parse(s, useTags); 

Or try it online! (expand "debug" section).

  • 6
    Should you merge with this? – wizzwizz4 Jan 25 '17 at 18:31
  • @wizzwizz4 I'm not sure. I asked in chat and got these two replies, so it's not really clear – Luis Mendo Jan 25 '17 at 19:47
  • 1
    yeah but Y tho? – sagiksp Jan 26 '17 at 9:34
  • @sagiksp Anything that throws an error will do, such as X or Z. This is because X, Y or Z are prefixes of two-char function names, so a Y by itself is invalid – Luis Mendo Jan 26 '17 at 10:55

R, 1 byte:

T

T is an alias for the constant TRUE. So the output for the above is:

[1] TRUE

Since junk is allowed around the name, the “R” in there is the language name.

(As noted in a comment elsewhere, pretty much any single letter and many glyphs will work equally well because they trigger the message “Error: …”, which contains “r”.)

HTML, 24 20 bytes

&#72;&#84;&#77;&#76;


HTML, 16 bytes

As pointed out by @Bob, modern browsers will recognize HTML entities without semicolons, though it's technically invalid HTML. Of course, it's perfectly valid for code golf.

&#72&#84&#77&#76


HTML, 4 bytes

And of course, the uninteresting answer.

html


Also, see my CSS answer.

  • 3
    You can save four characters by using decimal instead: &#72;&#84;&#77;&#76;. You can save an additional four characters by dropping the semicolons, at the cost of being technically invalid HTML (but still working in modern browsers). – Bob Jan 25 '17 at 3:26
  • Why doesn't HTML count? – OrangeDog Jan 25 '17 at 13:51
  • 1
    @OrangeDog "You can't use any character that is included in your programming language's name in your code" – darrylyeo Jan 25 '17 at 18:39
  • But html should be valid, reducing the score by 12 bytes. – Christoph Jan 27 '17 at 11:09
  • 1
    @Clearer This is code golf! As long as it works in at least one environment, who cares whether W3C thinks it's valid? – darrylyeo Feb 15 '17 at 15:31

Vim, 0 bytes



When you start Vim, the editor displays a splash screen which looks like this:

Vim splash screen

You can see it says Vim here:

Vim splash screen with vim highlighted

Previous answer:

Vim, 1 byte

<Ctrl-C>

In Vim 8, pressing will display Type :quit<Enter> to exit Vim at the last line. I'm not completely sure if this counts.

  • 1
    It should count. Ctrl-C actually has its own ASCII code (code 3, also called ETX or "end of text"), so this is a pure-ASCII program (if not purely printable ASCII). You can use that to prove that the program's one byte long, and displaying text on screen counts. – user62131 Jan 25 '17 at 14:36
  • 4
    Since when is "vim" a programming language? – DepressedDaniel Jan 27 '17 at 3:26
  • 2
    @DepressedDaniel vim is actually a scripting language if you take a deeper look into the internals. All those fancy keystrokes are instructions => you're programming when you're controlling your editor. – bash0r Jan 27 '17 at 13:32
  • @DepressedDaniel is it turing complete? If it's not, I don't think it should count. – Clearer Feb 14 '17 at 1:45

Python, 15 bytes

Python 2 (15)

exec"\150elp()"

It concatenates the strings uses the octal 150 which is h and "elp()" and runs the result. This prints the help() command which says "Welcome to Python 3.5's help utility!", meeting the requirements.

Python 3 (17)

exec("\150elp()")

Try it online!

  • Not sure help counts, it only works in a REPL environment. – xnor Jan 25 '17 at 1:09
  • It still prints out the Python. That's all that's required. – user63571 Jan 25 '17 at 1:16
  • If it works in TIO surely it's a valid answer? – user63571 Jan 25 '17 at 1:22
  • 1
    Never mind, I was mistaken and it works as a program. Sorry about that. – xnor Jan 25 '17 at 1:22
  • 3
    p is allowed but P isn't. Rule 1. – user63571 Jan 25 '17 at 17:54

C, 0 bytes.

/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status

Try it online!

  • where is the name ? Or do you refer to the c characters in there ? – HopefullyHelpful Jan 26 '17 at 11:46
  • 3
    This should be marked as C (gcc), because other compilers have different messages. – orlp Jan 26 '17 at 12:47
  • Meh, your c's come from extremely implementation-dependent sources. Would have been nicer if you at least provoked a message that contains c in some boilerplate output. – DepressedDaniel Jan 27 '17 at 3:24
  • 1
    @DepressedDaniel undefined reference to 'main' – Loren Pechtel Jan 27 '17 at 5:59
  • @LorenPechtel Fair enough, missed that. – DepressedDaniel Jan 27 '17 at 6:02

Huh?, 0 bytes



(no, there's nothing in that code block)

The language is named for its output, so...

In the implementation I checked, the interpreter takes the length mod 8 of each line of a given file, and switches depending on the result. For zero, it prints Huh?. Since it strips trailing newlines, you could also do a 1 byte (\n) version.

Note that it's not outputting to stderr or caseswapping or any other trickery. It's just that Huh?'s very confused interpreter finally came in handy.

brainfuck, 54 bytes

+[[-<]-[->]<-]<.<<<<.>>>>-.<<-.<.>>.<<<+++.>>>---.<++.

Outputs brainfuck, assuming an 8-bit tape open on the left. Try it online!

As always, partial credits go to @primo's Hello, World! answer.

Alternatives with different casing

Brainfuck (62 bytes):

+[<-[-<]-[->]<<]<---.<<<<<<--.>>>-.<+.<.>---.<<+++.>>---.<---.

BrainFuck (68 bytes):

-[[-<]->+[->]<-]<<.<<<<<--.>>+.<-.+++++.>>>------.<<<<+++.>>++.<---.

V, 2 bytes

¬U

Try it online!

The obvious answer is:

év~

Try it online!

Which is "Insert the letter 'v', and toggle case". However, since you allow for junk output before/after the language name, this works too.

The ¬ command takes two characters for input, and inserts every ASCII character between them. If we don't supply the second character, it automatically defaults to ÿ (ASCII 0xff), so this program inserts every character in the latin1 encoding between U and ÿ.

MATLAB, 3 bytes

ver

Output is as follows. Irrelevant info has been replaced by [...]). Some parts of the output may change depending on version, installed toolboxes etc.

-----------------------------------------------------------------------------------------
MATLAB Version: 8.6.0.267246 (R2015b)
MATLAB License Number: [...]
Operating System: [...]
Java Version: Java 1.7.0_60-b19 with [...]
-----------------------------------------------------------------------------------------
MATLAB                                                Version 8.6         (R2015b)
Communications System Toolbox                         Version 6.1         (R2015b)
Curve Fitting Toolbox                                 Version 3.5.2       (R2015b)
[...]
Wavelet Toolbox                                       Version 4.15        (R2015b)
  • Uses a v and an e – user63571 Jan 25 '17 at 0:31
  • Your language is Octave, so you can't use v and e. – JungHwan Min Jan 25 '17 at 0:31
  • 5
    Woops. Corrected by changing language to Matlab (which was my initial intent anyway) – Luis Mendo Jan 25 '17 at 0:55

Python 2 (1 byte)

è

output...:

output

  • Are you sure this is only 1 byte? – Okx Jul 27 '17 at 22:38
  • Agreed. It's 2 bytes in UTF-8 – mbomb007 Oct 20 '17 at 13:48
  • The key is "non-ASCII" -- try 0xa0 (nbsp) or basically any other high byte you like and you'll get the same error! – John P Oct 20 '17 at 17:57
  • 1
    This is 1 byte in Win1252, which the error message shows this is using. – ATaco Oct 21 '17 at 5:04

><>, 12 10 bytes

"2,:o:2-o|

This will continually print ><> until the interpreter runs out of space.

Try it online!

12 byte version below for those who like a clean output. Recommended by Aaron (no error, 1 output)

":3+:o$1+oo;
  • Brilliant solution! – Emigna Jan 25 '17 at 14:14
  • @Emigna - Thanks, the final version was after a bunch of failed golfs but I quite like it because with the error it prints ><> and fish :D – Teal pelican Jan 25 '17 at 15:32
  • Nice one ! Here's a 14 bytes version which only prints once and doesn't errors out : "-o-o-o;_!\ _! – Aaron Jan 25 '17 at 16:37
  • @Aaron if you check the edit the first version did that at 12. I do like how clean yours looks though :) – Teal pelican Jan 26 '17 at 17:28
  • I like your 12 bytes version (the 10 bytes too :)), I think you should have left it included to your answer as an aside ("for those who like a clean output,[...]") ! – Aaron Jan 26 '17 at 17:32

Python, 27 53 49 48 45 bytes

-3 bytes from @wizzwizz4

exec eval('"IMpORT THIS".LOWER()'.swapcase())

Prints the following text, which has "Python" on the first line.

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
  • 1
    @Arnauld fixed! – Value Ink Jan 25 '17 at 0:27
  • 1
    HELP() or HELP(HELP) is shorter. – Gurupad Mamadapur Jan 25 '17 at 8:14
  • It doesn't matter if you swap the case of the import string, because you're making it lower-case anyway. -3 bytes. – wizzwizz4 Jan 25 '17 at 18:39
  • @GurupadMamadapur the Python 3 answer already covered it and better (pretty sure my code would be the exact same), so I'm not in the mood to use it too. Guess I'm sticking to import this. – Value Ink Jan 27 '17 at 9:20
  • @ValueInk Alright then. – Gurupad Mamadapur Jan 27 '17 at 14:00

JAVA, 1 byte

1

The output to stderr is:

Main.java:1: error: class, interface, or enum expected
1
^
1 error
Error: Could not find or load main class Main
Command exited with non-zero status 1
    Command being timed: "/srv/wrappers/java-openjdk"
    User time (seconds): 1.40
    System time (seconds): 0.80
    Percent of CPU this job got: 40%
    Elapsed (wall clock) time (h:mm:ss or m:ss): 0:05.40
    Average shared text size (kbytes): 0
    Average unshared data size (kbytes): 0
    Average stack size (kbytes): 0
    Average total size (kbytes): 0
    Maximum resident set size (kbytes): 44564
    Average resident set size (kbytes): 0
    Major (requiring I/O) page faults: 205
    Minor (reclaiming a frame) page faults: 11301
    Voluntary context switches: 2666
    Involuntary context switches: 1677
    Swaps: 0
    File system inputs: 78312
    File system outputs: 0
    Socket messages sent: 0
    Socket messages received: 0
    Signals delivered: 0
    Page size (bytes): 4096
    Exit status: 1 
  • 13
    This is output from compilation, rather than running the program. I don't know whether this is allowed by default. – CAD97 Jan 25 '17 at 6:16
  • 2
    Also, if you chose a different file extension, it wouldn’t output "java" would it? (Not sure if that’s possible with java) – Jonas Schäfer Jan 25 '17 at 7:41
  • 11
    if you change from java to java bytecode you could reduce by one character. trying to run empty class file will throw java.lang.ClassFormatError – user902383 Jan 25 '17 at 9:59
  • 2
    Programs outputting to stderr should be edited into this answer. – mbomb007 Jan 25 '17 at 14:47

CSS, 25 bytes

:after{content:'\43\53\53

Note that extra markup is added to Stack Overflow snippets, causing "CSS" to be displayed more than once. Open an .html file with contents

<style>:after{content:'\43\53\53

to see the result as intended.

bash CLI, 9

printf $0

If you want an actual script and not just a command at the interactive command line, then you can do this:

bash, 13

printf $SHELL

Outputs /bin/bash

  • echo $0 should work – squeamish ossifrage Jan 25 '17 at 1:41
  • @squeamishossifrage That works at the shell command line, but in a script it will output the name of the script. – Digital Trauma Jan 25 '17 at 7:08
  • echo $SHELL isn't any better anyway. pastebin.com/BfsWjCni Regardless whether you run it from command line or script and whether you use shebang in that script or not. – manatwork Jan 25 '17 at 9:26
  • 2
    'h' is illigal character for you, and you are using it in echo – user902383 Jan 25 '17 at 11:38
  • 2
    $'ec\x68o' $0 cures that detail. – manatwork Jan 25 '17 at 12:02

dc, 6

25699P

Outputs dc.

Try it online.

Pip, 8 bytes

'IWR C80

Takes the character I and WRaps it in Chr(80), resulting in PIP. Try it online!

Using the I feels a bit like cheating, so here are two 9-byte solutions that don't use any of PpIi:

z@8WRz@15
(z8+^707)

Both output pip. I'm particularly pleased with the second one:

    ^707   Split 707 into a list of characters        [7;0;7]
  8+       Add 8 to each one                          [15;8;15]
(z      )  Use list to index into lowercase alphabet  ["p";"i";"p"]
           By default, lists are printed without a separator

For proper capitalization, we need a 10-byte solution:

'IWR C80Vx

How this one works is left as an exercise for the reader. ;^)

C#, 60 67 bytes

class P{static void Main(){System.\u0043onsole.Write("\x43\x23");}}
  • Is this actually your answer, or did a bug messed up your answer? – auhmaan Jan 25 '17 at 14:18
  • @auhmaan Sorry, fixed. I initially tested on LINQPad, and forgot it has a few default namespace imports. – Bob Jan 25 '17 at 14:40
  • I was referring to the \u0043 and alikes – auhmaan Jan 25 '17 at 16:16
  • 1
    @auhmaan That's intentional because I need Console but can't use C as per question rules. In C# you can use Unicode escape sequences in identifiers. – Bob Jan 25 '17 at 16:36
  • 3
    I'm sure you can use an anonymous method for this, I can't see a restriction requiring a full program, so you could do _=>System.\u0043onsole.Write("\x43\x23"); – TheLethalCoder Jan 26 '17 at 16:29

C, 15 Bytes

Compiled C on a Linux machine with a German locale:

main(){main();}

It will run to a stack overflow and print Speicherzugriffsfehler (german for Segmentation fault) on stderr.

brainfuck, 105 Bytes

--[----->+<]>----.[--->+<]>----.+++[->+++<]>++.++++++++.+++++.--------.-[--->+<]>--.+[->+++<]>+.++++++++.

Try it online here

  • 6
    Well, not a problem in BrainFuck ;) – devRicher Jan 25 '17 at 7:24
  • @devRicher not at all ;) – TrojanByAccident Jan 25 '17 at 7:29
  • @mbomb007 I see. – TrojanByAccident Jan 25 '17 at 20:31
  • @mbomb007 updated – TrojanByAccident Jan 25 '17 at 20:52
  • Is there any reason for the excessive --- in your markdown? – FlipTack Jan 25 '17 at 20:54

R, 11 bytes

cat("\x52")

Try it online!

J, 2 bytes

   a.


┌┬┐├┼┤└┴┘│─ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������

a. returns the alphabet of the J language — a built-in list of all bytes.

My original: 4 bytes

   %:_1
0j1

This just seems pretty cool to me. The square root (%:) of negative 1 (_1) is i (0j1).

  • 1
    2 Bytes: a.. Prints the alphabet, which obviously includes 'J'. Definetly not as cool though :/ – Bolce Bussiere Mar 26 at 16:47
  • Gotta golf it. :-) That said, I am attached to my original answer. – Dane Mar 28 at 17:47

C 24 20 Bytes (Clang 3.8.1)

Thanks to @squeamish ossifrage for helping me save 4 bytes.

main(){putchar(67);}
  • How about putchar(67);? – squeamish ossifrage Jan 25 '17 at 1:36
  • @squeamishossifrage yep, thanks – Wade Tyler Jan 25 '17 at 1:40
  • Just curious, but wouldn't printf('c') also be valid? You're not allowed to use uppercase "C", but you are lowercase, and the result is case-insensitive. – Jocie Jan 25 '17 at 9:51
  • Sure sounds like it would, @jocie, but 67 is shorter than 'c' :-) – Cody Gray Jan 25 '17 at 10:34
  • 1
    @Jocie printf needs a char * so I need to use "" – Wade Tyler Jan 25 '17 at 12:30

Perl 5, 36 bytes (35 + 1 for -E)

$^X=~s/.+(.)(...)$/\U$1\E$2/;say$^X

Run with the -E flag.

$ perl -E 'say$^X=~s/.+(.)(...)$/\U$1\E$2/r'
Perl

The variable $^X is the path to the executable that is running the current program. Since the Perl interpreter is called perl, we then need to make he first letter upper-case. But the ucfirst function contains an r, which is not allowed, so we have to resort to \U and \E, which turn upper-case-conversion on and off.

We cannot use the /r modifier for s/// to return the changed string because the r is not allowed.

It's important to know that the name of the Perl programming language is Perl, and the name of the interpreter is perl with a lower-case p. There is no PERL.

  • Technically, I think perl -v satisfies the constraints of the challenge, but this is much more interesting :) Although it makes assumptions that don't hold on all systems (e.g. $^X is /home/foo/.plenv/versions/5.16.3/bin/perl5.16.3 for me, but it could just as well be /home/foo/python if I were twisted like that). – ThisSuitIsBlackNot Jan 25 '17 at 23:22
  • @this not sure if that would be within the rules. They say pick a language and do stuff. But perl -v is not anything in Perl. So I think it doesn't count. But I do think there are easier ways. About the different systems, I think we can fix it with a bit more regex magic. – simbabque Jan 25 '17 at 23:36
  • There are a bunch of zero-byte solutions already that rely on default behavior (e.g. printing of version numbers). Nothing in the rules explicitly prohibits it. But it's definitely boring and feels "cheaty." – ThisSuitIsBlackNot Jan 26 '17 at 0:18
  • Looking at the rules again, you could actually just do the uber boring perl -E'say$^X'. – ThisSuitIsBlackNot Jan 26 '17 at 21:50
  • 2
    How about -E'say`$^X -v`' ? That's indisputably a program. – hobbs Jan 29 '17 at 18:02

Hexagony, 19 bytes

Basically a direct linear flow wrapped inside the hexagon.

h;E;N;Y;X;A;;@/OG;/

Try this 19 byte un-interesting solution online!

More interesting 28 bytes:

I]f.@]z;.(;[.$>]z(]b]\(]p]h<

Try it online!

This uses the small h, which is allowed. Uses the IP1 (Initial is 0) as a "function" which does "Decrement and print as char".

Expanded view

   I ] f .
  @ ] z ; .
 ( ; [ . $ >
] z ( ] b ] \
 ( ] p ] h <
  . . . . .
   . . . .

Saves I in the memory, go to the next instruction pointer with ], then IP1 runs from NE corner in SE direction and hits ..> which directs to E, wrapped to the bottom 5 no-ops . and then to ( (decrement), ; (print as char) and then [ which returns to IP0.

IP0 starts reading from where it stopped to f, go through the no-op . and to the middle ] which runs the "function" again: IP1 starts from where it stopped and hits no-op . then $ which skips the > and runs through the bottom again... to print e.

The program keeps doing things like that. Found out that I could've just printed n by calling the function again after printing o. Mm.. can't think of ways to shorten this further though I replace 1 byte by no-op with this discovery.

Leave me a comment if you want to see diagrams in this explanation!

Perl, 2 bytes

The perl is the call to the interpreter from command line:

$ perl -M6

Outputs (for my version of Perl):

Perl v6.0.0 required--this is only v5.16.3, stopped at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

Perl, 17 bytes

80.101.114.108->_

Outputs

Can't locate object method "_" via package "Perl" (perhaps you forgot to load "Perl"?) at -e line 1.

Can be shortened to 14 bytes if PERL is acceptable:

80.69.82.76->_

All solutions make use of version strings.

  • That's awesome. – simbabque Jan 30 '17 at 8:08
  • I believe this updated 2-byte solution should qualify – Zaid Jan 30 '17 at 8:48
  • 1
    This must be the shortest answer in Perl ever! – simbabque Jan 30 '17 at 8:49
  • @simbabque I'm trying to figure a way to get perl -x to spit out "No Perl script found in input" – Zaid Jan 30 '17 at 9:13
  • 1
    @Zaid perl -x -e1 – ThisSuitIsBlackNot Jan 30 '17 at 15:16

BASIC (ZX Spectrum), 4 bytes

õ°""

Note: In the ZX Spectrum character set, these bytes display as

PRINT VAL ""

which outputs

C Nonsense in BASIC, 0:1

because the empty string is not a valid numeric expression. (I could of course have used any statement that takes a single integer.) If this answer is unacceptable, then for 6 bytes you can write a program consisting of a single line with one of the keywords that accepts no arguments, then use POKE to replace it with an illegal keyword, then attempt to RUN the program.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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