Valid Through The Ages
Revised answer for "better" scoring system
C89 / C99, Score: 0
My program is 52 characters long and uses the same mechanism as in my original answer to achieve the different output. This works because C89 doesnt treat //
as a comment:
i=32;main(){putchar(i+++0//**/
+52)&&i<84&&main();}
The results:
$ ./diff2c89
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRS
$ ./diff2c99
TUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂Çüéâäàåç
$ ./diff2c99 | wc
0 1 52
$ ./diff2c89 | wc
0 1 52
$ wc diff2.c
1 2 52 diff2.c
Old answer:
C89 / C99, Score: -Infinity?
I'm not entirely sure if this program doesn't break the rules, but never mind.
This program exploits the fact that in C89 //
is not a valid comment but /* ... */
is.
Using the comment trick an other function is executed. In C89 the function just prints "trolololol..."
until the stack overflows (so it might finish within 2 seconds).
f1(){printf("ol");f1();}
f2(){printf("oll");}
main(){
printf("tr");
void (*f[])() = {f1,f2};
f[0 //* trollololol */
+1]();
}
C99
$ ./diffc99
troll
C89
$ ./diffc89
trolololololololololololololololololololololololololololololololololololololololololo
lolololololololololololololololololololololololololololololololololololololololololol
ololololololololololololololololololololololololol ....
Python - 10 points less than the next best answer
print(range(100))
In Python 2, this will print the entire list of integers from 0 to 99.
In Python 3, range
is a generator and so it will print only "range(0,100)".
Seeing as I've never run into a size limit on numbers in Python, I can replace that 100 with a much bigger number (2**1000, for example) and end up with a virtually infinite difference in the output.
Edited to reflect the fact that, while I can get a score that is infinitely low for any practical purpose, I cannot reach actual infinity with a program that terminates under 2 seconds
For the updated tie-breaker scoring system, I'd submit:
print(range(4))
Output:
Python 2: [0, 1, 2, 3]
Python 3: range(0, 4)
The first print has 5 unique characters ([123]
), the second print has 8 unique characters (range(4)
), the difference in length of output is 1, the code has 15 characters, the shortest output is 11 characters... these rules are pretty confusing but I think this brings me to a final score of 15+1-min(11,5+8) = 5.
Python - 0 points
No idea how this one works :P Just stumbled upon it while trying out random code.
int
On Python 3, it's <class 'int'>
and on Python 2, it's <type 'int'>
(using interative console)
"Better" Score: 3 (length) + 1 (char diff.) - 4 (unique chars)
Older Python 1 - 7 points
print()
Big thanks to @grc for this version and helping me subtract four points !
In Python 2, this statement is interpreted as print ()
which prints the empty tuple ()
.
In Python 3, the print
is a function and results in nothing being printed.
"Better" Score: 7 (length) + 2 (char diff.) - 2 (unique chars)
Older Python 2 - 13 points:
print(1,2)
"Better" Score: 12 (length) + 2 (char diff. o/p) - 1 (unique chars o/p)
I know this isn't going to win but still gave an answer, as this is my first Python try :)