-ENDED- Do something that looks like something else

78

29

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.

SteeveDroz

Posted 2013-04-23T07:08:03.090

Reputation: 2 399

Question was closed 2016-03-31T17:52:11.717

5

Possible ideas for contestants (especially ones writing C) can be found at http://underhanded.xcott.com/

– shiona – 2013-04-23T08:17:50.417

Hmm, I didn't know that! That is evil. Not quite the same goal, though. Thanks for the link! – SteeveDroz – 2013-04-23T08:23:19.610

3I 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. – ugoren – 2013-04-23T11:40:08.820

@ugoren : As a contestant, comment other peoples work. It's OK if the answer don't have the same amount of comments. But each must have some (I do comment as well, don't worry, I also feel dumb about not seeing the trick). – SteeveDroz – 2013-04-23T12:42:00.380

Question (I'm new to this exchange site, so sorry). If I don't know the language, should I still give it a shot :D? – TerryA – 2013-04-23T12:45:04.033

Hey, do you know any language? You can participate to this challenge in any language. It's not the case for some of them, but this one is ok. Why not trying a natural language? I would give at least a vote to a good intricated sentence that doesn't mean what it looks like (Example: my lady, you look like a twenty years old rose. [have you seen a rose after 20 years?]). – SteeveDroz – 2013-04-23T12:48:42.673

I know python :). But what I meant in my question was, should I rate other people's answers? Sorry for the confusion :x :( – TerryA – 2013-04-23T12:50:02.583

Ah! Yes, I think you can. If you know python, you know what if, for and while mean. You know what is a function, and so on. So if you don't understand anything to the code, don't rate it. If you think you understand (even if obviously you don't, because it's the point of the game), give it a try! – SteeveDroz – 2013-04-23T12:53:36.553

Alright, thanks for clarifying! This looks like a fun challenge! – TerryA – 2013-04-23T12:53:59.663

2

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

– ugoren – 2013-04-23T12:56:00.250

@Oltarus, seems the last example computes the wrong score: There are 3 votes for "Hello World", so the rating should be (15 - 3) / 21 = 57.1...% – SeanC – 2013-04-23T14:45:42.947

Yes, I edited it 10 minutes ago. reload the page. – SteeveDroz – 2013-04-23T14:46:54.670

At least one answer works by using unicode characters that look like another one but are distinct. Is that within the spirit here? – Winston Ewert – 2013-04-24T14:04:38.873

1I know which one you're talking about. I'm not that happy about that, it's not the kind of trick I was expected, but it isn't against the rules as I wrote them, so... I'll have to accept it. – SteeveDroz – 2013-04-24T14:48:11.690

In some esoteric programming languages, EVERY program is like that. Examples: Chef, IRC, or several others from the thematic languages list.

– AJMansfield – 2013-04-24T21:22:35.910

I'll say, I love the scoring scheme for this. It not only gives points for luring people away from the actual result, but also emphasises luring people towards the same wrong answer. A program where everyone guesses differently may very well score worse than one where half the people got it right, but everyone else picked the same wrong answer. – 3Doubloons – 2013-04-24T23:15:16.703

Thank you for the remark, it's exactly what I wanted: something that looks like something else, not something that looks like anything else. :-D – SteeveDroz – 2013-04-25T04:20:00.590

You may be interested in underhanded.xcott.com – Manishearth – 2013-04-25T07:48:02.163

2When does the challenge end? – Reinstate Monica – 2013-04-26T20:05:50.133

2When will it end? I really want to know the tricks behind some of these programs. – f.ardelian – 2013-04-26T22:00:31.910

1It will end when you won't expect it. As a matter of fact, it will end now! – SteeveDroz – 2013-04-27T06:20:01.273

Who won? (Not me...) – Reinstate Monica – 2013-04-27T06:23:53.620

Well, it just took me 20 minutes (max 1 comment every 15 seconds) to add a comment on each of the 50 questions (thanks guys for playing along!). Now people will rate themselves, because I don't every language. Feel free to comment any answer. now! – SteeveDroz – 2013-04-27T06:43:58.950

One thumbs up counts as a comment yea? – TerryA – 2013-04-27T06:46:36.910

Yes, exactly. So 2 It does nothing means 3 votes. – SteeveDroz – 2013-04-27T06:56:06.257

Shouldn't the lame score example above be (13 - 13) / 13 = 0 ? – Paul R – 2013-04-27T07:04:13.610

What happens when somebody has an answer with no guesses? ZeroDivisionError? – Volatility – 2013-04-27T07:10:44.783

The lame score is correct. You take the highest wrong answer. The lame score has 0 wrong answers → -100% – SteeveDroz – 2013-04-27T08:00:10.347

If someone has 0 guesses, well. I suppose it was too tough for anyone to answer. The rules of the game are not carved in stone. You can still give it a try to help them, if you think it's fairer. – SteeveDroz – 2013-04-27T08:01:34.443

4I 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%. – ugoren – 2013-04-29T14:38:58.930

1I already "do something that looks like something else". I sit at my desk all day, and it looks like I'm working... – WallyWest – 2014-01-20T23:04:02.723

Too bad the challenge ended, @Eliseod'Annunzio, you would have won! – SteeveDroz – 2014-01-21T14:27:20.573

Answers

79

Javascript

var а;
a = 1;
а++;
alert( a );

Answer: It outputs 1. The comments below explain it pretty well - there are two different variables here, a - 'LATIN SMALL LETTER A' and а - 'CYRILLIC SMALL LETTER A'.

There was 1 correct answer, 50 people thought it outputs 2, and with a total of 52 answers, the score is (50 - 1) / 52 = 49 / 52 = 94,23%

Danko Durbić

Posted 2013-04-23T07:08:03.090

Reputation: 10 241

http://meta.codegolf.stackexchange.com/a/1657/34543 – Loovjo – 2015-04-09T10:03:33.323

Yeah, I know, but this answer is about a year older than that rule :) – Danko Durbić – 2015-04-09T14:32:44.260

57Outputs 2 or at least that is what I hope :) – Alexander – 2013-04-23T23:32:24.403

Outputs 1 or throws a TypeError. (I can't decide definitively, of course.) – Ry- – 2013-04-23T23:42:40.913

8This is the sneakiest JS snippet I've seen yet. Well played. – Peter Majeed – 2013-04-24T14:32:46.487

1

For those who don't get it (spoilers ahead): link

– BlueRaja - Danny Pflughoeft – 2013-04-24T18:59:22.997

3

@soandos: (AGAIN, SPOILERS): The variable used in the first and third lines is different from the one in the second and fourth. One uses a (U+0061) while the other uses а (U+0430). See also.

– BlueRaja - Danny Pflughoeft – 2013-04-24T20:54:31.433

@BlueRaja-DannyPflughoeft, got it, feel free to delete now – soandos – 2013-04-24T20:55:49.300

Outputs true. – Kevin – 2013-04-24T22:43:51.357

I'm pretty sure I'm wrong, but that's what I decided after a few seconds of looking at the snippet and before reading the comments, so I guess, I'm committed to it xP – Kevin – 2013-04-24T22:44:32.923

5

A friend of mine thought this was pretty funny and was inspired to write this https://github.com/johnhaggkvist/WATifyJS - He had too little rep to comment so I'm doing it for him ^_^

– Henrik Andersson – 2013-04-26T09:45:26.670

@limelights - Great stuff. I'm glad this inspired someone to do something useful :) – Danko Durbić – 2013-04-26T12:32:36.950

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. – SteeveDroz – 2013-04-27T06:23:40.647

Now only if everyone used "use strict;" before every such JS snippet... – Peter Majeed – 2013-04-27T18:21:06.107

32

C, Score 33.3%

#include <stdio.h>
int main(int ac, char **av) {
        const char *arg = av[1];
        #define valid_ch(ch) (ch!='&' && ch!='\\')  // All valid except & and \
        while (*arg)
        {
                if (valid_ch(*arg)) putchar(*arg);
                arg++;
        }
        puts("");
        return 0;
}

Run ./prog 'Hello & goodbye, world!'

Score

The correct answer is H\n (the while is part of the comment, thanks to the line ending with \, so there's no loop), given by 6 people.
The most popular mistake was Hello goodbye, world\n, given by 25 people.
(25 - 6) / 57 = 33.3%.
Thanks to Olivier Dulac for bothering to calculate.

ugoren

Posted 2013-04-23T07:08:03.090

Reputation: 16 527

24Prints "Hello goodbye, world!\n"... – Vi. – 2013-04-23T11:42:47.623

5It is an endless loop. – None – 2013-04-23T12:03:40.097

It prints nothing – copy – 2013-04-23T15:26:16.193

5Only prints the first character in the arg and a newline. So it prints H\n. – marinus – 2013-04-23T15:37:06.877

7Prints: Hello goodbye, world! (no \n) (2 spaces after Hello) – Olivier Dulac – 2013-04-23T15:51:52.327

6produces a SEGFAULT. – pascalhein – 2013-04-23T16:57:00.560

it writes endless Hs – ratchet freak – 2013-04-23T19:35:25.737

1Syntax error: unclosed (. (Because the valid_ch expands to the comment too, and the rest of the line, including the ), is commented out.) – Rory O'Kane – 2013-04-24T21:33:22.587

I have no idea. The const char * looks suspicious. – user606723 – 2013-04-26T11:32:05.773

Outputs 'H' (more chars to be able to save) – f.ardelian – 2013-04-26T21:43:08.710

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. – SteeveDroz – 2013-04-27T06:24:11.180

Total 57 answers: 6 thought H\n, 25 thought Hello goodbye, world!\n, 26 thought something else (at least it is when I made this comment). So score is (25 - 6) / 57 = 33.3%. (I hope this is correct?) – Alvin Wong – 2013-04-27T10:18:43.893

Now you can try adding syntax highlighting (bug) to this code :)

– Alvin Wong – 2013-04-27T10:31:14.493

@AlvinWong, seems correct (didn't recount everything). – ugoren – 2013-04-27T14:06:18.850

Well, I thought it outputs just H, can you explain, why new line is printed? – ST3 – 2014-01-17T19:05:57.890

@ST3, puts(""); – ugoren – 2014-01-18T20:47:50.690

Oh man... I'm so stupid. – ST3 – 2014-01-18T21:05:34.213

27

Python

a = []
for i in range(10):
    a.append(i * ++i)
for a[i] in a: 
    print(a[i])

Rating

  1. Good answer: Prints 0 1 4 9 16 25 36 49 64 64, each number on one line.

  2. Explanation: Despite nobody getting the right answer, I consider this mostly a failed attempt, because nobody made the mistake I had intended. (I'll add a real explanation later if nobody else does.)

  3. Number of good answers: 0

  4. Number of peoply with same wrong answer: 7

  5. Total number of answers: 11

  6. Score: 63,64 % (rounded to two decimals)

Explanation

First, a list a is created and filled with values i * ++i. There is no ++ operator in Python, but there is a unary + operator, which does nothing for integers, and applying it two times still does nothing. So a contains the squares of the integers from 0 to 9.

I had put the ++ as a distraction and hoped that most voters would go on, thinking they had found the trap, and fall into the real trap. It didn't work out. Some thought that ++ is a syntax error, and the others still looked for the trap.

The trap The trap was in the second for loop:

for a[i] in a: 
    print(a[i])

I was sure that most people would think this prints out all the a[i], i.e. 0 1 4 9 16 25 36 49 64 81, each number on one line. That's what you get with this variaton, for example:

for x in a: 
    print(x)

x is assigned the values in a, and then x is printed. In the first version, a[i] is assigned the values in a, and then a[i] is printed. The difference is, that in our case we have i == 9, and thus the value of a[9] is changed each time through the loop. When finally a[9] is printed, it has the value of a[8], and thus 64 is printed again.

Reinstate Monica

Posted 2013-04-23T07:08:03.090

Reputation: 929

3Syntax error (no ++ in Python). – ugoren – 2013-04-24T14:06:02.543

5SyntaxError on the second for. – Bakuriu – 2013-04-24T14:39:00.163

Prints 81 ten times – Michael0x2a – 2013-04-24T18:04:38.873

SyntaxError on the second for. This is amazing. This really should win. It took me 5 mins to understand what was happening lol! – rubik – 2013-04-26T09:58:41.493

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. – SteeveDroz – 2013-04-27T06:29:03.290

Cannot reproduce. Executing this on Python2/3 correctly raises a SyntaxError on the second for. Your score is (7 - 7) / 11 = 0%. [Note that 7 people gave this answe. rubik put an other comment instead of voting up, but its answer is the same, hence should be counted together.] – Bakuriu – 2013-04-27T08:16:11.063

@Bakuriu: Why on earth should this be a SyntaxError? Ideone.com runs it without problems: link

– Reinstate Monica – 2013-04-27T08:28:58.453

@Bakuriu: Thanks for pointing out rubik's answer. I updated my score. – Reinstate Monica – 2013-04-27T08:35:38.520

@WolframH I cannot run it on my pc. The interactive interpreter gives a SyntaxError on the second for. – Bakuriu – 2013-04-27T08:43:40.670

Okay, I understand now. I knew that for a[i] in a would give a SyntaxError because it's something that I have already tried on it. But I must say that in this case python's syntax is broken.The interactive interpreter shouldn't behave differently. Also, according to the grammar, every expression should be valid, but if you try: for i+j, in a: you'll receive a SyntaxError: can't assign to operator which is simply wrong. According to the grammar you shouldn't get any error at compile time!

– Bakuriu – 2013-04-27T09:12:35.343

@Bakuriu: You need a : at the end of a for statement. The command line interpreter has no problems with the syntax. – Reinstate Monica – 2013-04-27T09:31:03.580

@Bakuriu compile time in Python? – Display Name – 2013-12-29T18:15:41.860

26

JavaScript, Score of -100%

I did not invent this, Gary Bernhardt did but it is one of my favourites

alert(Array(16).join("wat?" - 1)+", BATMAN!")

mplungjan

Posted 2013-04-23T07:08:03.090

Reputation: 369

37Outputs NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN, BATMAN! :) – codefreak – 2013-04-24T08:22:42.610

1This 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. – SteeveDroz – 2013-04-27T06:25:00.603

Seems like that video is quite famous... – Bakuriu – 2013-04-27T08:27:43.577

3Is this -100%?... – Alvin Wong – 2013-04-27T10:20:32.417

Of course. The batman gives it away. – mplungjan – 2013-04-27T12:57:25.293

Should use atob("QkFUTUFOIQ==") for "BATMAN!" – bendytree – 2013-10-03T19:46:12.577

14

Perl, 26.67%

Results:

This prints "I am ambivalent about saying anything at all."

my $num1,$num2 = @_; is missing parentheses. Therefore, it is equivalent to my $num1; $num2 = @_;. $num1 doesn't get set to anything.

Thus $num1 is never greater than zero. The bit about the secret fish world hidden off the screen is, err, a red herring, so that people think they have found the "trick".

Furthermore, the ternary operator is an l-value in Perl: 1 ? $a = 1 : $b = 2 actually means (1 ? $a = 1 : $b) = 2. Which means ($a = 1) = 2 is evaluated, setting $a to 2. Contrary to appearances, The second string is assigned to $num1.

In case you are wondering,// is the defined-or operator. If the sub returned an undefined value, the string "Stuff did not happen." would be printed. But it doesn't actually happen. It was just to give people another option.

Scoring:

Total correct: 5

Total guesses: 30

Score: (13 - 5) / 30 = 26.67%

no warnings;
no strict;
no feature;
no 5.16;
no Carp;

sub do_mysterious_stuff
{
    my $num1,$num2 = @_;               

    if ($num1 > 0)
    {                                                                                                                  eval q; $num1="This is a secret fish world. Carp cannot be repressed!" or
       $num1 = "Hello, world!";
    }
    else
    {
        $num2 > 0 ? 
            $num1 = "What's up, world?": 
            $num2 = "I am ambivalent about saying anything at all.";
    }

    return $num1;
}

print do_mysterious_stuff(1,1) //"Stuff did not happen.";

user7486

Posted 2013-04-23T07:08:03.090

Reputation:

2It outputs, I am ambivalent about saying anything at all. – marinus – 2013-04-23T10:37:20.257

10It prints This is a secret fish world. Carp cannot be repressed!. – ugoren – 2013-04-23T13:02:32.137

13Not being a perl guru this should print Hello, world!. – Alexander – 2013-04-23T14:56:47.180

2Well, that's it guys. I'm never dealing with Perl again. – Mr. Llama – 2013-04-23T16:15:40.687

Why does this print $num2? – ContextSwitch – 2013-04-23T16:59:51.973

1Prints This is a secret fish world. Carp cannot be repressed! and then NaN on another line? – Ry- – 2013-04-23T23:47:58.593

2It will print I am ambivalent about saying anything at all, as $num1 remains undefined, and $num2 is set to the length of @_ as my $num1,$num2 = @_; is equivalent to my $num1; $num2 = @_;. – primo – 2013-04-24T02:45:31.903

I guessed the right answer, but for wrong reasons. Very good, on a number of levels. Still can't figure out quite why that ternary operator does what it does. – aidan – 2013-04-24T06:02:42.973

3@ContextSwitch and @aidan, the ternary operator is an l-value in Perl. 1 ? $a = 1 : $b = 2 actually means (1 ? $a = 1 : $b) = 2. Which means ($a = 1) = 2 is evaluated, setting $a to 2. Also, as Primo pointed out, my $num1, $num2 = @_; doesn't do what you expect because the parentheses are missing. – None – 2013-04-24T06:04:02.013

1It prints What's up, world?. – Gieron – 2013-04-24T11:44:54.620

Some sort of error because // is not in-line comments in perl.. Also your semi-colon is at the end of those 'comments' – user606723 – 2013-04-26T11:19:58.087

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. – SteeveDroz – 2013-04-27T06:25:27.433

@Oltarus, I'm not quite sure I understand the scoring. Feel free to edit my answer to correct it if I didn't get it right. Thanks, this was a fun question. – None – 2013-04-29T07:37:27.670

It was almost good except you took the total number of votes (30) instead of the number of votes for the most given answer: 13 with Hello, world!. I edited your score. – SteeveDroz – 2013-04-29T08:05:37.107

14

Python, -54.8%

Answer: Raises SyntaxError: not a chance

from __future__ import braces

if (input() > 0) {
print 'You entered a positive number';
}
else {
print 'You didn\'t enter a positive number';
}
  • Good guesses: 24
  • Same bad guesses: 7
  • Total guesses: 31

Explanation:

from __future__ import braces is one of the easter eggs in Python. It is meant as a joke, saying that Python will never use braces for scoping in the future.

Volatility

Posted 2013-04-23T07:08:03.090

Reputation: 3 206

6Tests if the result of a user-supplied expression is signed. – Felix Dombek – 2013-04-23T14:31:42.157

1I suspect there are quite a few errors. Python programmers are stubborn ;) – grc – 2013-04-23T14:34:22.540

12This is a Syntax error! – Dhara – 2013-04-23T14:48:12.943

11SyntaxError: not a chance – Bakuriu – 2013-04-23T23:49:19.880

2@BoppreH Please limit yourself in stating the outcome without any kind of explicit explanation or upvote the comment that already states the result you think is correct. Other kind of comments only ruin the fun for following readers. – Bakuriu – 2013-04-24T21:54:37.777

@Bakuriu Sorry, deleted the comment. – BoppreH – 2013-04-25T19:07:14.570

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. – SteeveDroz – 2013-04-27T06:25:45.683

14

PHP 52%

  $arg = 'T';
  $vehicle = ( ( $arg == 'B' ) ? 'bus' :
               ( $arg == 'A' ) ? 'airplane' :
               ( $arg == 'T' ) ? 'train' :
               ( $arg == 'C' ) ? 'car' :
               ( $arg == 'H' ) ? 'horse' :
               'feet' );
  echo $vehicle;

(Copied verbatim from here)

Explanation & Score

The correct answer is horse. This isn't a trick or sleight of hand. Bizarrely, this is how the ternary operator is defined in PHP.
3 chose the correct answer: horse,
16 people chose train which is correct in literally every other language ever invented, except PHP.
25 answers total, giving a score of (16 - 3) / 25 = 52%

aidan

Posted 2013-04-23T07:08:03.090

Reputation: 241

5feet​​​​​​​​​​​​​ – wim – 2013-04-24T04:03:11.333

15prints train. – SteeveDroz – 2013-04-24T06:00:19.957

3prints 'horse'. – Jonathan – 2013-04-24T12:19:24.227

1http://phpsadness.com/sad/30 – mob – 2013-04-25T15:20:19.447

1And that... is why you should almost always use parenthesis to indicate order of operations, even if you think you don't need them. – Ryan Amos – 2013-04-26T02:54:28.993

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. – SteeveDroz – 2013-04-27T06:26:02.187

Typo in your edit. "3 got it right ('horse'), 16 people choose s/'horse'/'train'/ which is..." – Bakuriu – 2013-04-27T08:29:33.787

12

C++ 28.9%

#include <iostream>

using namespace std;

void print( void ) {
  static int times = 0;

  switch( times ) {
  case 0:
     cout << "Hello";
     break;
  case 1:
     cout << "World";
     break;
  default:
     cout << "Goodbye";
     break;
  }
  times++;
}

int main(int cout, char* argv[]) {

  print();
  cout << '\n';
  print();
}

Solution

The point of this code is to trick the user into thinking that a newline character will be printed between the text "Hello" and "World". Notice that the first parameter to main is named cout. Since, in the scope of main, cout is an integer, the << operator actually performs a left shift operation with a parameter of '\n', rather than printing a newline. The print function is there mainly to take attention away from the input parameters in main, but also to allow std::cout to be used without adding the namespace prefix.

Score

Courtesy of Alvin Wong

  • Total 38 answers:
  • 12 thought HelloWorld (considering minitech's and zeel's are the same)
  • 23 thought Hello\nworld 3 thought something else.
  • Score is (23 - 12) / 38 = 28.9%

Nick Hartung

Posted 2013-04-23T07:08:03.090

Reputation: 221

23Prints "Hello" in one line, and "World" in the next. – redtuna – 2013-04-23T20:44:25.507

2Prints "HelloWorld". Puts 1024 in cout if called without parameters. – Alexander – 2013-04-23T23:25:38.013

9Prints HelloWorld. – Ry- – 2013-04-23T23:44:14.263

1Prints HelloWorld. And performs a bit wise left shift on the integer "cout". – zeel – 2013-04-24T03:29:18.660

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. – SteeveDroz – 2013-04-27T06:26:47.237

Total 38 answers: 12 thought HelloWorld (considering minitech's and zeel's are the same), 23 thought Hello\nworld, 3 thought something else. So score should be (23 - 12) / 38 = 28.9%. – Alvin Wong – 2013-04-27T10:25:07.657

10

Ruby, 100%

display = lambda { puts "Hello, world!" }
display()

Correct answer:

Prints "main" with no newline. Explanation: In Ruby, you can't call a lambda using the normal parentheses syntax. Instead, display() is interpreted as the built-in method all objects have: o.display prints o.to_s to standard output. Methods called without an object are interpreted as methods of "main", an Object that includes the Kernel module.

Score: 3 of the same wrong answer, no other answers.

histocrat

Posted 2013-04-23T07:08:03.090

Reputation: 20 600

3Prints "Hello, world!" – 3Doubloons – 2013-04-26T02:35:41.777

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. – SteeveDroz – 2013-04-27T06:37:42.537

8

Python, -28.13%

x = 0
while x < 10:
    if (x%2)==0: x += 2
else: x += 1

print x

This prints 11 because the else block, which belongs to the while, is executed after the loop is exited.

  • Maximum number of false guesses: 8
  • Correct guesses: 17
  • Total guesses: 8 + 17 + 7 = 32

Score: (8 - 17) / 32 = -28.13%

flornquake

Posted 2013-04-23T07:08:03.090

Reputation: 1 467

7Fails because of missing indentation in else: – Alexander – 2013-04-23T23:34:32.553

16Prints 11 on one line. – Bakuriu – 2013-04-23T23:51:22.343

6This prints 10. – copy – 2013-04-23T23:57:47.613

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. – SteeveDroz – 2013-04-27T06:28:06.770

8

Python: Rating: -27%

name = "Robin"
seek = "Seek and find holy grail"
favorite_color = "blue"

from os import *

print "What is your name: %s" % name
print "What is your quest: %s" % seek
print "What is your favorite color: %s" % favorite_color

The program prints:

What is your name: <value of os.name> 
What is your quest: Seek and find holy grail
What is your favorite color: blue

Rating: Total opinions: 22 12 correct 3 + 1 + 6 wrong [for Bakuiru's answer, I would say it was close but still incorrect as os.name is a string (os.uname is a function)]

Rating based on that assumption and my understanding of the rating system: Maximum wrong = 6 Correct = 12 Score = (6-12)/22 = -27%

Foon

Posted 2013-04-23T07:08:03.090

Reputation: 201

11Prints What is your name: [operating system name], What is your quest: Seek and find the holy grail, What is your favourite color: blue on separate lines. Obviously [operating system name] is replaced by the actual name. – Volatility – 2013-04-24T03:06:28.657

3Displays the 3 last line with values name = "Robin", seek = "Seek and find holy grail" and favorite_color = "red", oh, no. blue! (AAARRGGGHHH!) – SteeveDroz – 2013-04-24T05:59:12.090

5Prints something like What is your name: <function os.name at 0x....> etc. – Bakuriu – 2013-04-24T09:09:32.403

Outputs What is your name: Robin, What is your quest: Seek and find holy grail, and What is your favorite color: blue on separate lines. – Rory O'Kane – 2013-04-24T21:42:17.733

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. – SteeveDroz – 2013-04-27T06:28:29.773

I knew that the variables would be replaced by something by os, but I forgot that os.name is a string and not a function... – Bakuriu – 2013-04-27T16:19:02.693

7

JavaScript, -46.7%

var getResult = function(n, notReadyYet) {
    alert("Calculating results...");
    if (notReadyYet) {
        setTimeout(getResult, 100, n);
    } else {
        sayResult(n);
    }
    return arguments.callee;
}

var sayResult = function(n) {
    if (n >= 10) {
        alert("That's a big number!");
    }
    if (n < 10) {
        alert("That's a small number.");
    }
    return n;
}

(function() {
    var input = parseInt(prompt("Please enter a number:"));
    var result = getResult(input, true);
    return result;
})();

You can run it here when you're ready (have a guess first!). If you scroll down far enough in the JS panel, you will see the code with a brief explanation.

Correct answer:

After asking the user to enter a number, it will enter into an infinite loop and display "Calculating results..." alerts until the maximum call stack size is exceeded (although the jsfiddle example will stop after about 20 times). However, if a semicolon is placed after the closing brace of the sayResult function, it will work as mgibsonbr described in the comments.

Scoring:

  • Good answers: 9
  • Most popular false opinion: 2
  • Total answers: 15

grc

Posted 2013-04-23T07:08:03.090

Reputation: 18 565

It asks for a number with the question Please enter a number: and returns you answer followed by true. – SteeveDroz – 2013-04-23T14:41:40.303

8it locks into an infinite loop by popping up "Calculating results" ad infinitum – SeanC – 2013-04-23T14:47:30.157

It prompts for a number, alerts "Calculating results" twice, then alerts "That's a _ number" – mgibsonbr – 2013-04-24T06:29:09.550

1It outputs That's a big number after a delay equal to the number you input in ms. – Gieron – 2013-04-24T11:53:27.133

Depending on the browser and/or how the DOM is set up (I'm really new to JS), it outputs the name of the function that is called on page load. – Kevin – 2013-04-24T22:54:55.473

Doesn't output anything (except 'Please enter a number' once and 'Calculating results...' twice), returns undefined. – f.ardelian – 2013-04-26T21:54:59.953

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. – SteeveDroz – 2013-04-27T06:27:19.923

7

Python

import sys

class TwoPlusTwoIsFive(object):
  def __bool__(self):
    if 2 + 2 == 5:
      return True
    else:
      return False

two_plus_two_is_five = TwoPlusTwoIsFive()

if two_plus_two_is_five:
  print('{} is company'.format(sys.version[0]))
else:
  print('{} is a crowd'.format(sys.version[0]))

edit:

score (8-1)/9 == 77.7 %

correct output is '2 is company' on python 2, '3 is a crowd' on python 3.

wim

Posted 2013-04-23T07:08:03.090

Reputation: 585

72 is a crowd (in Python 2, 3 in Python 3). – ugoren – 2013-04-24T04:23:09.213

2 is company (in Python 2), or 3 is a crowd (in Python 3). – Reinstate Monica – 2013-04-24T13:51:05.070

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. – SteeveDroz – 2013-04-27T06:28:46.290

5Damn special method renaming! :) – Bakuriu – 2013-04-27T08:11:02.607

6

Javascript

var a = [];
a.push( "Hello" );
a.concat( [ ", ", "world", "!" ] );
alert( a.join("") )

Answer: It alerts Hello. The concat method does not modify the array - it returns an array which contains the concatenation of the array it's called on and any other supplied arguments.

15 correct, 26 wrong, 41 answers in total and the score is (26-15) / 41 = 11 / 41 = 26,83%

Danko Durbić

Posted 2013-04-23T07:08:03.090

Reputation: 10 241

25Alerts Hello, world! – SteeveDroz – 2013-04-23T15:03:00.350

14It alerts Hello – Volatility – 2013-04-23T15:03:19.910

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. – SteeveDroz – 2013-04-27T06:27:39.927

5

C# 62.5%

int sum=0;
List<Task> threads = new List<Task>();
for (int i=1; i<=10; i++) {
  Task adder = new Task( ()=> sum += i );
  threads.Add( adder );
  adder.Start();
}
foreach (var t in threads ) { 
  t.Wait();
}
Console.WriteLine("Sum of all numbers in 1..10 is: "+sum);

This is my first code golf.

The correct answer was: "something between 55 and 110". That's because whenever the "sum+=i" statement executes, it'll use the current value of i. This code might even execute after the for loop is done, at which point i has value 11. This makes the highest-possible value 110 (and you can make sure to see it if you slow down the lambda in your testing). The smallest possible value is sum(1..10), which is 55.

  • Good answers: 0
  • Only approximately good answers: 5
  • Number of times the most popular answer was selected: 5
  • Total answers: 8

score: strictly speaking, no one got it right so the score should be (5-0)/8=62.5%. If we're willing to count "approximately good" as a correct answer, then the score is (5-5)/8=0%

redtuna

Posted 2013-04-23T07:08:03.090

Reputation: 151

4Prints an indeterminate number from 55 to 100, inclusive. – Ry- – 2013-04-23T23:51:57.453

It just prints 100. – Kevin – 2013-04-25T05:44:48.253

1Prints a 'random' number between 0 (inclusive) and 110 (inclusive) – fjdumont – 2013-04-25T08:38:14.147

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. – SteeveDroz – 2013-04-27T06:29:40.260

I'm happy that most people got it mostly right - presumably right enough that they'll know not to make that mistake in their code! – redtuna – 2013-04-29T17:13:29.120

Even if you count no answer as correct, your score isn't 100%, but 5/8 = 62.5%, because the most common mistake was chosen by 5 people. – ugoren – 2013-04-29T19:02:55.270

ah, you're right. Let me fix that. – redtuna – 2013-04-29T22:53:57.927

5

Java

public class Puzzle {

    public static void main(String[] args) {
        String out = "Some ungodly gibberish";
        //char x = \u000a; out = out + " and then some more. ";
        System.out.println(out);
    }
}

First attempt at codegolf...

good answer: Prints Some ungodly gibberish and then some more. and a newline

Rating:

  • Maximum number of guesses 6
  • Total number of guesses 11
  • number of correct guesses 5 (0 if you're in pedanitc mode)

Score: 9% (55% in pedantic mode)

Nicktar

Posted 2013-04-23T07:08:03.090

Reputation: 151

5Prints Some ungodly gibberish and then some more. – cardboard_box – 2013-04-24T18:26:26.137

6Prints Some ungodly gibberish with a newline – MrZander – 2013-04-24T19:09:29.477

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. – SteeveDroz – 2013-04-27T06:31:00.483

5

Python 33.3%

def Test():
    False = True
    True = False
    if False:
        return False
    elif True:
        return True
    else:
        return None

a = Test()
print a

Note: Assume this is Python 2.x, and not Python 3.


When run, this code produced an UnboundLocalError: local variable 'True' referenced before assignment.

TerryA

Posted 2013-04-23T07:08:03.090

Reputation: 171

1Raises a SyntaxError – Volatility – 2013-04-25T12:47:54.753

Shouldn't that be False, True = True, False? – None – 2013-04-25T12:59:07.720

It is what it is. (either way, I think that doesn't make a difference in this case) – TerryA – 2013-04-25T13:01:42.807

4This prints True. – Reinstate Monica – 2013-04-25T15:44:14.930

1Raises an UnboundLocalError. – Bakuriu – 2013-04-25T16:50:25.380

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. – SteeveDroz – 2013-04-27T06:31:20.437

4

PHP, 100%

First time posting to code gulf, hopefully this isn't to bad.

function word_to_num($word) {
 switch ($word) {
  case "one":
   return 1;
  case "two":
   return 2;
  case "three":
   return 3;
  default:
   return "error";
 }
}
function print_word($num) {
 switch ($num) {
  case 1:
   print "hello";
   break;
  case 2:
   print "world";
   break;
  case "error":
  default:
   print " ";
  }
}

$words = array("one", 0, "two");
foreach ($words as $word) {
 $result = word_to_num($word);
 print_word($result);
}

correct output is 'hellohelloworld'

score is (10 - 0) / 10 = 1 = 100%

Echo says Reinstate Monica

Posted 2013-04-23T07:08:03.090

Reputation: 141

9Prints hello world. – flornquake – 2013-04-23T21:51:39.340

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. – SteeveDroz – 2013-04-27T06:33:00.990

Oh, haha. Darn PHP. – Ry- – 2013-04-27T18:13:20.213

'one' == 0 => true. Quite clever. – primo – 2013-05-02T07:18:40.600

4

Python, -83.3%

Answer: Prints a < b if the inputs are equal, a = b if the first is larger, and a > b if the second is larger.

a = input()
b = input()
print 'a', '<=>'[cmp(a, b)], 'b'
  • Good guesses: 11
  • Same bad guesses: 1
  • Total guesses: 12

Explanation:

cmp(a, b) returns 0 if both arguments are equal, 1 if the first is larger, and -1 if the first is smaller, which is why the wrong comparison symbol is printed.

Volatility

Posted 2013-04-23T07:08:03.090

Reputation: 3 206

7Prints a = b if a > b a < b is a == b, or a > b if a > b – Foon – 2013-04-24T01:31:50.043

prints a = b for input a == b, a < b for input a > b, and a > b for input a < b – wim – 2013-04-24T02:02:33.180

2Prints a = b if a > b, a < b if a == b, a > b if a < b. (This is probably what @Foon meant.) – flornquake – 2013-04-24T18:39:49.070

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. – SteeveDroz – 2013-04-27T06:30:00.263

1I think that this is better than the score shows. If I hadn't beed in Error-Finding-Mode, I might not have found it. – Reinstate Monica – 2013-04-27T08:15:58.590

4

Perl: 100% (4-0)/4

print (1 + 2) * 3, "\n"; 
#

This program prints "3" without a new line. Perl parses this instruction as

((print (1+2)) * 3, "\n")

so only the (1+2) is passed as an argument to print.

mob

Posted 2013-04-23T07:08:03.090

Reputation: 2 506

3Prints 9 followed by a newline – 3Doubloons – 2013-04-25T20:07:56.220

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. – SteeveDroz – 2013-04-27T06:37:26.020

3

C (Score: 4.45%)

Good guesses: 7
Maximum of wrong guesses: 6+2 = 8
Total guesses: 6+7+3+2+4=22

Solution: ??/ is a trigraph for \, so the newline is escaped and the scanf line is commented out. Therefore the program runs forever, printing Guess a number between 1 and 10:. The comments are a quote from Mozart (via fortune).

// Why not?/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// What?/
int main(int argc, char** argv)
{
    // Why not?/
    int number;

    // Why should I not send it?/
    srand(time(NULL));

    while(1)
    {
        // Why should I not dispatch it?/
        printf("Guess a number between 1 and 10: ");

        // Why not??/
        scanf("%d", &number);

        // Strange! I don't know why I shouldn't/
        if(number == rand() % 10 + 1)
        {
            // Well, then/
            printf("You guessed right!\n");
            // You will do me this favor./
            exit(0);
        }
    }
}

Spoiler, how to compile and run:

gcc test.c -trigraphs

copy

Posted 2013-04-23T07:08:03.090

Reputation: 6 466

5Comments are just distractions. Program is "Guess the random number from 1 to 10". – luser droog – 2013-04-23T16:59:54.460

6"Guess a number between 1 and 10: Guess a number between 1 and 10: Guess a number between 1 and 10: " (and so on) without asking for input – pascalhein – 2013-04-23T19:10:41.820

2Something evil is hidden in the comments as they look like C++. – Alexander – 2013-04-23T23:31:19.053

1Eventually, prints "You guessed right!", and a newline, and then ends. – Kaz Dragon – 2013-04-24T08:11:14.243

4The evil comment has something to do with trigraphs. – shiona – 2013-04-24T08:40:40.977

There are no trigraphs. It's just another distraction. – luser droog – 2013-04-25T01:11:56.793

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. – SteeveDroz – 2013-04-27T06:32:21.927

3

Java

public class Test {
    public static void main(String[] args) {
        String fmt = "%s - %04d\n";
        System.out.println(fmt.format("Padded value: ", 0x0c));
    }
}

The Answer

It prints Padded value: (with a newline).

String's format method is static, with the format being passed as the first parameter. I.e. the call above is equivalent to:

        System.out.println(String.format("Padded value: ", 0x0c));

Number of good answers: 2 Wrong answers: 9

Score: (9-2) / 11 = 63%

Paul Cager

Posted 2013-04-23T07:08:03.090

Reputation: 131

8This prints Padded value: - 0012\n – copy – 2013-04-23T17:49:25.403

1This prints "Padded value: ` followed by a newline character. – Alvin Wong – 2013-04-24T07:49:35.130

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. – SteeveDroz – 2013-04-27T06:29:20.323

3

CPython

if 'Hello' + 'World' is 'HelloWorld':
  print 'Hello'
if 'Hello' + 'World!' is 'HelloWorld!':
  print 'World!'

correct output is 'Hello'

score (14-3)/19 == 57.9 %

wim

Posted 2013-04-23T07:08:03.090

Reputation: 585

13Prints nothing. – TerryA – 2013-04-24T03:18:29.767

1Prints Hello\nWorld!. – Bakuriu – 2013-04-24T09:12:40.370

2Prints Hello. (Implementation dependent.) – Reinstate Monica – 2013-04-24T13:46:23.000

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. – SteeveDroz – 2013-04-27T06:30:20.403

3

C

#include <stdio.h>
#define SIX  1+5
#define NINE 8+1

int main()
{
    printf("%d\n", SIX * NINE);
}

Score = (3-16)/19 == -68.4%

Don't forget your towel.

Kaz Dragon

Posted 2013-04-23T07:08:03.090

Reputation: 149

15It prints 42 + a newline – Paul Cager – 2013-04-24T08:08:52.040

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. – SteeveDroz – 2013-04-27T06:30:40.263

I just noticed your puzzle. I would have gotten it wrong xP I'm a Java/C# programmer, so that's my excuse... – Kevin – 2013-04-29T07:34:43.537

3

C#

static void Main(string[] args)
{
     Console.WriteLine('H' + 'e' + 'l' + 'l' + 'o');
     Console.ReadLine();
}

Crispy

Posted 2013-04-23T07:08:03.090

Reputation: 161

3Prints the sum of the ASCII values of each letter (500) – 3Doubloons – 2013-04-24T23:07:23.893

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. – SteeveDroz – 2013-04-27T06:36:18.610

To be fair, the first time I saw it I thought it'd print "Hello", but then did a double-take. – redtuna – 2013-04-29T17:17:04.307

3

C++

#include <cstdio>

int main()
{
    int f;

    f or (f = 0, f < 1000, ++f,
        printf("H ello world !\n"));

    return 0;
}

Score = (1 - 6) / 7 = -0.71428571428571 = -71.428571428571%

Paul R

Posted 2013-04-23T07:08:03.090

Reputation: 2 893

5That does nothing. – SteeveDroz – 2013-04-25T11:17:07.713

Doesn't compile. – f.ardelian – 2013-04-26T22:12:44.297

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. – SteeveDroz – 2013-04-27T06:33:39.947

2

R: 100%

Not that imaginative but might puzzle some people:

sum(data.frame(rep(1,10),stringAsFactors=TRUE))

What do you think is the result?

Edit:

The answer was 20. Because of a missing s in stringAsFactors (instead of stringsAsFactors), the argument is not recognized so the function create a new column called stringAsFactors. Because of vector recycling, the column contains 10 times TRUE which are converted to 1s in the sum, hence a total of 20 and not 10.

This answer was not given in the comments. 3 answers were given (all saying 10 more or less). Hence a score of an 100%, I guess.

plannapus

Posted 2013-04-23T07:08:03.090

Reputation: 8 610

Returns the value 10. – SteeveDroz – 2013-04-23T13:20:06.067

1I initially thought it would return 10. Sneaky... leaving off that one "s" really changes things... – Dason – 2013-04-23T22:01:43.757

1@Dason I now realize that suppressing the second one would have been even sneakier: one would assume partial matching would correct for it but it turns out it doesn't. – plannapus – 2013-04-24T06:47:10.190

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. – SteeveDroz – 2013-04-27T06:31:40.657

100%! Congrats! – redtuna – 2013-04-29T17:16:07.977

2

Tcl

Inspired by ugoren

foreach c [split [lindex $argv 0] {}] {
    # Don't print the invalid chars & and \
    if {$c in "& \\"} {continue}
    puts -nonewline $c
}

Sorry, forgot an example string. Ok, run as

./charfilter.tcl 'Hello & goodbye, world!'

Edit Right solution: It does not filter at all. (6x)
Max wrong answer: 4x
Total answers: 10
Score: -0.2

Johannes Kuhn

Posted 2013-04-23T07:08:03.090

Reputation: 7 122

5It just prints its argument and doesn't actually filter. – marinus – 2013-04-23T15:34:36.317

3it prints its argument without " ", "&", "\". – pascalhein – 2013-04-23T16:25:39.103

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. – SteeveDroz – 2013-04-27T06:32:00.707

2

Python

def greeting():
  try:
    return 'Hello World'
  finally:
    return 'HELL0 W0RLD'

print greeting().lower()

correct output is 'hell0 w0rld'

score (8-14)/22 == -27.3 %

wim

Posted 2013-04-23T07:08:03.090

Reputation: 585

7Prints: hello world – TerryA – 2013-04-24T03:21:29.713

14Prints hell0 w0rld – SteeveDroz – 2013-04-24T06:02:13.087

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. – SteeveDroz – 2013-04-27T06:33:20.600

2

JavaScript

var x = 0;
var y = !x * 4;
var z = !y;
alert("Z = "+z);

Tushar Koul

Posted 2013-04-23T07:08:03.090

Reputation: 121

13It alerts Z = false. – SteeveDroz – 2013-04-24T14:49:37.743

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. – SteeveDroz – 2013-04-27T06:35:20.437

2

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

ST3

Posted 2013-04-23T07:08:03.090

Reputation: 1 279

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. – flornquake – 2013-09-21T23:14:45.323

@flornquake so you said it is just a guess and it is wrong. – ST3 – 2013-09-22T19:01:25.767

1

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

Anbarasan

Posted 2013-04-23T07:08:03.090

Reputation: 79

22Prints 1. Are you assuming people don't know what ** does? – ugoren – 2013-04-23T11:35:01.987

2It'd be a harder question if it was rather a**a ;) (but still not in the spirit of this Q, perhaps) – Sean Allred – 2013-04-23T16:14:22.237

1​​​​​​​​​​​​ – wim – 2013-04-24T02:03:59.530

thanks for ur comments. will try to give improved answers in future. – Anbarasan – 2013-04-25T05:36:42.533

2+1 for the print -1**0.5 – Paul Cager – 2013-04-25T11:02:57.713

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. – SteeveDroz – 2013-04-27T06:36:35.253

Wow, I hadn't seen the edit. -1**0.5? I'd have gotten it wrong. – redtuna – 2013-04-29T17:18:22.237

1

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

skeevey

Posted 2013-04-23T07:08:03.090

Reputation: 4 139

3I 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. – plannapus – 2013-04-23T13:31:36.263

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. – SteeveDroz – 2013-04-27T06:33:59.980

1

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%

Erik

Posted 2013-04-23T07:08:03.090

Reputation: 119

3it'll print... something? And then wait for ENTER. – redtuna – 2013-04-23T20:45:42.980

It prints "Hello, world." – David – 2013-04-24T02:22:50.070

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. – SteeveDroz – 2013-04-27T06:32:40.630

This one's kind of silly... I haven't memorized ASCII and so don't expect it to do anything in particular. – Ry- – 2013-04-28T01:51:39.100

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? – Erik – 2013-04-29T17:46:02.703

1

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

Ry-

Posted 2013-04-23T07:08:03.090

Reputation: 5 283

This tells me we should hope for Dart to come along. – Alexander – 2013-04-23T23:45:09.253

Prints nothing but logs into the console: ;-) – SteeveDroz – 2013-04-24T06:05:20.680

3Definitely too hard too make a useful guess – copy – 2013-04-24T13:56:05.193

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. – SteeveDroz – 2013-04-27T06:34:22.153

1

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.

Volatility

Posted 2013-04-23T07:08:03.090

Reputation: 3 206

I would appreciate an explanation on how this answer isn't appropriate. – Volatility – 2013-04-24T10:05:27.880

2Raises a TypeError. [BTW: I don't understand the downvote too. An other answer uses a similar approach but wasn't downvoted...] – Bakuriu – 2013-04-24T11:35:27.650

1Prints 10 random bytes in the file random_bytes.txt – mgibsonbr – 2013-04-24T18:02:27.650

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. – SteeveDroz – 2013-04-27T06:34:40.120

1

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%

Toto

Posted 2013-04-23T07:08:03.090

Reputation: 909

2prints world then prints 7\n, though i don't know perl so i don't know what my does – Griffin – 2013-04-24T14:58:13.103

1Balls, I mean't 5 not 7, oh well – Griffin – 2013-04-24T15:03:36.020

@Griffin: my is just the way to declare variables. – Toto – 2013-04-24T15:43:57.310

Prints "world4" with no newline. – None – 2013-04-25T15:58:50.387

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. – SteeveDroz – 2013-04-27T06:35:00.153

1The score should be (3-0)/4. – flornquake – 2013-04-27T17:48:40.393

1

(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].

Bakuriu

Posted 2013-04-23T07:08:03.090

Reputation: 781

1It prints the contents of text_b – Volatility – 2013-04-24T09:37:42.320

2It prints the contents of text_a. (Implementation dependent.) (I changed the comment, terrible typo...) – Reinstate Monica – 2013-04-24T14:08:39.860

@WolframH I've added a clarification about the implementation. AFAIK all versions of the implementation I've used give the same result. – Bakuriu – 2013-04-24T14:33:23.967

Yes, I believe so. And I answered what I believe happens for that implementation :-) (but could be wrong, of course). – Reinstate Monica – 2013-04-24T15:00:09.590

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. – SteeveDroz – 2013-04-27T06:35:59.440

Side note: The optimization works for the empty tuple (). – Reinstate Monica – 2013-04-27T08:25:12.217

@WolframH I think it works because the empty tuple "does not have the comma", i.e. it is an actual literal. When the bytecode is first generated tuple literals are actually represented as BUILT_TUPLE opcodes, but not the empty tuple(which is like an int or str). When peephole.c optimizes these BUILD_TUPLE opcodes it creates a new tuple constant for every opcode, hence duplicating every non empty tuple(and nothing is done, at the moment, to remove duplicates. It's highly probably an AST optimizer will be added in the future...) – Bakuriu – 2013-04-27T08:41:20.800

@Bakuriu: Tuples are no literals anyway, so I don't understand your comment. – Reinstate Monica – 2013-04-27T09:32:58.840

@WolframH Yes, I probably wrote it in a obscure way, and my assumption was wrong. Anyway, as I said, there is no optimization done by the parser/compiler for the tuples. The empty tuple has always the same id because it is special cased in the tuple initialization and it is a singleton. But the parser doesn't know that, and in fact in __code__.co_consts the empty tuple appears multiple times(but because it is a singleton, they are actually all the same object). – Bakuriu – 2013-04-27T12:00:51.380

@Bakuriu: Ah, yes, that is much clearer. Thanks. – Reinstate Monica – 2013-04-27T14:16:33.030

1

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 %

Reinstate Monica

Posted 2013-04-23T07:08:03.090

Reputation: 929

3Prints 9 8 7 6 5 4 3 2 1 0, each number on one line. – Bakuriu – 2013-04-24T14:37:49.580

Prints 0 nine times. – histocrat – 2013-04-26T01:05:04.733

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. – SteeveDroz – 2013-04-27T06:35:40.327

1

Python

Please give the expected output without executing the below line.


print -1 ** 0.5

Anbarasan

Posted 2013-04-23T07:08:03.090

Reputation: 79

1It prints -1.0 – Volatility – 2013-04-25T09:39:29.290

Throws an exception – ugoren – 2013-04-25T10:57:25.413

no it does not throw an exception in python 2.7 – Anbarasan – 2013-04-25T10:58:23.027

1@Anbarasan -1. Giving explicit explanations of what happens/not happens simply spoils everything. – Bakuriu – 2013-04-25T16:46:44.443

Prints a complex number close to (but probably not equal to) 1j. – Reinstate Monica – 2013-04-26T19:10:21.203

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. – SteeveDroz – 2013-04-27T06:36:51.630

1

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%

Pieter Witvoet

Posted 2013-04-23T07:08:03.090

Reputation: 201

1Prints 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. – Volatility – 2013-04-25T13:24:46.973

You're right, too much obfuscation... I've added a more readable version now. – Pieter Witvoet – 2013-04-25T14:52:02.387

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. – SteeveDroz – 2013-04-27T06:39:39.890

1

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

mob

Posted 2013-04-23T07:08:03.090

Reputation: 2 506

1it'll print 0 but true – Toto – 2013-04-25T18:30:52.590

It will output 0. – f.ardelian – 2013-04-26T22:17:46.183

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. – SteeveDroz – 2013-04-27T06:37:07.707

1

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)

Casey Chu

Posted 2013-04-23T07:08:03.090

Reputation: 1 661

1

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.

ST3

Posted 2013-04-23T07:08:03.090

Reputation: 1 279

Why that strange solution? In math if you want “21+1” to give 4 then you add parenthesis: “2(1+1)”. Same here: #define TWO (ONE+ONE). – manatwork – 2014-01-20T13:31:42.453

@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. – ST3 – 2014-01-20T15:20:56.007

0

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

codefreak

Posted 2013-04-23T07:08:03.090

Reputation: 101

1Prints 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. :) – asteri – 2013-04-24T20:02:54.193

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. – SteeveDroz – 2013-04-27T06:37:58.600

0

VBA

Sub a()
    b = c = 1
    Debug.Print b, c
End Sub

Griffin

Posted 2013-04-23T07:08:03.090

Reputation: 4 349

1Random guess: prints "1 1" – asteri – 2013-04-24T20:03:37.570

3Prints either True or False (or however VBA prints boolean values) depending on whether c equals 1, then the value of c – 3Doubloons – 2013-04-24T23:01:31.667

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. – SteeveDroz – 2013-04-27T06:38:14.633

0

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

Michael0x2a

Posted 2013-04-23T07:08:03.090

Reputation: 111

1Prints [0, 8, 48], unless I got the plutimications wrong :-) – Reinstate Monica – 2013-04-24T18:37:20.787

Prints [0, 13, 208] (I think). – flornquake – 2013-04-24T19:01:38.033

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. – SteeveDroz – 2013-04-27T06:38:30.713

0

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 %

Reinstate Monica

Posted 2013-04-23T07:08:03.090

Reputation: 929

2This prints 0j. (Btw, the parentheses are not required. A space is enough: i ** 0.5 .real) – Bakuriu – 2013-04-24T21:04:12.180

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. – SteeveDroz – 2013-04-27T06:38:46.807

1I 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 :) – Bakuriu – 2013-04-27T08:25:30.647

0

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

Paul Cager

Posted 2013-04-23T07:08:03.090

Reputation: 131

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. – SteeveDroz – 2013-04-27T06:39:02.810

0

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.

f.ardelian

Posted 2013-04-23T07:08:03.090

Reputation: 101

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. – SteeveDroz – 2013-04-27T06:40:31.610

0

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.

f.ardelian

Posted 2013-04-23T07:08:03.090

Reputation: 101

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. – SteeveDroz – 2013-04-27T06:40:01.670

0

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);
    }
}

Petr Pudlák

Posted 2013-04-23T07:08:03.090

Reputation: 4 272

0.4, 0.5 0.2, 0.2 0.7, 0.7 NaN, NaN – mniip – 2013-05-04T10:02:46.933

0

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.");
  }
}

Petr Pudlák

Posted 2013-04-23T07:08:03.090

Reputation: 4 272

doesn't print anything – mniip – 2013-05-11T12:23:25.887

@mniip It does, but what? – Petr Pudlák – 2013-05-11T12:50:41.763

-1

Here it is for C

int main(){
    int a = 10;
    int b = 20;
    int c = a + b;
    printf("Hello World!");
}

Digvijay Yadav

Posted 2013-04-23T07:08:03.090

Reputation: 99

Depends what language it is. – histocrat – 2013-04-26T05:32:56.990

@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. – Digvijay Yadav – 2013-04-26T05:41:10.793

4It prints Hello World!. It also adds two numbers, but does nothing with the result. – ugoren – 2013-04-26T07:50:28.547

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. – SteeveDroz – 2013-04-27T06:41:01.660

-1

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

histocrat

Posted 2013-04-23T07:08:03.090

Reputation: 20 600

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. – SteeveDroz – 2013-04-27T06:41:26.693