Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

You are to write a program that does one of the following.

  1. Only displays "Hello World" does nothing else
  2. Quits and nothing else (no output, no errors.)
  3. Takes one line of input, parses it as an integer, displays the first that many primes (or gives a nice error if it is given input that can't be parsed as an integer, or is less than 0.)
  4. Given one line of input, it parses it has a stock symbol, and checks online for the current stock value and its change.

The catch, it should not be apparent which function it performs. Namely, for someone looking at your code, it should not be apparent which function it will do. Also, it may only perform and be able to perform one function (it can not pick and choose.) How good a program is is determined by how uncertain someone is that looks at it as to what its function is, and also how familiar that person is with that language.

BONUS: If you in a clever way make it so although for any one compiler/intrpreter and platform, the program will also perform the same function, different compilers/interpreters or platforms, it will perform a different function. This bonus may only be collected if done cleverly.

BONUS: If your program only contains code that is capable of one function (save nothing, as empty code is capable of that), and it is not possible to make a simple modification unrelated to the function to allow it to perform a different function. For example: if you did

obfuscatedBool = 1g8uhad'l8fygrcetdu8y4fd/,.oe87fy4d --Magic
if obfuscatedBool: print "Hello World"

Would not count as obfuscatedBool could be made True or False to make it print "Hello World" or do nothing respectively.

INFINITY BONUS: If you realize both bonuses simultaneously, you are magic.

NEGATIVE BONUS: Using libraries with specific abilities to do the functions.

Voters, take the bonuses in to consideration, because the program with the most votes wins!

Note: If you say what your program does, make sure to use spoiler syntax!

share|improve this question
1  
To be honest, I can't understand most of the question. I go further and will say that I only understand the 4 points. –  Ismael Miguel Mar 12 at 22:27
    
Make a program such that it does one of the 4 things, but no one knows what. –  PyRulez Mar 12 at 22:39
21  
And what about the bonuses? Seriously, even the question is obfuscated. –  Ismael Miguel Mar 12 at 22:49
3  
Since this is a popularity-contest, what for is the bonus? –  Ismael Miguel Mar 13 at 2:24
1  
@MukulKumar - as in, mine actually made sense? –  TheDoctor Mar 13 at 12:53

28 Answers 28

Whitespace/Brainfuck/Python

'''begin''''''''''''  
main(args){   	  	   
	parseArgs=args.Find('^++++++++^[<++++[<++<+++<+++<+>>>>a-z]<+<+<A-Z[>]>0-9]<<.<---.*$');
    for(int i=0;	Range(GetLength(parseArgs));	i++){validateArg(parseArgs(i));}  	 	
	//name
    string stockName="";		 		  
	//loop
    for(int i=0;Range(GetLength(parseArgs));i++){		 		  
	//validate
     	if(matchFound=Find('a+z+A+.Z.0+9+_+.<<*$'){	 				
	//found
     	parseArgs(i).Split('>-.>.+');}     
	
     	for(int j=0;Range(GetLength(parseArgs(i)));j++){	 			
	//download
    data=ConvertTo.String(eval("curl -get	http://some-stock-ticker-source-url-here.com"));	 				
	print;
    print data;			  	 
	
    //line separator		 		  
	
    print "--------.";		  	  
	}}
}  


''finish'''''''''''''''

Wikipedia: Whitespace (programming language)
Online Whitespace Interpreter to Test Answer
Online Brainfuck Interpreter to Test Answer

Output (Whitespace/Brainfuck):

Hello World
Ouput (Python):
Nothing, but runs successfully.

share|improve this answer
2  
This is really cool! I think you should update the description. Isnt the obvious code a third program that does something too? Also if you could change one of brainfuck or whitespace to perform one of the other function I would give you the INFINITY bonus! –  SebastianH Mar 13 at 8:59
    
What language is the pretend program in? –  durron597 Mar 13 at 14:11
1  
@durron597 It's a weird C# and Python hybrid. I was going to do it all in C# but it was difficult to make the syntax work all the way through. –  grovesNL Mar 13 at 14:47
    
@SebastianH It's a pretend program to mask its actual function. –  grovesNL Mar 13 at 14:49
    
The Python functionality is too transparent. After you see the first 3 characters, you just have to scan the rest of the code for the end of the string literal. –  user2357112 Mar 13 at 17:05

JS

゚ω゚ノ=/`m´)ノ~┻━┻//*´∇`*/['_'];o=(゚ー゚)=_=3;c=(゚Θ゚)=(゚ー゚)-(゚ー゚);(゚Д゚)=(゚Θ゚)=(o^_^o)/(o^_^o);(゚Д゚)={゚Θ゚:'_',゚ω゚ノ:((゚ω゚ノ==3)+'_')[゚Θ゚],゚ー゚ノ:(゚ω゚ノ+'_')[o^_^o-(゚Θ゚)],゚Д゚ノ:((゚ー゚==3)+'_')[゚ー゚]};(゚Д゚)[゚Θ゚]=((゚ω゚ノ==3)+'_')[c^_^o];(゚Д゚)['c']=((゚Д゚)+'_')[(゚ー゚)+(゚ー゚)-(゚Θ゚)];(゚Д゚)['o']=((゚Д゚)+'_')[゚Θ゚];(゚o゚)=(゚Д゚)['c']+(゚Д゚)['o']+(゚ω゚ノ+'_')[゚Θ゚]+((゚ω゚ノ==3)+'_')[゚ー゚]+((゚Д゚)+'_')[(゚ー゚)+(゚ー゚)]+((゚ー゚==3)+'_')[゚Θ゚]+((゚ー゚==3)+'_')[(゚ー゚)-(゚Θ゚)]+(゚Д゚)['c']+((゚Д゚)+'_')[(゚ー゚)+(゚ー゚)]+(゚Д゚)['o']+((゚ー゚==3)+'_')[゚Θ゚];(゚Д゚)['_']=(o^_^o)[゚o゚][゚o゚];(゚ε゚)=((゚ー゚==3)+'_')[゚Θ゚]+(゚Д゚).゚Д゚ノ+((゚Д゚)+'_')[(゚ー゚)+(゚ー゚)]+((゚ー゚==3)+'_')[o^_^o-゚Θ゚]+((゚ー゚==3)+'_')[゚Θ゚]+(゚ω゚ノ+'_')[゚Θ゚];(゚ー゚)+=(゚Θ゚);(゚Д゚)[゚ε゚]='\\';(゚Д゚).゚Θ゚ノ=(゚Д゚+゚ー゚)[o^_^o-(゚Θ゚)];(o゚ー゚o)=(゚ω゚ノ+'_')[c^_^o];(゚Д゚)[゚o゚]='\"';(゚Д゚)['_']((゚Д゚)['_'](゚ε゚+(゚Д゚)[゚o゚]+(゚Д゚)[゚ε゚]+(゚Θ゚)+(゚ー゚)+(゚Θ゚)+(゚Д゚)[゚ε゚]+(゚Θ゚)+((゚ー゚)+(゚Θ゚))+(゚ー゚)+(゚Д゚)[゚ε゚]+(゚Θ゚)+(゚ー゚)+((゚ー゚)+(゚Θ゚))+(゚Д゚)[゚ε゚]+(゚Θ゚)+((o^_^o)+(o^_^o))+((o^_^o)-(゚Θ゚))+(゚Д゚)[゚ε゚]+(゚Θ゚)+((o^_^o)+(o^_^o))+(゚ー゚)+(゚Д゚)[゚ε゚]+((゚ー゚)+(゚Θ゚))+(c^_^o)+(゚Д゚)[゚ε゚]+(゚ー゚)+((o^_^o)-(゚Θ゚))+(゚Д゚)[゚ε゚]+(゚Θ゚)+(゚Θ゚)+(c^_^o)+(゚Д゚)[゚ε゚]+(゚Θ゚)+(゚ー゚)+((゚ー゚)+(゚Θ゚))+(゚Д゚)[゚ε゚]+(゚Θ゚)+((゚ー゚)+(゚Θ゚))+(゚ー゚)+(゚Д゚)[゚ε゚]+(゚Θ゚)+((゚ー゚)+(゚Θ゚))+(゚ー゚)+(゚Д゚)[゚ε゚]+(゚Θ゚)+((゚ー゚)+(゚Θ゚))+((゚ー゚)+(o^_^o))+(゚Д゚)[゚ε゚]+(゚ー゚)+(c^_^o)+(゚Д゚)[゚ε゚]+(゚Θ゚)+((o^_^o)-(゚Θ゚))+((゚ー゚)+(o^_^o))+(゚Д゚)[゚ε゚]+(゚Θ゚)+((゚ー゚)+(゚Θ゚))+((゚ー゚)+(o^_^o))+(゚Д゚)[゚ε゚]+(゚Θ゚)+((o^_^o)+(o^_^o))+((o^_^o)-(゚Θ゚))+(゚Д゚)[゚ε゚]+(゚Θ゚)+((゚ー゚)+(゚Θ゚))+(゚ー゚)+(゚Д゚)[゚ε゚]+(゚Θ゚)+(゚ー゚)+(゚ー゚)+(゚Д゚)[゚ε゚]+(゚ー゚)+((o^_^o)-(゚Θ゚))+(゚Д゚)[゚ε゚]+((゚ー゚)+(゚Θ゚))+(゚Θ゚)+(゚Д゚)[゚o゚])(゚Θ゚))('_');

Alerts "Hello World"
Was answered at http://codegolf.stackexchange.com/a/3946/803
Since I did not come up with this answer, making it a community wiki

share|improve this answer
23  
Are you entirely sure this is not APL? –  mniip Mar 13 at 12:25
2  
@mniip Oh Yeah!! its is JS. Demo jsfiddle.net/7mqL8 –  Clyde Lobo Mar 13 at 13:42
9  
I see smileys everywhere.. –  tahatmat Mar 13 at 17:47
    
This is the best usage of Unicode in JavaScript I've ever seen! –  Cole Johnson Mar 13 at 23:33
1  
+1 for the smiley: (o^_^o). –  Amal Murali Mar 14 at 11:37

MS-DOS x86 Assembly

Because it isn't already obfuscated when it's in assembly, let's make it even worse! This SHOULD work with any assembler that can assemble to a COM file, but I've only tested with TASM for DOS using tasm obfuse, tlink /t obfuse

.286
CODE SEGMENT
ASSUME CS:code, DS:code
ORG 0100h

start:
.586

xor eax, eax
xor ecx, ecx
xor edx, edx
xor ebx, ebx
xor edi, edi
xor esi, esi
stc
pushfd
rcr di, 8
mov cx, 35
cli
push edi
xor word ptr [di + 8], 2720
pushfd
sub bx, 64512
rcr ebx, 11
sub word ptr [di + 125], 61702
pop eax
dec dx
and word ptr [di + 4], cx
mov ecx, eax
sub byte ptr [di + 124], 21
xor eax, ebx
push eax
xor byte ptr [di + 127], 240
popfd
xor dword ptr [di], 179066414
pushfd
xor byte ptr [di + 11], dl
pop eax
mov bp, 8268
xor byte ptr [di + 123], 110
pop edx
add byte ptr [di + 10], 49
popfd
sti
and ecx, ebx
or word ptr [di + 4], bp
and eax, ebx
xor word ptr [di + 6], 23601
cmp eax, ecx
db 'u', 5
dec cl
movsx dx, cl
int 32

CODE ENDS
END start

This is self-modifying code that does several things:
1) It modifies the first 12 bytes to 'Hello World[dollar sign]'
2) It modifies the seemingly out of place 'dec cl' and 'movsx dx cl' to 'nop', 'mov ah, 9', 'int 021h'
3) Everything is highly interspersed within each other. This is also doing a flags test to see if your CPU supports CPUID
4) Hex values converted to decimal so you have no clue....
5) Even if you did, it uses xor, or, and and sub to modify the existing code to the correct values. No direct values.
6) If your CPU doesn't support CPUID (not a Pentium or above, see DOSBox for a great example), you see "Hello World". Otherwise, nothing happens.

share|improve this answer
24  
Writing a program in Assembler is obfuscation enough! xD –  SebastianH Mar 13 at 8:59

C

int puts(const char *s) {
  char error[] = "Error: invalid number\n";

  int a, b=0, c=0, i, j;
  scanf("%d", &b);

  if (b<1) {
     printf(error);
  }

  for (i=2; c<b; i++) {
     int z=1;
     for (j=2; j<i; j++) {
        z = z&&(i%j);
     }
     if (z) {
        printf("%d\n", i);
        c++;
     }
  }
}

int main () {
  printf("Hello World\n");
}

On gcc, with default settings, this does the prime thing. Using tcc, you get Hello World. A C compiler may rewrite a printf("String\n") call into a puts("String") call. This is more efficient, but it does assume nobody wrote their own puts. A compiler does not have to do this, so depending on your compiler and your compiler settings, you will get either Hello World or a bunch of primes. The printf calls in puts are not affected, because they don't match the exact template. I think I qualify for the bonus.

share|improve this answer

LOLCODE

This language is already obfuscated by itself. Here is my code:

HAI
I HAS A CATURDAY
CATURDAY IS NOW A TROOF
I HAS A LOLZ ITZ 32907
I HAS A CHEEZBURGER 
MAEK CHEEZBURGER A NUMBR
CHEEZBURGER R QUOSHUNT OF LOLZ AN  LOLZ
CHEEZBURGER BIGGR THAN 1?, O RLY?
YA RLY BTW RLY LOLZ
CATURDAY R WIN 
OBTW EVERYDAY IS CATURDAY 
ME LIKEZ CATURDAY!!1!
TLDR
CHEEZBURGER R QUOSHUNT OF LOLZ AN CHEEZBURGER
NO WAI
CATURDAY R FAIL BTW LOLZ!!1!
I HAS A LIMIT ITZ 10
CHEEZBURGER R 0
OIC 
IM IN YR LOOP
CHEEZBURGER, WTF?
OMG 1
VISIBLE "Hello World!" 
OMGWTF
CATURDAY R FAIL
OIC
GTFO
IM OUTTA YR LOOP
KTHXBYE

This code quits and does nothing else (no output, no errors). But although it does absolutely nothing, it runs like a charm (tested with version that contained a VISIBLE "test" statement before the last statement KTHXBYE, proving that all is fine). Basically it declares variables, changes their types, enters in loops and ifs and cases constructs, even has a line that would print "Hello World!" if ever reached (if only reached...). A total waste of computation :)

share|improve this answer
1  
If you'd like, you can test it here –  gilberto.agostinho.f Mar 13 at 23:02

Java,C++-11 1 Bonus claimed

Not sure about if i got both bonuses but it was already a headache to intermingle 2 programming languages...

/* *??/
/
#include <iostream>
using namespace std;

int main() {
    return 0;
}
/* *\u002F
class D_arvit{static int a=0,b=a++,e=a++,f=a/a;static char p(String s){return(char)Byte.parseByte(s,a);}public static void main(String[]z){//\u000Along x=e,y=b;String c=((Long)x).toString(),d=((Long)y).toString();char u=p(c+c+d+c+c+d+d),m=p(c+c+d+d+c+d+c),o=(char)(u+a+f);char _=p(c+d+d+d+d+d),$=_++;System.out.print(new char[]{p(c+d+d+c+d+d+d),m,u,u,o,$,p(c+d+c+d+c+c+c),o,(char)(o+a+f),u,(char)(m-f),_});\u000A}}
/\u002A*/

Getting the C++ inbetween the java code which i already used on another Hello World answer was a Pain in the ass. Took me a while to find a fitting second language where i was able to juggle around comments as needed so they disable/enable differently at different languages

share|improve this answer
    
Using trigraphs to exit a comment in C++. This is neat! –  FUZxxl Jun 19 at 9:50
    
^It's also one of the standard loopholes, I think. Just saying. –  octatoan Sep 5 at 2:04

JavaScript (ES6)

Using pragma black magic to reveal JavaScript true power:

var WKRBD='';
var DIJqZ=(gFJLA=WKRBD,i=29)=>(
  "use black magic", 
  gFJLA=WKRBD.concat(gFJLA),
  [String.fromCharCode((c.charCodeAt()-61)^gFJLA[i++].charCodeAt())for(c of gFJLA.substr(1,11))].join('')
);
DIJqZ(DIJqZ);

Output:

Hello World

Explanations:

This program is actually quite simple and could be summarize as bellow.
Everything else if syntactic sugar!

var dummy = function() {
  var output = '';
  var a = 'gFJLA=WKRBD';
  var b = 'black magic';

  for (var i = 0; i < a.length; i++) {
    output += String.fromCharCode((a[i].charCodeAt(0) - 61) ^ b[i].charCodeAt(0));
  }

  return output;
};

dummy();

Here is the annotated version:

// Nothing special here.
var WKRBD='';

// Define a new function. Its name doesn't matter.
// But its arguments do!
//   * gFJLA=WKRBD: encoded "Hello World"
//   * i=29: number of characters before "black magic"
var DIJqZ=(gFJLA=WKRBD,i=29)=>(
  // Store the XOR key using a fancy pragma name!
  "use black magic", 
  // Convert gFJLA to String thus it is possible to read 
  // its body and extract the encoded "Hello World".
  gFJLA=WKRBD.concat(gFJLA),
  // Use a generator to decode the message.
  [
    // Generate the decoded character
    String.fromCharCode(
      // Decode the character.
      // gFJLA[i++] retrieves a character from "black magic".
      (c.charCodeAt() - 61) ^ gFJLA[i++].charCodeAt()
    )
    // Iterates over the function body.
    // The extracted part is "gFJLA=WKRBD".
    for(c of gFJLA.substr(1,11))
  // Build the message. Since it is the last expression of 
  // the arrow function, its result is returned.
  ].join('')
);

// Invoke the function and pass itself as the first argument.
DIJqZ(DIJqZ);
share|improve this answer
    
any exxplain? for the pragma? –  masterX244 Mar 13 at 15:15
    
+1 for that trololol; got clear after explain –  masterX244 Mar 14 at 9:54

COBOL (IBM Enterprise COBOL)

   ID

If shown that, very close to 100% of IBM Mainframe COBOL programmers would say "that's not even a program, that won't compile!". The more experience they have, the less likely they are to think it will compile (as older Mainframe COBOLs were much more strict).

Then ask "if it does compile, what does it do?" They would say, "it won't compile, but if it did, it would give some sort of error, probably Language Environment would give a U4038 or something like that".

Managed to shorten it. There are four DIVISIONs in a COBOL program. IDENTIFICATION/ID, ENVIRONMENT, DATA, PROCEDURE. It turns out that PROCEDURE requires the word DIVISION and the others don't. Guess which one I removed first and assumed that the other words DIVISION were mandatory... further puzzling revealed otherwise. Pity it's not Golf. A two-character COBOL program...

OK, yes, the compiler does moan, and indeed gives it a Return Code of eight. Usually people don't even generate the object code for, let alone try to execute, programs with a Return Code of eight. However, this is a case where none of the E-level errors affect the code generated. So the code runs without a problem at all, if you generate it.
The above source is effectively the equivalent of this:
ID DIVISION.
PROCEDURE DIVISION.
GOBACK
.
Which simply returns to whence it came.

share|improve this answer
2  
My first ever spoiler. There's code in there. All pickled. Rats. More research... –  Bill Woodger Mar 13 at 1:44
    
Slightly less pickled, but still not good. Late here. I'll see if there are more spoilers I can steal from tomorrow. Err... later today. ID and PROCEDURE start in column eight, GOBACK and full-stop/period in column 12. The ID in the original is also column eight, just for info. –  Bill Woodger Mar 13 at 1:53

Python - 1 Bonus Claimed

import base64
try:
    a=1/(1/2)
    eval(compile(base64.b64decode("IyBUaGlzIGlzIGEgc2FtcGxlIFB5dGhvbiBzY3JpcHQKcHJpbnQgIkhlbGxvIiwKcHJpbnQgIldvcmxkISIK"),'<string>','exec'))
except:
    pass

In Python 2, 1 divided by 2 equals 0. 1 divided by 0 can't be evaluated and throws a division by zero error. Nothing is printed, and still the program terminates without error.

In Python 3, 1/2 => 0.5, and 1/0.5 => 2.0. No error. Hello, World! is printed.

share|improve this answer
3  
I don't know that this is obfuscated enough. –  Hosch250 Mar 12 at 22:36
    
@hosch250 Is right, it is not very obfuscated. Is second part is wrong though. –  PyRulez Mar 12 at 22:40
    
Oh, I see. It does one in Python 2 and the other in Python 3. –  Hosch250 Mar 12 at 22:41
    
@hosch250 Oh well. At least I got the bonus. I won't really mind if someone else steals the bonus part of my answer and molds it. I'd be honored, even. –  Rainbolt Mar 12 at 22:43
    
Just obfuscate hello world in some way and you will be fine. –  Hosch250 Mar 12 at 22:51

Ruby - or is it Whitespace?

Well, can anyone guess what I do? Small hint: if you want to run it, please copy all of the code in the code box ;)

Update: Copying the code doesn't seem to work due to Unicode-related problems? Forking the online version and then copying the code seems to work! Look out for the whitespace ;)

Online version

# encoding: utf-8

def method_missing(m, *a)
  $* << (m.to_s.size-1).to_s
end

at_exit do
  eval ($**'').scan(/.../).map(&:to_i).pack('C*')
end

                                                                                                                                                                                                                                                   

Output:

Hello world!

Explanation:

  • The last line consists of quite a few chunks of no-break-spaces (UTF-8: 160dec) separated by regular spaces.
  • Ruby handles the chunks as though they were methods - since no such methods are defined, method_missing is called, which saves the lengths of the chunks
  • Each chunk represents one digit of a three digit number, which represents a character
  • in at_exit the characters are formed by concatenating the digits etc. and the expression is evaluated, in this case puts 'Hello world!'
  • Instead of using UTF-8 whitespaces, you could also use underscores for better visibility:
def method_missing(m, *a)
  $* << (m.to_s.size-1).to_s
end

at_exit do
  eval ($**'').scan(/.../).map(&:to_i).pack('C*')
end

__________ ____ _ ____ ____ _ _ _ __ _________ _ __ _____ __ __ __ __ __ __________ __ __ ___ ____ _ __ __ __ _________ _ __ _________ _ __ __ _ __ ___ ________ _ __________ ____ _ ___ ____ _ ______ __ __ _______ __ __ ________ __ __ ___ __ __
share|improve this answer
    
Copying Whitespace from SE doesn't work because SE's markdown interpreter replaces tab characters with 4 spaces. –  undergroundmonorail Mar 15 at 12:24

Forth

Let's create a new TASK.

FORTH ok
: TASK
  [ HEX ] 3A91224B. 1F836AFE.  
  4A BASE ! D. D.     
;
TASK Hello World ok

It displays two 32-bits numbers in base 74 (4Ah). 74 because it is the difference between ASCII "z" and ASCII "0" plus one, so I can use it to display a small words starting from a number. The first number is "Hello" (1F836AFEh) and the second number is "World" (3A91224Bh). It really prints a trailing space after the number "World".

Real execution

share|improve this answer
    
Forth...one of the few languages SHOUTIER than SQL. Welcome to the site! –  Jonathan Van Matre Mar 13 at 14:16
3  
I tried it on my Sinclair-ZX-Spectrum Forth and it works... –  Mattsteel Mar 13 at 14:29
1  
... and realize that using a different base (4F) will be compliant with another puzzle –  Mattsteel Mar 13 at 22:51

Batch

@echo off&setLocal enableDelayedExpansion&for /L %%a in (2,1,%1)do (set/aa=%%a-1&set c=&for /L %%b in (2,1,!a!)do (set/ab=%%a%%%%b&if !b!==0 set c=1)
if !c! NEQ 1 set l=!l!%%a,)
echo !l:~0,-1!

This will return a list of prime numbers less than the inputted value.
H:\uprof>obf.bat 12
2,3,5,7,11

I don't know that convoluted counts as obfuscated, though there are definitely some aspects of obfuscation present.

share|improve this answer
    
The program may only preform one function. –  PyRulez Mar 12 at 23:30
    
@PyRulez Sorry, fixed. –  unclemeat Mar 13 at 0:02
2  
I also recommend using spoilers so people don't what it does immediately. –  PyRulez Mar 13 at 0:10
    
+1 for %%%% xD –  SebastianH Mar 13 at 8:53

PHP:

$words=array('Heart','eagle','low','lonely','over',' SPACE ','Window','optimus','rotting','list','done','!done');

$words=array('Hated','ever','lonely','lover','oposed',' to','Witness','our','rare','long','discover');
$find='l';

foreach($words as $word)echo($find^(($find&$word)^($find|$word)));

Prints 'Hello World'.
It takes off the 1st letter from each word in the array.
The var $find can have any single-byte string of 1 byte.
Using a longer value for the var $find will give weird outputs.

share|improve this answer
5  
Without looking at the spoiler, I could see that this string has to be connected with "Hello World"! –  SebastianH Mar 13 at 8:54
    
Sorry if my obfuscated try isn't the best. And yes, the pattern is too easy, but at least I tried something different. I will edit it later and make it a little less obvious. –  Ismael Miguel Mar 13 at 9:24
    
+1 for bitwise :) –  CSᵠ May 3 at 10:03

Delphi

Not sure if this counts but I will tell you how I saw this challenge.
My thought was to write code that wouldnt execute what you expected it to.

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.sysutils,Generics.Collections;
type
  TMyIntList= TList<integer>;

  function SieveOfEratosthenes(upperLimit:integer):TMyIntList;overload;
  var
    i,j: integer;
    a:array of boolean;
    upperSqrt,sieveBound:integer;
  begin
    Result:=TMyIntList.Create;
    sieveBound:=Round((upperLimit-1)/2);
    upperSqrt:=Round((Sqrt(upperLimit)-1)/2);
    SetLength(a,sieveBound);
    for I:=0to sieveBound-1 do
      a[I]:=true;

    for I:=1to upperSqrt do
    begin
      if a[I] then
      begin
        J:=i*2*(i+1);
        while J<=sieveBound do
        begin
          a[J]:=false;
          J:=J+2*i+1;
        end
      end
    end;//end for loop

    Result.Add(2);

    for I:=1to sieveBound-1do
      if a[i]then
        Result.Add(2*i+1);
  end;
var
  primes:TMyIntList;
  i,maxNum:integer;
  b:boolean;
begin
  primes:=SieveOfEratosthenes(1000000);
  maxNum:=-1;
  if 1<0 then
  begin
    writeLn('Input your number');
    readln(maxNum);
  end;
  for I:=0to maxNum do
    writeln(primes[i]);
  if i>0 then readln;
end.

What I did was write a program that implies to execute function 3 but actually runs function 2 and simply exits as soon as its started.
The hints are: SieveOfEratosthenes Algorithm for generating primes
Var primes and maxNum
code: WriteLn('Input your number');readln(maxNum);
Which is code that will never be reached since booleans are False by default

share|improve this answer

Haskell

import Control.Concurrent
import System.Exit
import System.Time
import Control.Monad

hw = putStrLn "Hello World" 

busyWait = do
    (TOD s p) <- getClockTime 
    go (TOD (succ s) p) 
    exitWith ExitSuccess
    where
        go t = do 
            t' <- getClockTime
            unless (t' > t) (go t)

main :: IO ()
main = forkIO hw >> busyWait

Run with GHC and it will print hello World. With Hugs (which implements cooperative multitasking) It will always quit without printing anything.

share|improve this answer

JS

[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+([][[]]+[])[+[]]+([][[]]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(+(!+[]+!+[]+[+!+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+!+[]+[+!+[]])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]])()([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(+(!+[]+!+[]+[+!+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+!+[]+[+!+[]])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]])()(([]+[])[([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()[+[]])[+[]]+[!+[]+!+[]+!+[]]+(+(+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+[+[]])))()

Does nothing. No Error. No Output

share|improve this answer

Matlab

Here is code that can roughly perform various operations, can you predict the flow?

six=input('input your number or ticker?','s')
six=six(six==6) 

if six
    'Hello World!'
elseif ~six
    try
    primes(str2num(six))
    catch
        urlread(['http://finance.yahoo.com/q?s=' six])
    end        
end

Here is a hint:

Regardless of which number or ticker you input, you will always end up on the same spot

share|improve this answer
1  
Bravo for making it hard to eliminate any of the 4 functions. –  PyRulez Mar 14 at 16:46

C++11

I claim the bonus for compiler dependence - for example, this will exhibit different beahviour between gcc 4.8 and gcc 4.9.

#include <iostream>
#include <list>
#include <type_traits>
#include <utility>


// Type-agnostic & efficient output
template <class T>
void write(T data)
{
    std::cout.write((char*)&data, sizeof data);
}


// Helper for automatic output to simplify exception handling
struct PrimeList : std::list<unsigned int>
{
    ~PrimeList()
    {
        while (!empty())
        {
            write(front());
            pop_front();
        }
    }
};


// Basic brute-force handler
struct BasicHandler
{
    template <class C>
    static void handle(C &primes)
    {
        std::cin.clear(std::ios_base::failbit); // remove possible non-fatal errors
        std::cin.exceptions(std::ios_base::failbit); // easier error handling
        unsigned int count;  // unsigned so that negatives error out immediately
        std::cin >> count;
        unsigned long long candidate = 1;
        for (unsigned int p = 0; p < count; ++p)
        {
            bool isPrime;
            do {
                ++candidate;
                isPrime = true;
                for (auto prime : primes)
                {
                    if (candidate % prime == 0)
                    {
                        isPrime = false;
                        break;
                    }
                }
            } while (!isPrime);
            primes.push_back(candidate);
        }
    }
};


// Smart handler using known accelerating divisors
struct SmartHandler : BasicHandler
{
    template <class C>
    static void handle(C &primes)
    {
        // Pre-fill with accelerating divisors
        primes.push_back(1819043144u);
        primes.push_back(1867980911u);
        primes.push_back(560229490u);

        BasicHandler::handle(primes);

        // Remove divisors, as they are not primes
        primes.pop_front();
        primes.pop_front();
        primes.pop_front();
    }
};


// Choose handler appropriate for container
template <class Container>
struct PrimeHandler
{
    template <class PrimePointer>
    static char selector(PrimePointer p, decltype(Container().insert(p, *p)));

    static double selector(...);

    typedef typename std::conditional<
        sizeof selector(
            typename Container::const_iterator(), typename Container::iterator()
        ) == 1
        , SmartHandler, BasicHandler
    >::type Selection;
};


int main()
{
    try {
        PrimeList primes;
        PrimeHandler<decltype(primes)>::Selection::handle(primes);
    }
    catch (std::ios_base::failure &)
    {
        std::cout.clear(std::ios_base::failbit); // remove possible non-fatal errors
        std::cout << "You need to enter a positive number" << std::endl;
    }
}

Compiler dependency explanation:

C++11 changed the requirements for insert() and erase() functions in standard containers so that they now accept constant iterators, where previously they required mutable iterators. That's what PrimeHandler tests. gcc only changed its standard library to be compliant in 4.9; MSVC 2013 is not compliant yet; I don't know about clang.

General behaviour explanation:

The clear(x) function of streams does not clear flag x, it sets it. Therefore, the handle() function actually puts the stream in error state, so any attempt to read fails (and helpfully throws an exception). In the same way, the error output is avoided.
The auto-output destructor of PrimeList makes sure any data in it is written - as binary, not as numbers. Of course, the "smart divisors" are actually "Hello World!" encoded in little-endian ASCII. And because an exception is thrown, nothing gets added in BasicHandler, and only the "smart divisors" are added in SmartHandler (and never removed, because of said exception).

share|improve this answer

Brainfuck

print("Hello World")

Explanation

At least if your compiler ignores invalid instructions, this program does nothing.

share|improve this answer
    
The compiler must ignore non-commands, since they count as comments. –  MadTux Jun 10 at 10:03
    
I know of some compilers that error on them, though I can't name any. –  nyuszika7h Jun 10 at 20:22
    
Reminds me of this other challenge –  Qeole Jun 11 at 0:30

C, 346 chars

#include <stdio.h>

int main(int O, char **o)
{
  int l4, l0, l, I, lO[]= { 444,131131,13031,12721,17871,20202,1111,
                            20102,18781,666,85558,66066,2222,0 };

  for(l4=0;l4<14;++l4){
    for((l=l0=lO[l4])&&(l0=-7);
         l>4&&(I=2-((l|l>>O)&O));l=l&O?l+(l<<O)+O:l>>I,l0+=I);{
      putchar(10+l0);
    }
  }

  return 0;
}

This is an old program I created 10+ years ago. It actually prints "Hello, world!" The code uses palindromic numbers in base 10 and is slightly obfuscated.

Don't trust the indentation. Also, see: http://oeis.org/A006577

Oh, I almost forgot... The program only works when started without command line arguments. Also, if you start it with 11 command line arguments it seems to enter an infinite loop. 12 is fine though.

share|improve this answer

Malbolge

I'd say that it can't get anymore obfuscated than Malbolge ;)

(=<`:9876Z4321UT.-Q+*)M'&%$H"!~}|Bzy?=|{z]KwZY44Eq0/{mlk**
hKs_dG5[m_BA{?-Y;;Vb'rR5431M}/.zHGwEDCBA@98\6543W10/.R,+O< 

It just prints "Hello, world." All credits go to Wikipedia since I am still not getting this language...

share|improve this answer
2  
no one is supposed to understand this language.. –  Sp0T Mar 14 at 9:14
4  
Some say that when Malbolge is finally understood, the earth will crack open and we will all be enslaved to work a giant assembly line replacing its core with a chewy nougat center. p.s. We ask that users tag their answers as community wiki, and link to the source, when the work is not their own. Thanks!! –  Jonathan Van Matre Mar 14 at 14:38
    
I could almost deal with the ternary and multiple recodings, but every damned operation trashes some memory! A horrible blighted smut of a language. –  luser droog Apr 9 at 4:49

bash/sh, python

set -e
exec 2>/dev/null

main() {
  eval $(eval base64 -d<<<"cHl0aG9uIC1jICIkQCI=")
}

while read -r foo; do
  main "$foo"
done < <(echo "exec'import __\x68e\x6c\x6co__'")

This would produce:

Hello world...

when executed with bash.

When the same code is executed with sh or with bash in posix mode, i.e. by saying bash --posix filename, it doesn't produce any output.

Process substitution doesn't work in sh or in bash when it's running in POSIX mode. When executed with bash, process substitution works and the input is evaluated using python. Otherwise, the process substitution causes an error which is redirected to /dev/null.

share|improve this answer
    
Wondering if just hiding it counts as "no output, no errors"? –  Bill Woodger Mar 13 at 16:24
    
@BillWoodger If it's illegal, then there are other solutions (try/catch etc.) that are, in my opinion, pretty similar. –  devnull Mar 13 at 16:27
    
Fair point. I guess yours is just a bit more obvious, because the output from anything could be hidden that way, but since you're using the thing which actually includes that processing as part of itself, I'm happy :-) –  Bill Woodger Mar 13 at 16:35

Now, according to the comments and by reading it, this will do 1 of 3 things.

  • It will do the primes objective if you pass it a number.
  • It will lookup stocks if you pass it a non-number.
  • It will print "Hello World" if you do something silly

However, this program does not follow its documentation very well, because no matter what you give it... it will always print the FOURTH objective, which is nothing.

/**
 * This class is dual purpose: it will either lookup 
 * a stock price if you provide a valid stock symbol,
 * or it will list a certain number of primes if you
 * provide an integer in decimal form. Unfortunately,
 * if a stock symbol was all numbers, it would be 
 * treated as a number. Sorry for the inconvenience.
 *
 * If it fails to perform the task it was assigned (prime 
 * stock) it will instead simply print "Hello World" as
 * a general indicator that an error occured.
 *
 * Usage: java StocksOrPrimes 5
 *        2 3 5 7 11
 * Usage: java StocksOrPrimes MSFT
 *        37.70 
 */
import java.util.*;
import java.io.*;
import java.net.*;
class StocksOrPrimes {

    public static void main(String...args) { try {
        if(args.length != 1) {
            System.out.println("Please only enter one argument.");
            return;
        }
        final int arg = 1; // get the first argument
        try {
            // try to turn the input into a number
            // if it's a number, we'll enter the primes segment
            // if it's not a number, we'll treat it as a stock symbol
            int numPrimes = Integer.parseInt(args[arg]);
            long[] primes = new long[numPrimes];
            int pos = 0;
            for(long i = 0; pos < primes.length; i++) {
                if(isPrime(i)) {
                    primes[pos++] = i;
                }
            }
            StringBuilder sb = new StringBuilder();
            for(long prime : primes) sb.append(prime).append(" ");
            System.out.println(sb);
        } catch(Exception e) {
            // clearly we're dealing with a stock symbol, so print 
            // the stock's price
            Scanner sc = new Scanner(new URL("http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=" + args[arg]).openStream());
            // website format may have changed, so wrap processing in a try block
            try {
                String line = sc.nextLine();
                line = sc.nextLine();
                int start = line.indexOf("&lt;Last&gt;") + "&lt;Last&gt;".length();
                int end = line.indexOf("&lt;/Last&gt;");
                String last = line.substring(start,end);
                if(last.equals("0.00")) throw new IllegalStateException("invalid return code");
                System.out.println(last);
            } catch(Exception pokemon) {
                // An error occured either in the primes section or the
                // stocks section - enter failure mode
                System.out.println("Hello World");
            }

        }


    } catch(Exception ex) {} }

    static boolean isPrime(long n) {
        if(n < 2) return false;
        if(n == 2 || n == 3) return true;
        if(n%2 == 0 || n%3 == 0) return false;
        long sqrtN = (long)Math.sqrt(n)+1;
        for(long i = 6L; i <= sqrtN; i += 6) {
            if(n%(i-1) == 0 || n%(i+1) == 0) return false;
        }
        return true;
    }

}

This program works (or rather fails) because Java has 0 indexed arrays. So it should be trying to access args[0]. However, the final int arg = 1 value says we're accessing the first value. Java developers know that args[1] is actually the second value. Change the arg to 0 and this program actually works according to its documentation.

share|improve this answer

This one does both bonuses. Have a look at the spoilers in the end to see what it does.

Java / Brainf*ck

//[
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
//]

public class Something {
    private static String magicNumber="1000";

    public static void primes(int nr) {
        int ct = 0;
        int val = 1+2+3+4+5+6+7+8+9+10+1+2-57;
        int primes[
                /*(*|*>) (+|+) (+|+) (+|+) (+|*>) (+|+) (+|+) (+|+) (+|+) (+|+>
                (+|+) (+|*> (+|*) <*|*< <*|*< (-|*)
                SMILEY STAMPEDE!
                */
                ]; //I probably won't use that array anyways... Whatever.
        while (nr > ct) {
            val++;
            boolean isPrime = true;
            for (int i = 2; System.out!=null && val > i; i+=1) {
                if (val % i == Integer.parseInt("0")) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                println(val);
                ct++;//>*|*> (*|*>
            }
        }
    }

    public static void main(String[] args) throws IOException {//<*|*< <*|*) I like smileys!
        new Something();

        setMagicNumber(1+(getMagicNumber()+7+9+12+4));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        try {
            setMagicNumber(getMagicNumber()+3+1+2);
            System.gc();
            setMagicNumber(getMagicNumber()>5 ?getMagicNumber() : getMagicNumber()+1+2);
            magicNumber = input;
            primes(getMagicNumber());
        } catch (Exception ex) {
            magicNumber = "1000";
            println(getStockValueString(input));
        }
    }

    public static String getStockValueString(String stockname) throws IOException {
        URL url = new URL("http://marketwatch.com/investing/stock/"+stockname);
        setMagicNumber(getMagicNumber2()<7 ? (getMagicNumber2()<9+3) ? 5+3+5+7+6+3 : 2+9+6+9 : 7+6+1+2+5+2+4);
        HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();

        boolean setOutput = getMagicNumber2()>2;

        httpConnection.setDoOutput(setOutput);

        setMagicNumber(getMagicNumber2()+2+3+4);

        DataOutputStream wr = new DataOutputStream(httpConnection.getOutputStream());

        setMagicNumber(getMagicNumber2()-1-2-3-4-5-6);

        wr.flush();

        setMagicNumber(getMagicNumber2()-5-3-1-8-9-5-5-4);

        BufferedReader in = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
        String line;

        while ((line = readLine(in)) == null == (getMagicNumber2()>100000)) {
            line = line.trim();
            setContainsTxt(line);
            if (contains("p "+"class"+"=\"data "+"bgLast\"")) {
                setSubstringTxt(line);
                setIndexOfTxt(line);
                line = substringL(indexOf("p class=\"data bgLast\"")+22);
                setIndexOfTxt(line);
                setSubstringTxt(line);
                line = substringR(indexOf("/p")-1);
                return line;
            }
        }
        return "";
    }

    //>*|*> [*|*>
    public Something() {

    }
    public static int getMagicNumber2() {
        try {
            return Integer.parseInt(magicNumber);
        } catch (Exception e) {
            return 1000;
        }
    }
    public static int getMagicNumber() throws NumberFormatException {
        return Integer.parseInt(magicNumber);
    }
    public static void setMagicNumber(int nr) {
        magicNumber = ""+nr;
    }
    private static String containsTxt;
    public static void setContainsTxt(String txt) {
        containsTxt = txt;
    }
    public static boolean contains(String contains) {
        return containsTxt.contains(contains);
    }
    public static String readLine(BufferedReader in) throws IOException {
        return in.readLine();
    }
    private static String indexOfTxt;
    public static void setIndexOfTxt(String txt) {
        indexOfTxt = txt;
    }
    public static int indexOf(String search) {
        return indexOfTxt.indexOf(search);
    }
    public static void println(Object txt) {
        System.out.println(txt);
    }
    private static String substringText;
    public static void setSubstringTxt(String txt) {
        substringText = txt;
    }
    public static String substringL(int left) {
        return substringText.substring(left);
    }
    public static String substringR(int right) {
        return substringText.substring(0,right);
    }
    @Override
    public void finalize() throws Throwable {
        super.finalize();
        magicNumber = "NaN";
    }//<*|*]
}

Brainfuck

In Brainfuck this just returns "Hello World".

Java

In Java this either returns the first x prime numbers (depending on the input number) or the stock value of the given stock market symbol (e.g. GOOG for Google). Which one is chosen depends on the implementation of the currently used JavaVM, but with the Oracle JavaVM it should get the stock market value. You can also force the prime number calculator (2nd bonus) by commenting out the System.gc()-line, which in turn stops the finalize() call so the magicNumber never becomes NaN and thus no exception is thrown that would cause the stock market value getter to run instead of the prime numbers generator.

share|improve this answer

Javascript

I don't even understand this

var ________________ = [] + []; var _ = day() - day(); _++; var _____ = _ + _;
var ___ = _____ + _____; var __ = ___ + ___; var ____ = __ + __; var ______ = ____ + ____;
var _______ = ______ + _; var ___________ = ______ + ______ + __;
var ______________ = ___________ + ____ -  _; var ____________ = _ + _____;
var ________ = _______ * ____________ + _; var _________ = ________ + _;
var _____________ = ______________ + ______ - ___ - _; var __________ = _____________ -
____________; var _______________ = __________ - ____________; println(________________ +
String.fromCharCode(___________, _________, _______________, _______________, __________,
______, ______________, __________, _____________, _______________, ________, _______));

Note the script is not mine: original source

share|improve this answer
    
How about making in Community-Wiki then? –  Bill Woodger Mar 13 at 20:41
2  
It's kinda understandable. [] + [] -> '', day() - day() -> 0. From there, it just looks like getting the decimal representation of each char, then doing a String.fromCharCode on them. –  Ralph Wiggum Mar 13 at 22:44

Perl

This is my first attempt to write obfuscated code. I hope you'll like it.

#!/usr/bin/env perl

{$i=$s=-!$v>>~!!$a<<!$l,$e=<>,!$e||$e<=$!?last:$!;{$_.=!(!$!+$#{[grep{$i==$_||!($i%$_)}$s..$i/$s]})&&$e--?"$i+!":'',$i++,$e>$!?redo:y.+!.,\x20.,s.,\s$.\n.,print}exit}
$_="Hello World\n",s#\w(.)(.){5}(.)(.)\w*#$1$4$4$3$4#,print and die

This program asks for a number and then prints that many primes. In case of error it will simply print error.

share|improve this answer

Ruby 2.0.0 + 1 Bonus

Okay, so I'll explain the bonus in the spoiler. But this is pretty much just a roundabout way to print "Hello World!" in Ruby.

require "base64"
eval(Base64.decode64(DATA.read))
_________ = $$/$$
_ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ #H
__ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ #e
___ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ #l
____ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ #o
_____ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ # 
______ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ #W
_______ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ #r
________ = _________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________+_________ #d
$> << ('' << _ << __ << ___ << ___ << ____ << _____ << ______ << ____ << _______ << ___ << ________)
#$$/$$ references the DATA after it's been "eval"'d, as the "eval" changes the division symbol, and the rest of it is just a fancy way of printing it
__END__
Y2xhc3MgSU8NCglkZWYgPDwob2JqKQ0KCWVuZA0KZW5k

And the output:

What?

Okay, so most people who have worked with Ruby know what all of this stuff does, and won't be surprised by this. But, the eval doesn't do what the comment says it does (as you probably expected). Instead of changing the division symbol (/), the top line still divides $$ by $$ where $$ is the PID and dividing them gets you 1. Instead, the eval changes how the shovel symbol (<<) works. After it is eval'd, the shovel symbol does absolutely nothing. You can see how I did this by Base64 decoding the stuff after the __END__

And the bonus:

Comment out the second line, it prints "Hello World!". Maybe this doesn't count, because it still prints one space.

share|improve this answer

C

#include <stdio.h>
int main(void) {
    int numbers[] = {1, 2, 3, 4};
    printf("%d\n", numbers[42]);
}

This can do anything, and you won't know what will happen. In theory, undefined behavior in C is allowed to do anything, including the behaviors you mentioned. Obviously, it doesn't happen in most compilers, but perhaps somebody could fine one where this happens.

share|improve this answer
1  
I think this only counts if you actually find compilers who show the behaviors in the question. –  Paŭlo Ebermann Mar 14 at 17:01
    
o.O Didn't you read the compilers 'thingy'? –  Anonymous Pi Mar 16 at 2:40

Your Answer

 
discard

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

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