78
votes
\$\begingroup\$

Write a snippet, a function, a programm, ... that is obfuscated in a way that it looks clear at the first sight that it does something else.

For example: write a bit of code that adds two number, but when you ask someone "what does it do?", he will tell you it prints "Hello, World!".

Rules

  • The code must be readable for someone who roughly knows the language you use (avoid intrinsic obfuscated language like APL, in your own interest).
  • The code must do something unexpected that the reader initially couldn't predict.
  • When you ask different readers, they must have the same (wrong) opinion about what the code does.

Rating

  • Please read other contestants' codes during maximum 10-20 seconds, just to have a good idea of what happens there.
  • Add a comment to the answer saying what you think the code does. If the answer you want to give is already there, simply +1 the comment. (if you miss that answer and add another comment, don't worry, it won't be counted as another answer).
  • The points will be awared this way: (maxFalseOpinion - goodGuess) / totalOpinion (see example below).
  • Rate other contestants with fairplay and don't comment your own code.
  • Only add useful comments. Avoid "I don't know" and "good one!", they are not taken into account for the rating, but it's the code and not the ratings that must be obfuscated.

Rating example

The snippet adds two numbers. The comments say:

(3) It displays "Hello, World!"
(1) It substracts 2 numbers.
(2) It adds 2 numbers.

The total amount of points is the maximum number of opinions (3) - the number of good guesses (2) divided by the total amount of guesses (3 + 1 + 2 = 6). Result: (3 - 2) / 6 = 1/6 = 16.67%.


MORE ABOUT POINTS

People seem to have some trouble figuring out the points.

Here is a perfect score:

printf('Hello World');

comments:
It displays the number of time you have clicked a button. (17 comments).
TOTAL: 17 comments

Score: (17 - 0)/17 = 1 = 100%

Here is a lame score:

printf('Hello World');

comments:
It prints "Hello World". (13 comments).
TOTAL: 13 comments

Score: (0 - 13) / 13 = -1 = -100%

Here is a not so bad score:

printf('Hello World');

comments:
It prints the user name. (2 comments).
It displays the current time (15 comments).
It returns what you entered without modification. (3 comment).
It prints "Hello World" (1 comment).
TOTAL: 21 comments

Score: (15 - 1) / 21 = 0.6667 = 66.67%
Explaining :
15 is the main guess, what people said the most. 1 is the correct number of guesses. 21 is the sum of all comments.

\$\endgroup\$
32
  • 5
    \$\begingroup\$ Possible ideas for contestants (especially ones writing C) can be found at underhanded.xcott.com \$\endgroup\$
    – shiona
    Apr 23, 2013 at 8:17
  • 3
    \$\begingroup\$ I have a feeling people would be reluctant to comment if they don't see the trick (because they'd obviously end up wrong). This would strongly modify the results. \$\endgroup\$
    – ugoren
    Apr 23, 2013 at 11:40
  • 2
    \$\begingroup\$ @Haidro, I'd say that if you know the language just a bit, and seem to understand what the program does, then comment. If you can't make sense of it (e.g. I can't understand slackwear's answer), don't. \$\endgroup\$
    – ugoren
    Apr 23, 2013 at 12:56
  • 2
    \$\begingroup\$ When does the challenge end? \$\endgroup\$ Apr 26, 2013 at 20:05
  • 4
    \$\begingroup\$ I think you should require a minimum number of guesses for a winner - I'd say 10. 1 wrong answer out of 1 isn't very impressive, yet it's 100%. \$\endgroup\$
    – ugoren
    Apr 29, 2013 at 14:38

55 Answers 55

1
2
2
votes
\$\begingroup\$
<?php
for ($i = 'a'; $i <= 'z'; $i++)
    echo "$i\n";

That is my code, asked only two php developers and they were wrong, can you think that it should do and make a test, comments about that are welcome.

\$\endgroup\$
2
  • \$\begingroup\$ I don't know PHP well, but my guess would be that $i++ has to convert 'a' to an integer (0) and then 1 <= 'z' returns FALSE. Meaning that only a is printed. \$\endgroup\$
    – flornquake
    Sep 21, 2013 at 23:14
  • \$\begingroup\$ @flornquake so you said it is just a guess and it is wrong. \$\endgroup\$
    – ST3
    Sep 22, 2013 at 19:01
1
vote
\$\begingroup\$

Python

I'm new to code golf so correct my if anything is wrong or I have misunderstood something

a = 0
b = 1
print b**a

New try:

print -1**0.5
\$\endgroup\$
7
  • 22
    \$\begingroup\$ Prints 1. Are you assuming people don't know what ** does? \$\endgroup\$
    – ugoren
    Apr 23, 2013 at 11:35
  • 2
    \$\begingroup\$ It'd be a harder question if it was rather a**a ;) (but still not in the spirit of this Q, perhaps) \$\endgroup\$ Apr 23, 2013 at 16:14
  • \$\begingroup\$ 1​​​​​​​​​​​​ \$\endgroup\$
    – wim
    Apr 24, 2013 at 2:03
  • \$\begingroup\$ thanks for ur comments. will try to give improved answers in future. \$\endgroup\$
    – Anbarasan
    Apr 25, 2013 at 5:36
  • 2
    \$\begingroup\$ +1 for the print -1**0.5 \$\endgroup\$
    – Paul Cager
    Apr 25, 2013 at 11:02
1
vote
\$\begingroup\$

Python

Please give the expected output without executing the below line.


print -1 ** 0.5
\$\endgroup\$
6
  • 1
    \$\begingroup\$ It prints -1.0 \$\endgroup\$
    – Volatility
    Apr 25, 2013 at 9:39
  • \$\begingroup\$ Throws an exception \$\endgroup\$
    – ugoren
    Apr 25, 2013 at 10:57
  • \$\begingroup\$ no it does not throw an exception in python 2.7 \$\endgroup\$
    – Anbarasan
    Apr 25, 2013 at 10:58
  • 1
    \$\begingroup\$ @Anbarasan -1. Giving explicit explanations of what happens/not happens simply spoils everything. \$\endgroup\$
    – Bakuriu
    Apr 25, 2013 at 16:46
  • \$\begingroup\$ Prints a complex number close to (but probably not equal to) 1j. \$\endgroup\$ Apr 26, 2013 at 19:10
1
vote
\$\begingroup\$

Python, -20%

Answer: Raises a TypeError.

from os import *

with open('random_bytes.txt', 'wb') as f:
        f.write(urandom(10))
  • Good guesses: 3
  • Same bad guesses: 2
  • Total guesses: 5

Explanation:

When everything from os is imported (from os import *), the builtin function open is overwritten. os.open expects an integer as the second parameter, hence the TypeError.

\$\endgroup\$
4
  • \$\begingroup\$ I would appreciate an explanation on how this answer isn't appropriate. \$\endgroup\$
    – Volatility
    Apr 24, 2013 at 10:05
  • 2
    \$\begingroup\$ Raises a TypeError. [BTW: I don't understand the downvote too. An other answer uses a similar approach but wasn't downvoted...] \$\endgroup\$
    – Bakuriu
    Apr 24, 2013 at 11:35
  • 1
    \$\begingroup\$ Prints 10 random bytes in the file random_bytes.txt \$\endgroup\$
    – mgibsonbr
    Apr 24, 2013 at 18:02
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:34
1
vote
\$\begingroup\$

Python:

def f(n):
    result = []
    for i in range(n):
        result.append(lambda x: i - x)
    return result

n = 10
A = f(n)
for i in range(n):
    print(A[i](i))

Rating

  1. Good answer: Prints 9 8 7 6 5 4 3 2 1 0, each number on one line.

  2. Explanation: Ten functions are created, each subtracts its argument from i from, and each is defined with a different value of i. So A[i](i) should subtract i from i, shouldn't it? No! The value of i that is subtracted is the value of the local variable i of the function f. This is 9 after f(10) finishes, independent of which A[i] is called. Too bad only one voter fell into the trap ;-)

  3. Number of good answers: 4

  4. Number of peoply with same wrong answer: 1

  5. Total number of answers: 5

  6. Score: -60 %

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Prints 9 8 7 6 5 4 3 2 1 0, each number on one line. \$\endgroup\$
    – Bakuriu
    Apr 24, 2013 at 14:37
  • \$\begingroup\$ Prints 0 nine times. \$\endgroup\$
    – histocrat
    Apr 26, 2013 at 1:05
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:35
1
vote
\$\begingroup\$

(C)Python:

text_a = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed orci leo. Quisque ac semper leo. Nulla a justo id nulla viverra gravida. Donec ornare semper venenatis. In fringilla placerat sapien, ut pretium nibh pharetra ut. Aliquam mauris mi, venenatis nec lobortis id, fringilla sit amet leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam consectetur turpis at neque pulvinar sit amet congue tortor luctus. '''

text_b = '''Per me si va nella città dolente,
Per me si va nell'etterno dolore,
Per me si va nella perduta gente.
Giustizia mosse il mio alto fattore:
Fecemi la divina potestate,
La somma sapienza, e 'l primo amore.
Dinanzi a me non  fuor cose create
Se non etterne, e io etterna duro:
Lasciate ogni speranza, voi ch'entrate.'''

if (1, 2) is (1, 2) and (1, 2)[0] is (1, 2)[0]:
    print(text_a)
elif (1, 2) is not (1, 2) and (1, 2)[0] is (1, 2)[0]:
    print(text_b)
else:
    import __phello__.spam

Good answer:

It prints the contents of text_b.

good answers: 2

total answers: 5

score = (3 - 2) / 4 = 25%

Explanation:

Python's compiler is smart enough to use a single value for integer constants but this optimization is not (currently) applied to tuples, hence (1, 2) is not (1, 2) but (1, 2)[0] is (1, 2)[0].

\$\endgroup\$
10
  • 1
    \$\begingroup\$ It prints the contents of text_b \$\endgroup\$
    – Volatility
    Apr 24, 2013 at 9:37
  • 2
    \$\begingroup\$ It prints the contents of text_a. (Implementation dependent.) (I changed the comment, terrible typo...) \$\endgroup\$ Apr 24, 2013 at 14:08
  • \$\begingroup\$ @WolframH I've added a clarification about the implementation. AFAIK all versions of the implementation I've used give the same result. \$\endgroup\$
    – Bakuriu
    Apr 24, 2013 at 14:33
  • \$\begingroup\$ Yes, I believe so. And I answered what I believe happens for that implementation :-) (but could be wrong, of course). \$\endgroup\$ Apr 24, 2013 at 15:00
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:35
1
vote
\$\begingroup\$

Perl: 100%

my $x;
print $x++ ? 'Hello' : 'world';
print ++$x + ++$x . "\n";

Answer: world6 (with a line feed).

Explanation:

For perldoc :

Note that just as in C, Perl doesn't define when the variable is incremented or decremented. You just know it will be done sometime before or after the value is returned. This also means that modifying a variable twice in the same statement will lead to undefined behavior.

Score:

total answer : 4
good answer : 0
score : (4-0)/4 = 100%

\$\endgroup\$
6
  • 2
    \$\begingroup\$ prints world then prints 7\n, though i don't know perl so i don't know what my does \$\endgroup\$
    – Griffin
    Apr 24, 2013 at 14:58
  • 1
    \$\begingroup\$ Balls, I mean't 5 not 7, oh well \$\endgroup\$
    – Griffin
    Apr 24, 2013 at 15:03
  • \$\begingroup\$ @Griffin: my is just the way to declare variables. \$\endgroup\$
    – Toto
    Apr 24, 2013 at 15:43
  • \$\begingroup\$ Prints "world4" with no newline. \$\endgroup\$
    – user7486
    Apr 25, 2013 at 15:58
  • 1
    \$\begingroup\$ The score should be (3-0)/4. \$\endgroup\$
    – flornquake
    Apr 27, 2013 at 17:48
1
vote
\$\begingroup\$

Python

Tested using Python 2.7 and 3.3. I've updated this post with a more readable version:

def e(code):
    return eval(code)

try:
    items = sorted(globals().items())[0][1]
    for item in dir(items):
        if item[4:] * 2 == '':
            globals()[item[0]] = getattr(items, item)
finally:
    e('print("Ni hao, shijie!")')
    print('What, you don\'t speak Chinese?')

The previous, more obfuscated version:

def e(s):
    return eval(s)
#

glob = globals()
items = sorted(glob.items())[int()][True]
s = type(type('', (), {'__getitem__': lambda a, b: b})()[:])(0b100, None)
try:
    for item in dir(items):
        if item[s] * 2 == '':
            glob[item[0]] = getattr(items, item)
finally:
    e('print("Ni hao, shijie!")')
    print('What, you don\'t speak Chinese?')

Score

The program exits without printing anything. The code within the try block loops through each item in __builtins__ and looks for names of 4 characters or less. It registers them in the global namespace, using the first character of their original name. By doing so, the 'exit' function becomes available as 'e', replacing the function defined before the try block.

2 incorrect answers, 2 answers total: (2 - 0) / 2 = 100%

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Prints print("Ni hao, shijie!"). This one took me a while to decipher - quoting the OP, "The code must be readable for someone who roughly knows the language you use". This is quite the opposite. \$\endgroup\$
    – Volatility
    Apr 25, 2013 at 13:24
  • \$\begingroup\$ You're right, too much obfuscation... I've added a more readable version now. \$\endgroup\$ Apr 25, 2013 at 14:52
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:39
1
vote
\$\begingroup\$

JavaScript (V8)

(function a() {
    /* (function(package) {
     *  (function(a) {
     *      "use strict";
     *      var a\u005f = package;
     *      with(a_)
     *          this && a();
     *  })(a);
     * })();
     */

    var code = "";
    var match;
    var re = /[ /]\* (.+)$/gm;

    while(match = re.exec(a)) {
        code += match[1];
    }

    try {
        var package = {a: a};
        eval(code);
    } catch(ex) {
        console.log(/SyntaxError: (.+)/.exec(ex.stack)[1]);
        return;
    } finally {
        console.log(";-)");
    }
})();

The correct output is:

Unexpected strict mode reserved word
;-)

So my result is sort of 100%, but it was probably too confusing. The only important part is the commented code, actually; the rest of it finds the code, executes it, and gets the error. But JavaScript doesn't have multiline strings.

(package is an ECMAScript 5 future reserved word and so can't be used inside the strict-mode inner function. a\u005f is a valid variable name. I'd expect people to expect that the error was "Strict mode code may not include a with statement" or just "Unexpected token ILLEGAL".)

\$\endgroup\$
4
  • \$\begingroup\$ This tells me we should hope for Dart to come along. \$\endgroup\$
    – Alexander
    Apr 23, 2013 at 23:45
  • \$\begingroup\$ Prints nothing but logs into the console: ;-) \$\endgroup\$
    – SteeveDroz
    Apr 24, 2013 at 6:05
  • 3
    \$\begingroup\$ Definitely too hard too make a useful guess \$\endgroup\$
    – copy
    Apr 24, 2013 at 13:56
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:34
1
vote
\$\begingroup\$

C# - 100%

static void Main(string[] args)
    {
        var h = "Hello, world.";
        var key = "\u007C\u002D\u007C\u0033\u0031\u0031\u0030\u002C\u0020\u005C\u002F\u005C\u002F\u0030\u0052\u0031\u005B\u0029\u0021";
        var StringToHash = h + key;
        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
        byte[] b = System.Text.Encoding.ASCII.GetBytes(StringToHash);
        byte[] hashBytes = md5.ComputeHash(b);
        try {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(0, -32);
            for (int i = 0; i < hashBytes.Length; i++) {
                sb.Append(hashBytes[i].ToString("x2"));
            }
            Console.WriteLine(sb.ToString());
        }
        catch {
            Console.WriteLine(StringToHash.Substring(13));
        }
        finally {
            Console.ReadLine();
        }
    }

Answer: Prints "|-|3110, \/\/0r1{)!"

  • Number of good answers: 0
  • Number of people who answered mostly the same thing: 5
  • Total number of answers: 5
  • Score: (5-0) / 5 = 1 = 100%
\$\endgroup\$
5
  • 3
    \$\begingroup\$ it'll print... something? And then wait for ENTER. \$\endgroup\$
    – redtuna
    Apr 23, 2013 at 20:45
  • \$\begingroup\$ It prints "Hello, world." \$\endgroup\$
    – David
    Apr 24, 2013 at 2:22
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:32
  • \$\begingroup\$ This one's kind of silly... I haven't memorized ASCII and so don't expect it to do anything in particular. \$\endgroup\$
    – Ry-
    Apr 28, 2013 at 1:51
  • \$\begingroup\$ This kind of depends on whether or not you know what the StringBuilder and Substring args are supposed to do. But they're all kind of silly, aren't they? \$\endgroup\$
    – Erik
    Apr 29, 2013 at 17:46
1
vote
\$\begingroup\$

Perl: -33% (1-2)/3

sub foo {
  ($TRUE,$FALSE) = ("0 but true",0);
  return $TRUE and $FALSE;
}
print &foo;

This program prints 0 but true because Perl parses the return statement like

(return($TRUE)) and $FALSE;

not

return ($TRUE and $FALSE);
\$\endgroup\$
3
  • 1
    \$\begingroup\$ it'll print 0 but true \$\endgroup\$
    – Toto
    Apr 25, 2013 at 18:30
  • \$\begingroup\$ It will output 0. \$\endgroup\$
    – f.ardelian
    Apr 26, 2013 at 22:17
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:37
1
vote
\$\begingroup\$

Q - 100%

server:":localhost:1234:username:password";
h:hopen server;
h@(-1;"Alert Message");

Score

The correct answer was not given. This exploits the fact that the underlying k instruction for hopen (opening a handle to a remote instance) is the same as iasc (the indices needed to sort a list).

\$\endgroup\$
2
  • 3
    \$\begingroup\$ I don't know Q but I will guess (so that you can have a score) that it attempts to open a server and send an alert message if it fails doing so. \$\endgroup\$
    – plannapus
    Apr 23, 2013 at 13:31
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:33
1
vote
\$\begingroup\$

A little late, but I got some inspiration.

JavaScript

// I miss Python :(
function print(x) {
    console.log(x)
}

// Build the points.
x = (1, 2, 3)
y = (4, 5, 6)
z = (7, 8, 9)

// Swap x and y.
[x, y] = [y, x]
print(x) // Prints (4, 5, 6)
\$\endgroup\$
1
vote
\$\begingroup\$

C++

#include <iostream>

#define ONE 1
#define TWO ONE+ONE
#define FOUR 2*TWO

int main()
{
    std::cout << FOUR << std::endl;
    return 0;
}

Output is 3.

Actually to have FOUR, definition should be 2 * TWO * 2, that looks really confusing.

\$\endgroup\$
2
  • \$\begingroup\$ Why that strange solution? In math if you want “2*1+1” to give 4 then you add parenthesis: “2*(1+1)”. Same here: #define TWO (ONE+ONE). \$\endgroup\$
    – manatwork
    Jan 20, 2014 at 13:31
  • \$\begingroup\$ @manatwork, exactly, I just answered into the question, for people who aren't really into preprocessor it looks like an output is 4 instead of 3. \$\endgroup\$
    – ST3
    Jan 20, 2014 at 15:20
0
votes
\$\begingroup\$

PHP

<?php
function num2alpha($n) {
    $r = '';
    for ($i = 1; $n >= 0 && $i < 10; $i++) {
        $r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) . $r;
        $n -= pow(26, $i);
    }
    return $r;
}
echo num2alpha(3752126) . " " . num2alpha(10786571);
?>
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Prints a bunch of characters separated by a space, which I'm far too lazy to calculate. I'll guess "Hello World" just because it makes sense and so you can have a score. :) \$\endgroup\$
    – asteri
    Apr 24, 2013 at 20:02
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:37
0
votes
\$\begingroup\$

VBA

Sub a()
    b = c = 1
    Debug.Print b, c
End Sub
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Random guess: prints "1 1" \$\endgroup\$
    – asteri
    Apr 24, 2013 at 20:03
  • 3
    \$\begingroup\$ Prints either True or False (or however VBA prints boolean values) depending on whether c equals 1, then the value of c \$\endgroup\$
    – 3Doubloons
    Apr 24, 2013 at 23:01
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:38
0
votes
\$\begingroup\$

Python

def test(foo, bar=[]):
    bar.append(foo)
    for i in bar:
        bar = bar * 2
    else:
        return i * len(bar)
    return bar

print [test(i) for i in range(3)]
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Prints [0, 8, 48], unless I got the plutimications wrong :-) \$\endgroup\$ Apr 24, 2013 at 18:37
  • \$\begingroup\$ Prints [0, 13, 208] (I think). \$\endgroup\$
    – flornquake
    Apr 24, 2013 at 19:01
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:38
0
votes
\$\begingroup\$

PHP

No comments this time. Comments should be on the HTML source that it will output, use backticks ( ` ) to escape HTML code in comments so Stack Exchange won't eat them up.

$funcs = array_shift(array_slice(get_defined_functions(), 1));
global $output;

function one() { return '<b>hello'; }
function two() { return ' '; }
function three() { return 'world'; }
function four() { return '!</b>'; }
function five() { echo '<pre>' . print_r($output); return '\n'; }

$output = array();
while ($funcs) {
    foreach ($funcs as $func) {
        $output = $output + array($func());
    }
    array_shift($funcs);
}

Whoever gets the answer is either a wizard or a liar.

\$\endgroup\$
1
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:40
0
votes
\$\begingroup\$

JavaScript

I tried to keep it under 20 chars width. I hope the comments help.

f=function//functify
(s){
    var X;
    return new (X=
    function()
    {this.s=s},X.
    prototype.
    toString=
    function(){return
    this.s},X)(s)
}
w=function//wordify
(n) {
    return n
    ? f('world')
    : f('hello')
}
s=function//spacify
(a,b){
    return a
    + ' ' + b
}
m=function//main
() {
    alert(s(w(0),
    w(1)))
}
m()

If anyone figures it out, they probably know real pain. When I first stumbled across this a few years ago, it took me hours until I figured it out and I only understood it several months later when I read an article on JavaScript and I made the connection. You see, th͝e̸ ͢t̨hin͞g ̵is i̧͜n̶҉́ ̛͘͠J̷͟a͜͞v̶̧͠a̢̨͟͞S̷͞͞c͝͏͏r҉̶i̴͞͞p̷͟t̷̕҉ ̡͠z̨̢b͘͢ơ̢͜͞d̨̡͘i̷̛͜s̛͞è̡ a̵͘҉̕l̨͟͞s̶̶̀o͠͞ ̶͟͠͠b͢͟r̵i̶̡̛͟n̨҉̶g̸̴̕͡ ̕͞i̴̧n̢͜͡ ̵̧̀́͞ş͡͞o̷̧̧͜͜m̴̧ę̶͏b̶͞͠͝e͏e͜͡r̶̵̢.̴̶̸̢̨ a͢n̢d͜ ̸͟͞t̶͞h̶́a̕͘ţ ̴͢͟c̢a҉́n͘͟ r̴ea̧ll̸y͢ ̕m͞e̴s͡s with what you're expecting from your program.

\$\endgroup\$
1
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:40
0
votes
\$\begingroup\$

Python

i = 1j
i = i ** 4
while (i ** 0.5).real:
    i -= 1
print(i)

Rating

  1. Good answer: Prints 0j.

  2. Explanation: The first line was inteded to make the reader aware of the fact that Python works with complex numbers out of the box. Then, the counter i is set to 1 + 0j and then is decreased until... well, until its real attribute has a falsey value. I had hoped to trick somebody into thinking that real means "this is a real number"; the loop would then go until i was -1. Apparently everybody knowing about complex numbers in Python also knows that real is just the real part of the number, and then 0j is the first falsey value. Also, everybody remmbered that it's 0j, not 0. I'm impressed!

  3. Number of good answers: 2

  4. Number of peoply with same wrong answer: 0

  5. Total number of answers: 2

  6. Score: -100 %

\$\endgroup\$
3
  • 2
    \$\begingroup\$ This prints 0j. (Btw, the parentheses are not required. A space is enough: i ** 0.5 .real) \$\endgroup\$
    – Bakuriu
    Apr 24, 2013 at 21:04
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:38
  • 1
    \$\begingroup\$ I think I never used complex numbers in my programs, but I'm well aware that when operating with numbers the type can only go "up" (int -> long, float ->complex), never "down", hence the correct solution :) \$\endgroup\$
    – Bakuriu
    Apr 27, 2013 at 8:25
0
votes
\$\begingroup\$

Erlang

What will be printed?

-module(confusion).
-compile(export_all).
go() ->
    Pi = "3",

    case Pi of
        3 ->
            io:format("Phew; pi is still the same");
        _ ->
            io:format("Pi has changed: ~p~n", Pi)
    end.

The Answer

It prints:

 Pi has changed: 51
\$\endgroup\$
1
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:39
0
votes
\$\begingroup\$

Yet another piece of code (after the deadline):

Scala

object HW extends App {
  val yes = 1;
  val no  = 0;

  (6*7 % 2) match {
    case yes  => println("Hello world.");
    case no   => println("No, thanks.");
  }
}
\$\endgroup\$
2
  • \$\begingroup\$ doesn't print anything \$\endgroup\$
    – mniip
    May 11, 2013 at 12:23
  • \$\begingroup\$ @mniip It does, but what? \$\endgroup\$
    – Petr
    May 11, 2013 at 12:50
0
votes
\$\begingroup\$

I know the competition is over, but I couldn't resist to post this idea.

Java:

public class QuadraticEq {
    /** Prints the roots of x^2 + bx + c = 0 (if they exists). */
    public static void root(double b, double c) {
        //System.out.print("x^2 + " + b + "x + " + c + ": ");
        double d = Math.sqrt(b*b - 4*c);
        double r1 = (d - b) / 2;
        double r2 = (-d - b) / 2;
        System.out.format(java.util.Locale.US, "%f, %f\n", r2, r1);
    }

    public static void main(String argv[]) {
        // Compute some square roots
        root(-0.9, 0.20);
        root(-0.4, 0.04);
        root(-1.4, 0.49);
        root( 0,   1);
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ 0.4, 0.5 0.2, 0.2 0.7, 0.7 NaN, NaN \$\endgroup\$
    – mniip
    May 4, 2013 at 10:02
-1
votes
\$\begingroup\$

Here it is for C

int main(){
    int a = 10;
    int b = 20;
    int c = a + b;
    printf("Hello World!");
}
\$\endgroup\$
4
  • \$\begingroup\$ Depends what language it is. \$\endgroup\$
    – histocrat
    Apr 26, 2013 at 5:32
  • \$\begingroup\$ @histocrat: Well does not. In the first it looks like I have provided a solution for the original question, but actually I have implemented the example provided in the question. \$\endgroup\$ Apr 26, 2013 at 5:41
  • 4
    \$\begingroup\$ It prints Hello World!. It also adds two numbers, but does nothing with the result. \$\endgroup\$
    – ugoren
    Apr 26, 2013 at 7:50
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:41
-1
votes
\$\begingroup\$

Ruby

puts "Please enter a boring sentence"
sentence = gets <<"!!!!!!!!111"
puts sentence
!!!!!!!!111

Edit: This might be getting downvoted because the user interaction makes it hard to test. Is that why? Hint:

$ Try typing this at the prompt it gives you: puts sentence

\$\endgroup\$
1
  • \$\begingroup\$ This is the end of the game, please rate yourself with the comments that are above this one. Edit your content and add the good answer, the number of good answers, the number of people that mostly answered the same thing, the total number of answer and your score. Don't forget that a 2 next to a comment means 3 answers. Comment freely below this. \$\endgroup\$
    – SteeveDroz
    Apr 27, 2013 at 6:41
1
2

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