Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

The goal of this challenge is to write a program where the length of the following three are exactly the same:

  • the length of the source code
  • the length of the output it prints to the standard output
  • the length of the compiler warnings it generates with the (unmodded) compiler of your choice

The winner is the shortest code to fulfill all three criteria, and has to be at least 1 character long.

To spice things up, if the output has less than three different characters, it gets a 5 point penalty added to the length for each one (so +10 if only a single type, +5 for two).

(Newlines count either as 1 or 2 characters, your choice, but it has to be consistent through all three criteria. Leading and trailing white-spaces are ignored in all lines in all three criteria)

In case of equal score, the one printing the most interesting result (instead of garbage) is the winner.

share|improve this question
What is a "type of character"? – Peter Taylor May 17 '12 at 18:36
3  
Also, what if the compiler produces non-warning output (e.g. "Compiling Main") ? Also, what if the name of the source file appears in warning messages (e.g. "foo.c:1:1: ...") ? – Joey Adams May 17 '12 at 18:40
2  
My weapon of choice is VBA, which doesn't really have a compiler and does not output a binary file to run (as is the case for some other languages, I believe). Are there considerations for this, or am I just disqualified by default? – Gaffi May 17 '12 at 19:17
2  
I wonder if a triple-quine is possible in some language? – rynah May 18 '12 at 0:00
1  
For interpreted languages, we get an output even on occurance of an error, in such a case, are those errors accepted or are only warnings accepted? – l0n3_sh4rk May 18 '12 at 10:51
show 4 more comments

7 Answers

up vote 6 down vote accepted

Bash, 23 characters

Error:

bash: /: Is a directory

Source:

echo       $0-$01234;/;

Output:

/bin/bash-/bin/bash1234


Brainf*ck, 32 characters

This code executes for about 3 seconds and stops and displays the following error and output.

Error:

bff: out of memory (-2058691272)

Source:

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

Output: (Hexdump)

0505 0505 0505 0404 0404 0404 0303 0303
0303 0202 0202 0202 0101 0101 0101 0000


C, 35 characters

Warning:

b.c:1:30: warning: division by zero

Source and Output:

main(){system("cat "__FILE__)/0;;;}


PHP, 50 characters

Warning:

PHP Warning:  Division by zero in /tmp/3 on line 1

Source and Output:

<?php echo (0/0).''.file_get_contents(__FILE__);?>
share|improve this answer
   
The bash example is an error, not a warning. – Peter Taylor May 18 '12 at 10:34
What compiler are you using for the C solution? – breadbox May 18 '12 at 16:10
@breadbox gcc version 4.7.0 20120505 (prerelease) (GCC) – l0n3_sh4rk May 18 '12 at 16:33

Bash, 23 chars

echo $BASH_COMMAND 1>&2

Outputs its own source to both STDOUT and STDERR.

share|improve this answer
+1 for being a quine... and an "error quine"! – Johno May 18 '12 at 8:39
Very nice entry! – ChristopheD May 18 '12 at 22:30
While it is not technically a compiler warning, (and the accepted solution has a solution of the same length anyway), still +1 as an honorable mention for the idea. – vsz May 22 '12 at 6:17

C - 48 chars

main(i){while(++i<49)putchar(i);putchar('\z');}

Note: includes a final (Unix-style) newline.

Output from gcc a.c reads:

a.c:1:41: warning: unknown escape sequence '\z'

The output from a.out is mostly non-printing chars, so here's what it looks like after piping through hexdump:

00000000: 0203 0405 0607 0809 0A0B 0C0D 0E0F 1011  ................
00000010: 1213 1415 1617 1819 1A1B 1C1D 1E1F 2021  .............. !
00000020: 2223 2425 2627 2829 2A2B 2C2D 2E2F 307A  "#$%&'()*+,-./0z
share|improve this answer
My understanding is that non-printable (whitepace?) are truncated, so this would not count. If that works, I can improve my own answer. – Gaffi May 17 '12 at 19:39
1  
Control characters aren't usually considered whitespace, except of course for \t ,\n, \r, \f, and sometimes \v. None of these are at the leading or trailing position, so I figured I was safe. – breadbox May 17 '12 at 20:36
1  
I think this is perfectly acceptable. They are not whitespace, and in either case this is not ACM to be that strict with the requirements. The main reason for this "whitespace rule" was that some IDEs might heavily format their compiler output. – vsz May 18 '12 at 3:09
1  
@copy, Or main(i){i='\z';while(i-->74)putchar(i);} -- but reducing the program size is actually counter-productive. – breadbox May 18 '12 at 16:09
1  
This is my favorite answer, I know I should have prohibited accessing the contents of the file (just as real quines do) – vsz May 22 '12 at 6:14
show 2 more comments

JavaScript, 63 66

!function x(){console.log(x+'...');eval(Array(33).join('$'))}()

The output is:

function x(){console.log(x+'...');eval(Array(33).join('$'))}...

In Chrome, the error is:

ReferenceError: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ is not defined
share|improve this answer

Visual Basic .NET, 185

Gee, vbc is pretty verbose with its compilation warnings. Anyway, the code is this:

Public Module Main
    Public Sub Main()
        Console.WriteLine(New String("a"c,185))
    End Sub

    Public Function A()
        'This is actually just padding.
        'Hi
    End Function
End Module

(Note that they're supposed to be tabs, not spaces.)

The output is this:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

And the compiler warning is this:

warning BC42105: Function 'A' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

    End Function
    ~~~~~~~~~~~~

(This time, it's actually four spaces, not tabs.)

share|improve this answer

C

I currently only have access to online compilers, and I couldn't find one that shows warnings.
So this program doesn't really qualify.
But the output and the compiler output surely match, and not only in length.
Getting the program length to match shouldn't be hard.

main(){system("gcc "__FILE__" 2>&1");}
share|improve this answer

VBA: 39

Not sure if this qualifies, given the compiler constraint, but:

Input: (in the immediate window)

For i=1 To 39:a=a & Chr(i):Next:Print a

*The output includes non-printing characters that don't play well in this window.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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