title: Convert header levels to numbers

text:
# Question
Title: Convert header levels to numbers
### Introduction

Nodes in tree structures (e.g. headings in a long document, law paragraphs, etc.) are often created by assigning a specific header level (h1, h2, etc.) to each item, but outputted with additional node numbers for each level (1., 1.1., etc.), e.g.:

```
1. Intro (h1)
1.1. About this (h2)
1.2. Target audience (h2)
2. Actual stuff (h1)
3. More stuff (h1)
3.1. Details (h2)
3.1.1. Special points (h3)
3.2. Specifics (h2)
3.2.1. Minutiae (h3)
3.2.2. Petitesses (h3)
3.3. Specifications (h2)
4. Index (h1)
5. Appendices (h1)

```

### Input

Given (by any means) a list of header levels (the X's in hX above) like:

```
[1,2,2,1,1,2,3,2,3,3,2,1,1]

```

Input will always begin with a 1, and Input*n*+1 is in the range \[1,1+Input*n*\].

Input will only contain numbers in the range \[1,256\].

### Output

Return (by any means) the list of lists (or matrix - see below) of node numbers (dot-separated above):

```
[[1],[1,1],[1,2],[2],[3],[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],[4],[5]]

```

You may return scalars instead of one-element sub-lists:

```
[1,[1,1],[1,2],2,3,[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],4,5]

```

You may return a matrix (or list of lists) which is padded with zeros so that all rows (sub-lists) have the same length:

```
[[1,0,0]
 [1,1,0]
 [1,2,0]
 [2,0,0]
 [3,0,0]
 [3,1,0]
 [3,1,1]
 [3,2,0]
 [3,2,1]
 [3,2,2]
 [3,3,0]
 [4,0,0]
 [5,0,0]]

```

### Additional rules

The reverse process of all this is just the length of each sub-list. You must also include a reverse program in the same language. Your score is the total byte count of your two programs. If you return zero-padded results on the first prgram, your reverse code must handle such input.

Please explain your code so we all can learn from it.

This is code golf, because I'll need to read it on a phone screen and type it into a computer. - No, really, this is not meme-ness!

# Answer
> 4 votes
## CJam (15 + 4 = 19 bytes)

```
Mq~{1$0+<))+}%`

```

Online demo

To reverse,

```
q~:,

```

# Answer
> 3 votes
## JavaScript (ES6), 47 + 21 = 68 bytes

```
a=>a.map(l=>b=[...b.slice(0,--l),-~b[l]],b=[])

```

Explanation:

```
a=>a.map(l=>            Loop over each header level
 b=[                    Make a new sublist using
  ...b.slice(0,--l),    First l-1 elements from the previous sublist
  -~b[l]],              Plus increment the lth element or default to 1
 b=[])                  Start with an empty sublist

```

The bitwise not operator is used because it will coerce its operand to a signed 32-bit integer, which will be zero if this is a new level. Negating the result conveniently returns one more than the original number, or 1 in the case of a new level. Reverse process:

```
a=>a.map(b=>b.length)

```

# Answer
> 3 votes
# Jelly, ~~10~~ 8 bytes

### Forward, ~~8~~ 6 bytes

```
ḣ+Ṭ}ð\

```

Try it online!

### Backward, 2 bytes

```
L€

```

Try it online!

## How it works

### Forward

```
ḣ+Ṭ}ð\  Main link. Argument: A (list of integers)

    ð\  Cumulatively reduce A by the dyadic chain to the left. Arguments: x, y
ḣ       Head; Truncate x to y items.
  Ṭ}    Untruth; yield a list of y-1 zeroes and 1 one.
 +      Compute the vectorized sum of both results.

```

### Backward

```
L€      Main link. Argument: A (nested list)

L       Length.
 €      Map the previous link over all items in A.

```

# Answer
> 2 votes
# Pyth, ~~27~~ 22 + 2 = 24 bytes

This is embarrassingly ~~more than~~ 1 less than half of the bytes that javascript used.

```
JylQjRJ.uhs*N^JY-VtQQ1

```

Try it online!

### Reverse, 2 bytes

```
lM

```

Try it online!

# Answer
> 2 votes
# Pyth, 11 + 2 = 13 bytes

Forward:

```
m=X_1<+Y0d1

```

Demonstration

Backward:

```
lM

```

I like this one.

How it works:

```
m=X_1<+Y0d1
               Implicit: Y = []
m              Map over the input, with d being the map variable
      +Y0      Add a 0 on to the end of Y
     <   d     Slice down to the first d elements
  X_1     1    Increment the last one
 =             Assign the result back to Y

```

The resultant list will contain each value that Y takes on, which is the desired sequence.

Embarrassment cured.

# Answer
> 1 votes
# Ruby, 44 + 17 = 61 bytes

Forward:

```
->x{l=[]
x.map{|e|l=l[0,e-=1]<<(l[e]||0)+1}}

```

Backward:

```
->x{x.map &:size}

```

---
Tags: code-golf, number, sequence, generation
---


title: Make the longest cat program

text:
# Question
Title: Make the longest cat program
There's been challenges for the shortest cat program, but as far as I know, there hasn't been any for the *longest* one.

A cat program is a program that copies its input to its output. Here's an example:

```
Input: Hello
Output: Hello

Input: cat
Output: cat

```

So, the rules are simple:

* The program has to copy its input to its output
* No loopholes allowed.
* **This is code-bowling, so the longest code wins.**

Also, I'm quite new here, so if you don't like this challenge, then please do tell me why so I'll be able to make better ones later!

# Answer
> 2 votes
# Brachylog, theoretically infinite

```
.............................................................................................

```

You can add as many periods as you like.

The first period will unify the output with the input. The second period will unify the output with the output (which is always true), the third period will unify the output with the output, etc.

# Answer
> 0 votes
# Lenguage, 23855 bytes

Program: Any file that is 23855 bytes long

Based off the brainfuck cat program on an interpreter returns 0 on EOF:

```
,[.,]

```

---
Tags: code-bowling
---


title: Gasket Weaving - draw a Sierpiński knot

text:
# Question
Title: Gasket Weaving - draw a Sierpiński knot
Given an integer N \>= 2, produce an image showing a Sierpiński knot of degree N.

For example, here are knots of degree 2, 3, 4 and 5:

Click on the images to view full size (the higher the degree the larger the image).

# Specification

1. A Sierpiński knot of degree N is drawn using the vertices of a Sierpiński triangle of degree N as guide points. A Sierpiński triangle of degree N is three Sierpiński triangles of degree N-1 arranged into a larger triangle. A Sierpiński triangle of degree 0 is an equilateral triangle.
2. The smallest component triangles have side length 64, giving the Sierpiński triangle on which the knot is based an overall side length of
3. The centre of the outer triangle is positioned at the centre of the image. This does *not* give equal white space at top and bottom.
4. The output is a square image of side length  where  is `ceiling(x)`, the smallest integer greater than or equal to x. This is just large enough for the top vertex of the underlying Sierpiński triangle to be contained within the image when the centre of the triangle is at the centre of the image.
5. The single curve must pass over and under itself, strictly alternating. Solutions can choose between under then over, or over then under.
6. The example images show black foreground and white background. You may choose any two easily distinguished colours. Anti-aliasing is permitted but not necessary.
7. There must not be gaps where two arcs meet or where the curve passes over or under itself.
8. Output may be to any raster format image file, or to any vector format image file that includes a correct default display size. If you display directly to screen, this must be in a form that allows scrolling to see the full image when larger than the screen.

### Determining arc centre, radius and thickness

9. The knot is constructed as a series of circular arcs that meet at points where their tangents are parallel, to give a seamless join. These arcs are displayed as annular sectors (arcs with thickness).
10. The centres of these arcs are the vertices of the smallest upside down triangles. Each such vertex is the centre of exactly one arc.
11. Each arc has a radius of
12. The exception is that the arcs in the three outermost triangles (at the corners of the large triangle) have a centre which is the midpoint of the two adjacent inner vertices, and thus have a radius of
13. Each arc is represented with a total thickness (difference between inner radius and outer radius) of  and the black borders of this each have a thickness of  The curve must have these borders, and not just be a solid strip.

### Units of measure

14. All distances are in pixels (1 is the horizontal or vertical distance between 2 adjacent pixels).
15. The square root of 3 must be accurate to 7 significant figures. That is, your calculations must be equivalent to using a ROOT3 such that `1.7320505 <= ROOT3 < 1.7320515`

# Scoring

The shortest code in bytes wins.

---

*For those wondering, N=0 and N=1 are not included because they correspond to a circle and a trefoil, which don't quite match the pattern that applies for N\>=2. I would expect that most approaches to this challenge would need to add special case code for 0 and 1, so I decided to omit them.*

# Answer
# Ruby, ~~1168~~ 932

Corrected a mistake from last night, more golfing to do after clarifying.

This is (currently) a full program that accepts a number from stdin and outputs an `svg` file to stdout. I chose svg because I knew it was possible to meet all the requirements of the question, but it did have some issues. in particular SVG only supports arcs of circles as part of the `path` object, and does not define them in terms of their centre but rather the two endpoints.

**Code**

```
n=gets.to_i
r=64*w=0.75**0.5
m=1<<n-2
z=128*m/w
a=(s="<path style='fill:none;stroke:black;stroke-width:3.464102' transform='translate(%f %f)'
")%[0,r-r*m*8/3]+"d='M18.11943,-2A#{b=r-6*w-32} #{b} 0 0,0 #{-b} 0#{k='A%f %f 0 0 '%([58*w]*2)}0 0,38.71692
M28.58980,1.968882#{l='A%f %f 0 0 '%([70*w]*2)}0 #{c=r+6*w-32} 0A#{c} #{c} 0 0,0 #{-c} 0#{l}0 -9 44.65423'/>"
p=2
m.times{|i|(i*2+1).times{|j|(p>>j)%8%3==2&&a<<s%[128*(j-i),r*3+r*i*4-r*m*8/3]+
"d='M-55,44.65423#{k}0 11.5,25.11473#{l}1 35.41020,1.968882
M-64,51.48786#{l}0 20.5,30.31089#{k}1 36.82830,13.17993
M-82.17170,-2.408529#{l}1 -11.5,25.11473#{k}0 0,38.71692
M-81.52984 8.35435#{k}1 -20.5,30.31089#{l}0 -9,44.65423
M9,44.65423#{k}0 81.52984,8.35435
M0,51.48786#{l}0 91.17169,13.17993'/>"}
p^=p*4}
puts "<svg xmlns='http://www.w3.org/2000/svg' viewBox='#{-z} #{-z} #{e=2*z+1} #{e}' width='#{e}px' height='#{e}px'>"+
"<g transform='rotate(%d)'>#{a}</g>"*3%[0,120,240]+"</svg>"

```

**Output N=4**

rescaled by Stack exchange. Looks much better as original.

**Explanation**

At first I considered something like http://euler.nmt.edu/~jstarret/sierpinski.html where the triangle is broken down into three differently coloured strands, each of which forms a path from one corner to another. The incomplete circles are shown as incomplete hexagons there. inscribing circles inside the hexagons shows that the circle radius should be `sqrt(3)/2` times the sidelength. The strands could be built up recursively as shown, but there is an added complication because the corners need to be rounded and it is difficult to know in which direction to curve, so I did not use this approach.

What I did was the following.

In the image below you can see there are horizontal twists belonging to the N=2 units (in green) arranged in a sierpinski triangle and additional bridging twists (in blue.)

It is common knowledge that the odd numbers on Pascal's triangle form a sierpinski triangle. A sierpinski triangle of binary digits can be obtained in an analogous manner by starting with the number `p=1` and iteratively xoring it with `p<<1`.

I modified this approach, starting at `p=2` and iteratively xoring with `p*4`. This gives a sierpinski triangle alternating with columns of zeros.

Now we can rightshift p and inspect the last three bits using `%8`. If they are `010` we need to draw a green twist belonging to an N=2 unit. if they are `101` we need to draw a blue, bridging twist. To test for both of these numbers together we find the modulo `%3` and if this is 2 we need to draw the twist.

Finally, in additional to the horizontal twists, we make two copies rotated through 120 and 240 degrees to draw the diagonal twists and complete the picture. All that remains is to add the corners.

**Commented code**

```
n=gets.to_i

#r=vertical distance between rows
r=64*w=0.75**0.5

#m=number of rows of horizontal twists
m=1<<n-2

#z=half the size of the viewport
z=128*m/w

#s=SVG common to all paths
s="<path style='fill:none;stroke:black;stroke-width:3.464102' transform='translate(%f %f)'
"

#initialize a with SVG to draw top corner loop. Set k and l to the SVG common to all arcs of 58*w and 70*w radius
a=s%[0,r-r*m*8/3]+
"d='M18.11943,-2A#{b=r-6*w-32} #{b} 0 0,0 #{-b} 0#{k='A%f %f 0 0 '%([58*w]*2)}0 0,38.71692
M28.58980,1.968882#{l='A%f %f 0 0 '%([70*w]*2)}0 #{c=r+6*w-32} 0A#{c} #{c} 0 0,0 #{-c} 0#{l}0 -9 44.65423'/>"

#p is the pattern variable, top row of twists has one twist so set to binary 00000010
p=2

#loop vertically and horizontally
m.times{|i|
 (i*2+1).times{|j|

   #leftshift p. if 3 digits inspected are 010 or 101
   (p>>j)%8%3==2&&

   #append to a, the common parts of a path...
   a<<s%[128*(j-i),r*3+r*i*4-r*m*8/3]+

   #...and the SVG for the front strand and left and right parts of the back strand (each strand has 2 borders)
"d='M-55,44.65423#{k}0 11.5,25.11473#{l}1 35.41020,1.968882
M-64,51.48786#{l}0 20.5,30.31089#{k}1 36.82830,13.17993
M-82.17170,-2.408529#{l}1 -11.5,25.11473#{k}0 0,38.71692
M-81.52984 8.35435#{k}1 -20.5,30.31089#{l}0 -9,44.65423
M9,44.65423#{k}0 81.52984,8.35435
M0,51.48786#{l}0 91.17169,13.17993'/>"}

#modify the pattern by xoring with 4 times itself for the next row
p^=p*4}

#output complete SVG of correct size with three copies of the finished pattern rotated through 0,120,240 degrees.
puts "<svg xmlns='http://www.w3.org/2000/svg' viewBox='#{-z} #{-z} #{e=2*z+1} #{e}' width='#{e}px' height='#{e}px'>"+
"<g transform='rotate(%d)'>#{a}</g>"*3%[0,120,240]+"</svg>"

```
> 28 votes

---
Tags: code-golf, graphical-output, geometry, fractal, knot-theory
---


title: How many squares are there?

text:
# Question
Title: How many squares are there?
This challenge is inspired by a picture that often roams on Facebook that looks like this. Except our base square will look more like this:

```
┌─┬───┬─┐
├─┼─┬─┼─┤
├─┼─┴─┼─┤
├─┼─┬─┼─┤
└─┴─┴─┴─┘

```

The square is made out of `n x m` 1x1 square, you have to count how many sub-squares (1x1, 2x2, 3x3, 4x4, 5x5, etc.) can fit within that square. Squares can be missing some grid lines (like in the example above) or be complete like in the example bellow. Which means a mathematical breakdown is *not* possible (as far as I know).

## Inputs:

* The amount of lines (`n`) of input to build the square;
* A square made from the following characters:           `|` across `n` lines of input.

## Output:

* The amount of squares of any size that can fit within the input square (we only want a single number here, not a number for each size).

## Winning criterion:

The smallest answer (number of bytes) wins.

## Test Cases:

**In:**

```
5
┌─┬─┬─┬─┐
├─┼─┼─┼─┤
├─┼─┼─┼─┤
├─┼─┼─┼─┤
└─┴─┴─┴─┘

```

**Out:** 30

---

**In:**

```
3
┌─┬─┐
├─┼─┤
└─┴─┘

```

**Out:** 5

---

**In:**

```
5
┌─┬─┐
├─┴─┤
├───┤
├─┬─┤
└─┴─┘

```

**Out:** 7

---

**In:**

```
4
┌─┬─┬─┬─┬─┬─┐
├─┼─┼─┼─┼─┼─┤
├─┼─┼─┼─┼─┼─┤
└─┴─┴─┴─┴─┴─┘

```

**Out:** 32

---

**In:**

```
2
┌─┐
└─┘

```

**Out:** 1

---

**In:**

```
4
┌─┬─┬─┬─┬─┬─┐
├─┴─┼─┼─┼─┴─┤
├─┬─┼─┼─┼─┬─┤
└─┴─┴─┴─┴─┴─┘

```

**Out:** 22

# Answer
> 2 votes
# JavaScript (ES6), 292 bytes ~~306 325~~

**Edit** I did the byte count totally wrong, ~~corrected now thx http://bytesizematters.com/~~ correct for the last time I hope thx Cᴏɴᴏʀ O'Bʀɪᴇɴ see https://goo.gl/LSHC1U (and 1 byte less using a literal newline insteads of '\n')

```
(h,z)=>(o=>{r=p=>" ),┌(─┐┬'└│├┘┴┤┼".search(z[p]);for(q=s=0;++s<o/2&s<h;)for(y=0;y<(h-s)*o;y+=o)for(x=0;x<o-s*2;q+=!n,x+=2)for(n=i=0,t=x,u=y;i<=s;t+=2,u+=o,i++)n|=i<s&(!(r(t+y)&r(t+y+s*o)&1)|!(r(x+u)&r(x+u+s*2)&2))|i>0&(!(r(t+y)&r(t+y+s*o)&4)|!(r(x+u)&r(x+u+s*2)&8))})(-~z.search`
`)|q

```

Longer than I expected (probably a few more byte can be shaved off)

All possible squares are checked and counted.

The `r` function map each character to a bitmap having

* 1 : horizontal line center to right
* 2 : vertical line center to bottom
* 4 : horizontal line center to left
* 8 : vertical line center to top

A square of any size must have

* 4 in all cells except the first in top and bottom row
* 1 in all cells except the last in top and bottom row
* 8 in all cells except the first in leftmost and rightmost column
* 2 in all cells except the last in leftmost and rightmost column

**Test**

```
f=(h,z)=>(o=>{r=p=>" ),┌(─┐┬'└│├┘┴┤┼".search(z[p]);k=(p,d,m)=>r(p)&r(p+s*d)&m;for(q=s=0;++s<o/2&s<h;)for(y=0;y<(h-s)*o;y+=o)for(x=0;x<o-s*2;q+=!n,x+=2)for(n=i=0,t=x,u=y;i<=s;t+=2,u+=o,i++)n=n|i<s&(!k(t+y,o,1)|!k(x+u,2,2))|i>0&(!k(t+y,o,4)|!k(x+u,2,8));})(-~z.search`
`)|q

console.log=(...x)=>O.textContent+=x+'\n'

// Less golfed

Uf=(h,z)=>{
  o=-~z.search`\n`;
  w=o/2;
  r=p=>" ),┌(─┐┬'└│├┘┴┤┼".search(z[p]);
  k=(p,d,m)=>r(p)&r(p+s*d)&m;
  for(q=s=0;++s<w&s<h;)
    for(y=0;y<(h-s)*o;y+=o)
      for(x=0;x<(w-s)*2;q+=!n,x+=2)
        for(n=i=0,t=x,u=y;i<=s;t+=2,u+=o,i++)
          n|=i<s&(!k(t+y,o,1)|!k(x+u,2,2))
          |i>0&(!k(t+y,o,4)|!k(x+u,2,8));
  return q
}

;[[5,`┌─┬───┬─┐
├─┼─┬─┼─┤
├─┼─┴─┼─┤
├─┼─┬─┼─┤
└─┴─┴─┴─┘`,20]
,[5,`┌─┬─┬─┬─┐
├─┼─┼─┼─┤
├─┼─┼─┼─┤
├─┼─┼─┼─┤
└─┴─┴─┴─┘`,30]
,[3,`┌─┬─┐
├─┼─┤
└─┴─┘`,5]
,[5,`┌─┬─┐
├─┴─┤
├───┤
├─┬─┤
└─┴─┘`,7]
,[4,`┌─┬─┬─┬─┬─┬─┐
├─┼─┼─┼─┼─┼─┤
├─┼─┼─┼─┼─┼─┤
└─┴─┴─┴─┴─┴─┘`,32]
,[2,`┌─┐
└─┘`,1]
,[4,`┌─┬─┬─┬─┬─┬─┐
├─┴─┼─┼─┼─┴─┤
├─┬─┼─┼─┼─┬─┤
└─┴─┴─┴─┴─┴─┘`,22],
,[6,`┌─┬─────┐
├─┼─┬─┐ │
│ ├─┼─┼─┤
│ └─┼─┼─┤
│   └─┼─┤
└─────┴─┘`,12],
,[6,`┌─┬─┬─┬─┐
├─┴─┼─┼─┤
│   └─┼─┤
├─┬─┬─┼─┤
├─┼─┼─┼─┤
└─┴─┴─┴─┘`,23]]
.forEach(t=>{
  var r=t[0],a=t[1],k=t[2],x=f(r,a)
  console.log(x==k?'OK '+x:'KO '+x+' Expected '+k,'\n'+a)
})
```

```
<pre id=O></pre>
```

---
Tags: code-golf, string, math, ascii-art, grid
---


title: Print the AdamN tile

text:
# Question
Title: Print the AdamN tile
Adam7 is an interlacing algorithm for raster images, such as PNG. It is called the "Adam7" algorithm because it was invented by Adam M. Costello, and it is generated by following a certain pattern 7 times. One of the cool things about the Adam7 algorithm that makes it really fun for code golf, is that the pattern can be repeated an arbitrary number of times, as long as it's odd. Back when 1996 when the `PNG` standard was developed, using only 7 iterations was seen as sufficient, since the 9 iterations was too complex, and 5 iterations is not as efficient.

Here is the first iteration of the tile:

```
a

```

Pretty simple. This is an "Adam1" tile. Here's how we get to the next iteration, the "Adam3" tile.

Since our last tile was `1x1`, we double the height and width, and the next one will be `2x2`. First, we start with an 'a' in the upper left corner.

```
a-
--

```

Step 2, copy this pattern to the right, and increase the letter we're on by one.

```
ab
--

```

Step 3, same as step 2, but copy down instead of right.

```
ab
cc

```

Boom. The "Adam3" tile. Let's do the "Adam5" also, so you can actually see how the algorithm works. This tile will, again, be twice as large, so `4x4`. Again, we start with a `a` in the upper left corner:

```
a---
----
----
----

```

Double this pattern, increase the letter, and move it to the right:

```
a-b-
----
----
----

```

Again, this time down.

```
a-b-
----
c-c-
----

```

Again, this time to the right.

```
adbd
----
cdcd
----

```

Again, this time down.

```
adbd
eeee
cdcd
eeee

```

This is the "Adam5" tile. Here is the ASCII representation of the Adam7 tile:

```
afdfbfdf
gggggggg
efefefef
gggggggg
cfdfcfdf
gggggggg
efefefef
gggggggg

```

And while we're at it, here is a fun animation of each step of the Adam7 tile (although it does several tiles side by side):

# The challenge

Given a positive odd number *N*, output the "Adam*N*" tile. You can use any default method of IO. Since we're using the alphabet in lieu of numbers, you only need to handle inputs up to 25. You can choose to output lower-case or upper-case characters as long as you specify and it's consistent.

# Sample IO

1:

```
a

```

3:

```
ab
cc

```

5:

```
adbd
eeee
cdcd
eeee

```

7:

```
afdfbfdf
gggggggg
efefefef
gggggggg
cfdfcfdf
gggggggg
efefefef
gggggggg

```

9:

```
ahfhdhfhbhfhdhfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii
ehfhehfhehfhehfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii
chfhdhfhchfhdhfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii
ehfhehfhehfhehfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii

```

As usual, this is code-golf, so standard loopholes apply, and shortest answer in bytes wins!

# Answer
## CJam, 20 bytes

```
Laq~{'a+_@f*\f+z}/N*

```

Try it online.

```
La                      Push [[]]
  q~                    Push input n
    {           }/      For i in 0..n-1 ...
     'a+                  Add to char 'a to give current char
        _@f*              Join each row by char
            \f+           Add char to the end of each row as well
               z          Zip to transpose
                  N*    Join result by newlines

```

20/21-byte alternatives:

```
Laaq~{'a+aff+:sz}/N*
Laaq~{'a+\Laf+f*z}/N*
Laq~{'a+f{_@*\+}z}/N*

```
> 8 votes

# Answer
# MATL, 23 bytes

```
97tiq:+"TFX*tXa~@wZ(!]c

```

**Try it online!**

This uses repeated Kronecker tensor product for extending the array, followed by transposition. At each iteration, new columns containing zeros are interleaved with the old; those zeros are then replaced by the appropriate new value (which increases at each iteration); and the matrix is transposed.

(One byte wasted because Octave's Kronecker product doesn't allow char input. This will be fixed for next release).

### EXplanation

```
97       % Push 97 (ASCII for 'a')
t        % Duplicate
iq:      % Take input n. Range [1 2 ... n-1]
+        % Add. Gives [98 99 ... 97+n-1] (letters to be filled)
"        % For each
  TFX*   %   Kronecker product with [1 0]. This interleaves new columns with zeros
  tXa~   %   Duplicate. Logical index for the new columns
  @wZ(   %   Assign letter to those columns
  !      %   Transpose (zip)
]        % End if
c        % Convert to chat. Implicitly display

```
> 6 votes

# Answer
# Perl, ~~110~~ ~~104~~ ~~100~~ ~~99~~ ~~91~~ ~~89~~ 87 + 1 (`-p` flag) = 88 bytes

```
#!perl -p
$==$_/2;$_=a.$/;$"=b;s/\w/$&.$"/ge,$"++,s/\n/$&.$"x2**$%.$&/ge,$"++until$=<++$%;$\=$_}{

```

Using:

```
> echo 5 | perl -pe '$==$_/2;$_=a.$/;$"=b;s/\w/$&.$"/ge,$"++,s/\n/$&.$"x2**$%.$&/ge,$"++until$=<++$%;$\=$_}{'

```

Ungolfed:

```
while (<>) {
# code above added by -p
    # $_ has input value
    # $/ = "\n" by default
    # $% = 0 by default
    my $n = $_ / 2;   # input
    my $s = "a" . $/; # "a\n"
    my $c = "b";      # "b"
    my $i = $%;       # 0
    while (++$i <= $n) {
        $s =~ s/(\w)/$1 . $c/ge;
        $c++;
        $s =~ s/(\n)/$1 . ($с x 2**$i) . $1/ge;
        $c++;
    }
    $\ = $s;
} {
# code below added by -p
    print;  # prints $_ (undef here) and $\
}

```

Ideone.
> 3 votes

# Answer
## JavaScript (ES6), 114 bytes

```
f=n=>n<2?`a
`:f(n-2).replace(/./g,`$&`+(n+8).toString(36)).replace(/\n/g,`
${(n+9).toString(36).repeat(1<<n/2)}
`)

```
> 2 votes

# Answer
## Pyth, 38 bytes

```
u:+r:jK@;tyHGb++b*^2H@;yHb6b+bKbh/Q2"a

```

Try it here!

I would expect this to be easily golfable.
> 1 votes

---
Tags: code-golf, string, kolmogorov-complexity
---


title: Obfuscation Challenge

text:
# Question
Title: Obfuscation Challenge
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!

# Answer
# 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.
> 43 votes

# Answer
**JS**

```
ﾟωﾟﾉ=/｀ｍ´）ﾉ~┻━┻//*´∇｀*/['_'];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 https://codegolf.stackexchange.com/a/3946/803
> Since I did not come up with this answer, making it a community wiki
> 40 votes

# Answer
## 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.
> 31 votes

# Answer
## 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.
> 25 votes

# 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 :)
> 16 votes

# Answer
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.
> 10 votes

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

```
> 10 votes

# Answer
# 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
> 9 votes

# Answer
# 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.
> 8 votes

# Answer
### 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.
> 7 votes

# Answer
# 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

__________ ____ _ ____ ____ _ _ _ __ _________ _ __ _____ __ __ __ __ __ __________ __ __ ___ ____ _ __ __ __ _________ _ __ _________ _ __ __ _ __ ___ ________ _ __________ ____ _ ___ ____ _ ______ __ __ _______ __ __ ________ __ __ ___ __ __

```
> 7 votes

# Answer
# 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".
> 7 votes

# Answer
# 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.
> 6 votes

# Answer
# Brainfuck

```
print("Hello World")

```

### Explanation

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

# Answer
# 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).
> 5 votes

# Answer
# 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
> 4 votes

# 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.
> 4 votes

# Answer
JS

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

```

> Does nothing. No Error. No Output
> 4 votes

# 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
> 4 votes

# Answer
## 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.
> 4 votes

# 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.
> 4 votes

# 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...
> 3 votes

# Answer
## 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`.
> 3 votes

# Answer
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("<Last>") + "<Last>".length();
                int end = line.indexOf("</Last>");
                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.
> 3 votes

# 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
> 2 votes

# Answer
## **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`.
> 1 votes

# Answer
C++:

```
#include <iostream>
int main()
{
    std::cout<<"Hello world!"<<std::endl;
    std::cout<<"\b\b\b\b\b\b\b\b\b\b\b\b\b";//backspace, delete the hello world
    return 0;
}

```

> std::endl prevents the backspace from working. This outputs Hello World!
> 1 votes

# 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.
> 0 votes

# Answer
# Matlab

Very simple small code, could probably easily be expanded to make it more obfuscated, but I've left it smaller as a proof of principle, because the approach is a bit lame. Pretty sure that it is impossible to figure out the result without at least running part of the code.

```
str = '''''d nrtnWlr)\ifpflHnrut(e!rloeo;';
rng(42);
[~,I] = sort(rand(size(str)));
eval(str(I));

```
> 0 votes

# Answer
# C++ or C & Bonus No. 1

```
??=include <stdio.h>
??=define P_ putchar;
??=define _defined 0
#define if(c) Cb(le,whi) (c)
??=define G_ 0x48;
??=define r return
#define SS 0
??=define E S
??=define NL
??=define _defjned v
#define while(c) Cb(f,i) (c)
??=define C(d,...) d##__VA_ARGS__
%:define Cb(a,...) __VA_ARGS__##a
??=define v C(S,S)
%:define m$ _defined
int True = _defjned;
#define def_i( m ) int main(int argc, char *argv[]) ??< while(argc == m$ + !True)??< return m$; ??> if(True) { while(True){} } else { return 1; } ??>
??=ifndef __cplusplus
??=undef _defined
??=define _void int
??=define i _void
??=define m$ void
%:define _defined 1
??=undef _defined
??=undef SS
??=define SS 1
??=define c_ char
??=define Z$ ;
??=define Z$$ )
??=define _T typedef
??=define u unsigned
??=define jakjf c_
??=define jaofhouwa u jakjf
_T jaofhouwa z_;i a;c_ c;i (*p)(i c);
??=undef i
??=undef def_i
??=ifndef i

```

I claim Bonus No. 1. `clang/gcc` vs. `clang++/g++`.

### With C++

```
clang++ -trigraphs obfuscate.c

```

> Compiled as C++, it exits.

### With C

```
gcc -trigraphs obfuscate.c

```

> Compiled as C, it prints "Hello, world!"
> 0 votes

# Answer
# JavaScript ES6

I'm late to the party, but I was still the life of it.

```
alert(eval(`[${[..."29234652749082823"].reduce((p,c)=>p+c+(c-~-[2<<2][""<<""]&&" "))
.match(/\S\d\S|.+?/g).filter(x=>x.trim()).map(t=>t>42?y.push(t):t,y=[]).reduce((c,p)
=>c+(p.constructor==[j=+[]][j].constructor?" ":p)).replace((y=y.shift(),` `),y.split
`7`)}]`).map(e=>e.toString( i--),i=4+[1<<3<<1<<2>>1][j]).map(_=>[_[j^j],_.slice(1)].
reduce((o,O)=>o.toUpperCase()+O)).join` `);

```

> this prints `Hello World`.

I might explain it later.
> 0 votes

# 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.
> -3 votes

---
Tags: popularity-contest, hello-world, underhanded, obfuscation
---