triplegolf - not only the source code length counts!

15

2

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.

vsz

Posted 2012-05-17T17:32:45.030

Reputation: 7 963

1What is a "type of character"? – Peter Taylor – 2012-05-17T18:36:17.557

Is compiling with -Wall allowed? Or is that considered "modding" the compiler? – Joey Adams – 2012-05-17T18:37:44.717

5Also, 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 – 2012-05-17T18:40:02.623

@Peter Taylor: edited, I don't know if it's clearer now. I wanted to express that aaaaaaa is one, ababbbba is made of two different characters. – vsz – 2012-05-17T18:59:39.130

@Joey Adams: Good question, I should have thought about that. Is it too late to impose a mandatory filename? – vsz – 2012-05-17T19:00:45.463

3My 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 – 2012-05-17T19:17:42.480

2I wonder if a triple-quine is possible in some language? – Ry- – 2012-05-18T00:00:49.257

2For 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? – l0n3sh4rk – 2012-05-18T10:51:59.723

1@Joey Adams: by unmodded I meant that modifying your compiler to print the warning you wanted would be obviously cheating. Sorry, I read too much IOCCC and am never paranoid enough about the rules and the possible circumvention of them. :) – vsz – 2012-05-22T06:19:49.713

=p in ed unfortunately requires a newline. – jimmy23013 – 2017-03-29T01:24:08.650

If there isn't the special note about newlines and whitespaces, someone may try =p in ed on Cygwin or MinGW. – jimmy23013 – 2017-03-29T02:06:55.157

Answers

14

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__);?>

l0n3sh4rk

Posted 2012-05-17T17:32:45.030

Reputation: 1 387

1The bash example is an error, not a warning. – Peter Taylor – 2012-05-18T10:34:36.300

What compiler are you using for the C solution? – breadbox – 2012-05-18T16:10:46.727

@breadbox gcc version 4.7.0 20120505 (prerelease) (GCC) – l0n3sh4rk – 2012-05-18T16:33:38.523

8

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

breadbox

Posted 2012-05-17T17:32:45.030

Reputation: 6 893

My understanding is that non-printable (whitepace?) are truncated, so this would not count. If that works, I can improve my own answer. – Gaffi – 2012-05-17T19:39:53.153

1Control 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 – 2012-05-17T20:36:20.400

Any word from the OP on this? – Gaffi – 2012-05-17T21:05:50.347

1I 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 – 2012-05-18T03:09:36.937

47 chars and ascii output: main(){'\z';int i=32; while(++i<80)putchar(i);} – copy – 2012-05-18T13:11:27.043

1@copy, Or main(i){i='\z';while(i-->74)putchar(i);} -- but reducing the program size is actually counter-productive. – breadbox – 2012-05-18T16:09:59.020

1This is my favorite answer, I know I should have prohibited accessing the contents of the file (just as real quines do) – vsz – 2012-05-22T06:14:25.777

5

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

Ry-

Posted 2012-05-17T17:32:45.030

Reputation: 5 283

3

Zsh, 20 bytes

<<<   $-$_$_$_$_$_
[

The problem we face here is alluded to in a comment above: Zsh prints the program name in addition to the line number before every error. The solution here uses a one-character filename to abuse this. I've wrapped it up in a helper script to show exactly what it prints, and used wc -c on stderr, stdout, and the source file.

Output: 569Xcatcatcatcatcat followed by a newline
Errors: s:[:2: ']' expected followed by a newline


EDIT: Alternate 20 byte solution with no file restriction:

<<<$-$-$-$-$_>&1 >&2

Try it online!

Zsh, zsh -x, 10 bytes

<<<$_$_$_

-x flag enables xtrace. This again requires a single-character filename. Try it online!

Zsh zsh -JNTwEDY, 12 bytes

<<<$->&1 >&2

Shortest -flag answer with no filename requirement. Sets more flags, and $- prints them all. Try it online!

GammaFunction

Posted 2012-05-17T17:32:45.030

Reputation: 2 838

3

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.)

Ry-

Posted 2012-05-17T17:32:45.030

Reputation: 5 283

2

JavaScript (Firefox 54), 34 bytes

alert((f=function(x)1234)(56)+f+f)

Outputs:

1234function(x)1234function(x)1234

And it sends this warning to the browser console:

expression closures are deprecated

It looks like this in my copy of Firefox Developer Edition (54.0a2). It may work in other versions of Firefox as well.

ETHproductions

Posted 2012-05-17T17:32:45.030

Reputation: 47 880

2

Ruby, 48 characters

IO=1;puts ?a*48;# let's make it 48 bytes long :)

Outputs

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Warns

r.rb:1: warning: already initialized constant IO

(the file is r.rb, I removed the path, if you run it from irb, you'll get (irb):1: warning...)

There is the warn method in Ruby, but it just outputs its arguments to $stderr, making it look less like a warning.

Redouane Red

Posted 2012-05-17T17:32:45.030

Reputation: 311

1

Python, 57 bytes

Other interpreters may display the warning differently. This was only tested to work on TIO.

from warnings import*
print("prt"*19)
warn("Warning...!")

Try it online

Output

prtprtprtprtprtprtprtprtprtprtprtprtprtprtprtprtprtprtprt

Warning

.code.tio:3: UserWarning: Warning...!
  warn("Warning...!")

Note that the leading spaces are not counted toward the byte count. If the leading spaces were not ignored, this could be done in 51 bytes.

mbomb007

Posted 2012-05-17T17:32:45.030

Reputation: 21 944

1

Javascript (ES6), 32 30 bytes

Screen(console.log(Function));

prints

ƒ Function() { [native code] }

in Chrome, and then throws

TypeError: Illegal constructor

My original 32 byte solution:

(x=y=>console.log(x+!0+10)||z)()

first, prints

y=>console.log(x+!0+10)||ztrue10

And throws the error

ReferenceError: z is not defined

vrugtehagel

Posted 2012-05-17T17:32:45.030

Reputation: 251

0

Perl 6, 10 bytes

dd say 1e9

Try it online!

Prints 1000000000 to STDOUT, and Bool::True to STDERR. Both produce a trailing newline, but trailing whitespace is ignored in this challenge. dd is a Rakudo specific debugging function

Jo King

Posted 2012-05-17T17:32:45.030

Reputation: 38 234

0

VBA, 39 Bytes

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.

Gaffi

Posted 2012-05-17T17:32:45.030

Reputation: 3 411

VBA does not give any compiler warnings so I do not think that this counts a being valid – Taylor Scott – 2017-05-31T16:52:44.897