# Question
Title: Unscramble the Source Code [robber thread for cracking attempts]
**This is the companion thread to the main Unscramble the Source Code challenge.** If you think you have managed to unscramble one of the cop answers, you should post your solution as the answer to this thread.

As a reminder, you have one attempt at cracking each submission. Your cracking attempt will be an unscrambled version of the source code. If your guess matches the description (same characters, output, and of course language), and you are the first correct guess, then you win a point. It is important to note that your program does not have to exactly match the original, simply use the same characters and have the same functionality. This means there could be more than one correct answer.

The robber with the most points (successful cracks) wins.

## Leaderboard

**Too many solves**

**20 solves**

**15 solves**

**10 solves**

**7 solves**

**5 solves**

**4 solves**

**3 solves**

**2 solves**

**1 solve**

# Answer
> 33 votes
# CJam, size 20, by Martin Büttner

```
Hi "petStorm!", mame

```

Try it online.

### How it works

```
Hi                      "           int(17)                     ";
   "petStorm!",         "                    len('petStorm!')   ";
                ma      "     atan2(       ,                 )  ";
                  me    " exp(                                ) ";
                        " exp(atan2(int(17), len('petStorm!'))) ";

```

### Cracking the code

The desired output, `2.956177636986737`, is either a Double or a Double followed by a Long.

Using only the characters in `"Stop, Hammer time!"`, there are four builtin operators that return non-integer Doubles:

* `mS`, which is `asin`
* `ma`, which is `atan2`
* `me`, which is `exp`
* `mt`, which is `tan`

All of them contain an `m`, so we can use at most three of them. There is only one `S` and one `a`.

All of those operators need input, and `ma` is the only one that consumes two inputs. We have only three ways to push Longs:

* `"...",`, which pushes the string's length (strictly less than 18).
* `H`, which pushes 17.
* `...!`, which pushes the logical NOT of `...`.

We have no way of pushing something falsy as `...`, so the last option will always push 0.

The output doesn't begin or end with `17` or `0`. Since 15 decimal digits is the usual number of digits for a Double, it seemed likely that the output was a simple Double.

Assuming this, the code has to fall in one of the following categories:

* `<Long> <mS|me|mt>{1,3}`
* `<Long> <mS|me|mt>{x} <Long> <mS|me|mt>{y} ma <mS|me|mt>{z}`.
* Any of the above, with some cast to Long (`i`) or rounding (`mo`) applied to a Double.

In the second case, `x + y + z` is either 1 or 2 and one of the Longs is 0 or 17.

The rest was basically brute force. After a few tries,

```
18 , {H \ ma me 2.956177636986737 =} =

```

returned `9`, meaning that

```
H 9 ma me

```

produces the desired output.

All that's left is to eliminate all but 9 characters from the string. Spaces are noops and `i` is a noop on Longs, so `"petStorm!"` is one of the possible choices.

# Answer
> 26 votes
# Python 3, size 12, by xnor

```
()and bciprt

```

Does nothing (expression produces an empty tuple, which is not printed). This works due to short-circuit evaluation.

# Answer
> 24 votes
# Python, size 74, by xnor

```
any(print(set is
set)for i in oct(chr is
map))and aeeeeeggiilnnpprrrrrstvw

```

Well that was fun. Thanks to FryAmTheEggman, hosch250 and isaacg for suggestions/helping out.

# Answer
> 13 votes
## Python 2, size 50, by Geobits

```
print 2**2**2*2**2-22-2**2**2**2/2**2**2**2**2/2/2

```

Outputs 42.

# Answer
> 13 votes
# GolfScript, size 13, by Peter Taylor

```
,22,{.4&?+.}/

```

Test it here.

Another one, that I only cracked with big help from Sp3000. Thanks!

So here's how we got there. Sp3000 noticed a bunch of runs of consecutive numbers in the output:

```
1,2,3,4,[2608852181],4582,4583,4584,4585,4586,[253225388392299],
142924,142925,142926,142927,142928,[302928],497409,497409

```

Based on that we made the assumption, that this was an increasing sequence, which only allowed for one possible splitting of the remaining numbers:

```
1,2,3,4,260,885,2181,4582,4583,4584,4585,4586,25322,53883,92299,
142924,142925,142926,142927,142928,302928,497409,497409

```

That's 23 numbers, which was a strong indicator for repeating the block 22 times, as well as ending the block with `.` (duplicate top stack element), such that the previous result got left behind on the stack and such that the final iteration would appear on the stack twice. That's `22,{____.}/`.

Now looking at the gaps, those turn out to be 4th powers (which is nice, because we have `4` and `?`). More precisely, they are the fourth power of the index of the current number. So next we looked at which indices created a gap:

```
4,5,6,7, 12,13,14,15, 20,21,..?

```

In binary those are

```
00100
00101
00110
00111
01100
01101
01110
01111
10100
10101

```

They all have the third bit set, which means that the index is probably just bitwise-and'ed with `4` (which is nice again, because we can make another `4` with `.` and have a `&`). This works particularly well, because this operation results in either `0` or `4`, and if we use that as the exponent we get either `1` or a fourth power, which is exactly what we need. So let's put that together:

```
22,{.4&?+.}/

```

Here is what the block does:

```
.      # Duplicate current index
 4     # Push a 4
  &    # Bitwise and
   ?   # Raise index to resulting power
    +  # Add to previous result
     . # Duplicate for use in next iteration

```

Now there were two problems left: we had a stray `,` we didn't use yet, and the first iteration is a special case, in that there is no value from a previous iteration which we could add things to when encountering `+`. We found that thanks to an unrelated comment by user23013 who casually mentioned that GolfScript starts out with an empty string on the stack (if there's nothing on STDIN). So we could use that other `,` right at the beginning to turn that string into a `0`, which was just what we needed as the start of the iteration.

# Answer
> 11 votes
# Python 3, size 16, by matsjoyce

```
import __hello__

```

# Answer
> 11 votes
# Ruby, size 17, by Doorknob

```
p 2,%r~n~i=~'*tN'

```

That was great fun. Thanks to Sp3000 for helping me out with this! And I learned that `%r?...?` literals can have any delimiters. :)

# Answer
> 11 votes
# PHP, size 49, by bwoebi

```
print@substr(new exception,+~$$a+=++$$m+$$i+2+n);

```

That was absolutely *mental*.

It got to

```
print@substr(new exception,);

```

fairly quickly, at which point I needed something that gives `-6` after the comma, having `$++$++$++$+=$~main$2` left.

The main catch is that `$a`, `$m` and `$i` are all `NULL`, so using them indirectly in variable variables, means they all point to the same variable. However, PHP seems to be doing some weird things about resolving variable variables. With normal variables you can do things like

```
echo $a+$a=2;

```

which prints `4` (the `2` is assigned to `$a` and then added to itself). But if I do the same with variable variables:

```
echo $$a+$$a=2;

```

I get `2`, because now the first `$$a` is evaluate before the assignment.

In the end I managed to force some order by putting some increments on the RHS of the `+=` which had to be evaluated before that addition-assignment. That way I got to `5` which I could then just bit-complement. Still... there are some mysterious things going on, and I have no idea why half the things I tried worked and didn't work.

# Answer
> 9 votes
# Ruby, size 38, by Doorknob

```
[$><<(!$pece60).to_s[rand($win)].succ]

```

I'm pretty sure this is nowhere near the original source. It's deterministic despite using `rand`.

Here is how this one works. `$><<` is just output. `$pece60` and `$win` are undefined global variables, which therefore are just `nil` (and they allowed me to get rid of some extraneous characters). `!$pece60` makes a `true` and `to_s` gives the string `"true"`.

For ages, I tried getting a `2` or `-2` to access that `u` in there, but then I realised I could just take the `t`, and call `.succ`(essor) on it to make a `u`.

`rand` with a `nil` parameter returns a random float in the interval \[0,1). When using floats to index into strings, they get truncated to integers, so this will always return the first character.

Finally, I had a spare pair of `[]` so I just wrapped everything in it, because thankfully everything is an expression in Ruby.

Thanks to Sp3000 for throwing some ideas around in chat.

# Answer
> 8 votes
# C, 51 by es1024

```
c=0xf.cp9,hhtaglfor;main() {;; printf("%d",(++c));}

```

After 20 years of programming C today I learned about hexadecimal floating point constants.

# Answer
> 8 votes
# Ruby, 45 (histocrat)

```
%q[zyfnhvjkwudebgmaclprs x].to_i(36)/51074892

```

Woohoo! This is my first crack at a code golf problem, and I don't have enough rep to comment on the original post. I immediately recognized the trick used, since I've actually found use for it in production code often. It took about 5 minutes to figure out most of the structure and a few hours to come up with the complete answer.

Explanation:

* `%q[]` is an alternative method for creating strings. Parenthesis and curly braces may also be used.
* `String#to_i` in Ruby accepts numbers in any base from 2 to 36. It will ignore the first character in the string which is not part of the number, so any extra characters can be "thrown away" after the space.

And here's the code I used to crack it:

```
require 'set'

# return true if the string is made up of unique characters
def uniq(s)
  a = s.each_char.to_a
  return a == a.uniq
end

def uniq_while_same(a,b)
  s = Set.new
  a.each_char.zip(b.each_char).each do |ai, bi|
    return true if ai != bi
    return false if s.include? ai
    s << ai
  end
  return true
end

def ungolf(answer)
  # For each base that even makes sense
  [            36, 35, 34,     32, 31, 30,
   29, 28, 27, 26, 25, 24, 23,     21, 20,
   19, 18, 17, 16, 15, 14, 13, 12,     10].each do |base|
    # Ignore bases where it is not possible to create a unique-string number greater than answer
    next if answer > base ** base
    # Pick digits for the denominator that are not duplicates of the digits in base
    denominator_digits = ('1234567890'.each_char.to_a - base.to_s.each_char.to_a)
    # For each permutation of those digits for the denominator
    (1..10).each do |denominator_length|
      denominator_digits.permutation(denominator_length) do |denominator_s|
        # Maybe the denominator is in octal
        denominator_base = 10
        if denominator_s[0] == '0'
          next if denominator_s.include?('8') || denominator_s.include?('9')
          denominator_base = 8
        end
        denominator_s = denominator_s.join
        denominator = denominator_s.to_i denominator_base
        print "#{"\b"*64}(%q[#{(answer * denominator).to_s(base).ljust(36)}].to_i #{base})/#{denominator_s.ljust(10)}" if rand < 0.01
        # Ignore denominators that are definitely impossible to have answers for
        next unless uniq_while_same "qtoi#{base}#{denominator_s}#{(answer * denominator).to_s(base)}",
                                    "qtoi#{base}#{denominator_s}#{((answer + 1) * denominator).to_s(base)}"

        # For each numerator that gives answer when divided by the denominator
        (answer * denominator...(answer + 1) * denominator).each do |numerator|
          print "#{"\b"*64}%q[#{numerator.to_s(base).ljust(36)}].to_i(#{base})/#{denominator_s.ljust(10)}" if rand < 0.01
          # Remove any that are still not unique
          s = "#{numerator.to_s(base)}#{base}#{denominator_s}qtoi"
          next unless uniq s
          # Done. Compute which characters need to be thrown away to fill the remaining space
          remains = ('0123456789abcdefghijklmnopqrstuvwxyz'.each_char.to_a - s.each_char.to_a).join
          print "#{"\b"*64}#{" "*64}#{"\b"*64}"
          return "%q[#{numerator.to_s(base)} #{remains}].to_i(#{base})/#{denominator_s}"
        end
      end
    end
  end
  print "#{"\b"*64}"
  puts "\nnone"
  return nil
end

print ungolf 9410663329978946297999932

```

Way to go embedding an NP problem inside a riddle. I have been thoroughly nerd-sniped. Good job!

# Answer
> 7 votes
# Python \[any\] shell size 44, by Caridorc

```
__name__[3]  or (enfin_____[42], manager[1])

```

I'm sure there was supposed to be more to it than this, but since `__name__` equates to `__main__`, the 4th character 'a' is selected and the rest of the line is never evaluated.

# Answer
> 7 votes
## Perl, size 36, by squeamish ossifrage

```
$_=rof;for$i(1..2129<<7){$_++}print;

```

Another difficult one.

# Answer
> 7 votes
# CJam, size 13, by user23013

```
G,Cf#If/sE*K%

```

Test it here.

Solved by hand, like so:

First, some background for non-CJammers:

* `CEGIK` are all variables, which are pre-initialised to `12`, `14`, `16`, `18`, `20`, respectively.
* `s` converts the top stack element to a string.
* Strings are technically just arrays of characters.
* `f` is pretty magic. For the purpose of this answer, the simplified version is that, for an array `a`, some other value `b` and an operator `g`, the sequence `abfg` maps `g(_,b)` onto `a` (where each element of `a` goes into the `_` slot).
* `/` is division and splitting arrays (amongst other things).
* `*` is multiplication and array repetition (amongst other things).
* `%` is modulo and some weird operation, which in the form `ad%` for array `a` and integer `d` takes every `d`th element of `a` (like Python's slicing with step width `d`).
* `#` is exponentiation (amongst other things).
* `,` turns numbers into ranges (from `0` to `n-1`) and returns the length of an array.

Okay, that out of the way...

It was fairly obvious that we needed `,` to turn a number into a range, because the only other way to get an array would have been to build a larger number and turn it into a character array with `s` \- but then we couldn't have done any further arithmetic on it. And we need an array to do something with the `f`s.

I first assumed that the `f`s were used with `#` and `%`, but that would mean we would have needed a number around 90 to get the right amount of digits in the end. And also, this didn't explain what to do with `s`, and since the answer looked really golfy, I doubted user23013 just appended an `s` as an effective no-op somewhere to throw people off.

So I figured, maybe he isn't even keeping the numbers small with `%`, but instead he builds an array of huge numbers, concatenates their string representation with `s`, but then only picks some odd slice out of it with `%`. So I played around a bit with the following framework:

```
__*,_f#_f/s_%

```

(You can't do `_f/` first, because that would yield zero for at least the first 12 elements.)

Where the `_` are some permutation of the variables. I didn't try all of them before I got bored, and the main problem with this was that the resulting sequence of digits as always way too long.

At some point it occurred to me, that we wouldn't need such a large range (i.e. the product of two numbers), if instead we used the `*` to repeat the resulting string. Due to the mismatch of the parameters of `*` and `%` this would yield no repetition in the result:

```
_,_f#_f/s_*_%

```

This yielded results of a length very close to what I was looking for. I would have actually tried all 240 of them, but fairly quickly (third or fourth attempt), I stumbled upon

```
E,Cf#If/sG*K%

```

which yields

```
03081942753650251594592190492275006661328850322159030034930530649722385533653290754678977

```

And I figured a match of the first six digits wouldn't be a coincidence. So the question was how to rearrange it without upsetting the actual computation:

* I couldn't change `K` because that would pick out different digits altogether.
* I couldn't change `C` or `I` because that would change the numbers resulting from the two map operations.
* If I changed `G` that would only change the number of repetitions, which would do nothing but change the length of the result. (Which is good.)
* If I changed `E` that would change the range of the array, but the range would still start with `[0 1 2 3 ...]`, so it wouldn't affect the calculation. It *would* affect the length of the base string returned by `s`, which would also mean that `K%` would pick out different digits upon additional repetitions.

So I just tried swapping `E` and `G` and voila:

```
030819828850379075460427536222159187897761502517030034671154875945928930530907551421904962649729

```

In summary, here is what the code does:

```
G,            "Push [0 1 2 3 ... 13 14 15].";
  Cf#         "Raise each element to the 12th power.";
     If/      "Divide each element by 18.";
        s     "Concatenate all numbers into a string.";
         E*   "Repeat 14 times.";
           K% "Pick every 20th digit.";

```

# Answer
> 7 votes
# APL, size 17, by user23013

```
+(3*3)3,(***)\3 3

```

I spent *far* too long trying to crack this. It probably would've gone quicker if I knew APL going in.

Try it out here

# Answer
> 6 votes
# Pyth, size 11, by isaacg

```
:\\w$ ",d,N

```

That's some mean bug abuse right there. This compiles to:

```
Pprint("\n",at_slice("\",input(), ",d,N))

```

The relevant bug is that `\\` compiles to `"\"` instead of `"\\"`, which lets you compile Pyth into a string.

# Answer
> 6 votes
# Python, size 69, by Sp3000

```
print(sum(list(map(ord,str((dict(((str(dict()),list()),)),str()))))))

```

That was hard...

# Answer
> 6 votes
Python 3, 37 bytes, by Sp3000

```
print(sum(b"a".zfill(len(str(...)))))

```

Embarrassingly by far the hardest part was figuring out to convert the string into bytes. I had to sleep on it, and in the night realized 'duh, it's a bytes literal!'

# Answer
> 6 votes
# PHP, 53, by PleaseStand

Cracked it at last:

```
for($d=57,$o=35;$o+$d<999;)$o+=printf("$d%o",$d+=$o);

```

The solution came quite quickly when I noticed that the sequence consists of alternating decimal and octal numbers:

```
Dec: 57...92...132...177...228...285...348...417...492....573....661....756....858....
     571349220413226117734422843528553434864141775449210755731225661136475615328581707
Oct: ..134..204...261...344...435...534...641...754...1075...1225...1364...1532...1707
==Dec:  92  132   177   228   285   348   417   492    573    661    756    858    967

```

Also, the intervals between each set of numbers grew at a rate equal to the value returned by `printf()` (i.e., the number of characters written).

# Answer
> 6 votes
# Python 2, size 132, by Vi.

```
exec('from string import printable as e\nprint "cqance"\x2Ereplace("q",e[len("fgiillmmooprrsstt")])or ",,,\016:::S[]____tuuvyy" ""')

```

Thanks for all the backslashes and quotation marks :)

---

Edit: The updated 96-char version:

```
exec "try:exec'from __future__ import braces\\nt(12)'\nexcept SyntaxError as q:print(q[0][6:])"

```

This is taken entirely from Alex's solution in https://codegolf.stackexchange.com/a/41451/32353

# Answer
> 5 votes
# CJam, size 15, by Ypnypn

```
98,{7%}%{6+}%:+

```

From the given characters, I guessed it had to be one of the three following forms:

```
__,{_%}%{_+}%:+
_,{_%}%{__+}%:+
__,{_+}%{_%}%:+

```

which creates a two-digit range, then maps an addition and modulo operation (in either order) onto the range, before summing it. So I just started with the first one, and systematically tried permutations of `6789` in the gaps.

# Answer
> 5 votes
# PHP, size 52, by PleaseStand

```
for(mt_srand($i=46);$i--;)echo chr(mt_rand()%95+32);

```

This turned out to be quite easy in the end. The output looks very random, and the characters `m`, `t`, `_`, `r`, `a`, `n` and `d` all appeared twice...

# Answer
> 5 votes
## Python 2, size 61, by FryAmTheEggman

```
print(dir('~s]l.c:st_''-p_tp.l]-~.:o:Te[_u[.i_')[10][2:][:3])

```

I'd be very surprised if this matches the original.

# Answer
> 5 votes
# Python 3, Sp3000, size 44

```
print(~(~(()<((),))<<(()<((),))))<<((()<()))

```

Python 3 helped me here as I was able to cause an error (left-shifting `None` by something) after printing the answer.

# Answer
> 5 votes
# PHP, size 52, by kenorb

```
_:@print_r(chr(@++$i+pow(3<<5,1)));if($i<2*4)goto _;

```

(God, how long it took me to figure what to do with the remaining `_r` suffix. Until I noticed it was not `print`, but `print_r`...)

# Answer
> 5 votes
# PHP, size 54, by Steve Robbins

```
echo(21<<($$$$$$${$aaaabbbbbbehi==$l&$w^2}^1==1));;;;

```

Not the original solution, I think.

# Answer
> 5 votes
# C, es1024, length 70

```
e='C',f;main(g){Chorkil:f=printf("40%.d",e+e-  -g);}hAx;*hotpoCkats();

```

The hard part ended up being to keep track of all the unneeded characters...seriously...I had to redo them about 10 times. The only one that worried me was the `.` but somehow I stuck it in the middle of the `printf` format string and it became invisible!

# Answer
> 5 votes
## Python 3, size 110, by Sp3000

```
import sys,io
u=sys.stdout;sys.stdout=_=io.StringIO()
import this
u.write(" ".join(_.getvalue().split()[::9]))

```

This was a fun one :)

# Answer
> 5 votes
# Haskell, size 34, by Petr Pudlák

```
main=print(0xb2f3d5^0x7f1f27::Int)

```

Note that this program must be run on a 32-bit machine. If you want to check that this is the correct program and you have a 64-bit machine, you can use this instead:

```
import Data.Int
main=print(0xb2f3d5^0x7f1f27::Int32)

```

It was pretty easy to guess the "frame" of the program `main=print(0x<hex digits>^0x<hex digits>::Int)`. All the magic was in searching for the right way to partition and order the digits. I didn't do very much smart here, just a brute-force search... though I did take care to abuse the fact that some digits were duplicated, there were probably about an equal number of digits in the base and exponent, and the last digit of the base almost certainly wasn't even. The complete search code is included below; it uses the multiset-comb package. The full search takes about 10:33 on my machine (and produces only one right answer, of course).

```
{-# LANGUAGE NoMonomorphismRestriction #-}
import Control.Monad
import Data.Int
import Data.List (inits, tails, group)
import Numeric
import Math.Combinatorics.Multiset

main = print (searchFor (-1121766947))

searchFor n = do
    nl <- [6,5,7,4,8,3,9,2,10,1,11]
    (l_, r_)  <- chooseSubbag nl digits
    l <- perms l_
    guard (last l /= '2')
    r <- perms r_
    guard ((fromString l :: Int32) ^ (fromString r :: Integer) == n)
    return (l, r)

chooseSubbag n = chooseSubbag' n . group
chooseSubbag' n xss = go (drop (n-1) (concat xss)) n xss where
    go _  n xss | n < 0 = []
    go _  0 xss = [([],concat xss)]
    go [] n xss = []
    go m  n (xs:xss) = do
        (kx, tx) <- zip (tails xs) (inits xs)
        (k , t ) <- go (drop (length tx) m) (n-length kx) xss
        return (kx++k, tx++t)

digits = "1223577bdfff"
fromString = fst . head . readHex
perms = permutations . fromList

```

# Answer
> 5 votes
# Javascript, 82, by TrungDQ

```
b=/v/[0]+' ';b[0]+b[9]+b[6]+b[7]+'v'+b[7]+((0==0)+b)[1]+b[9]+b[4]+b[5]+b[6]+b[2];

```

Took forever to get the indexes right.

# Answer
> 5 votes
# C, 43 bytes, FryAmTheEggman

Extremely abusive C code; works in the provided tester. Assumes no command-line arguments are passed (which is the default).

```
main(ui,abdenprsx){printf(&"%se7en%"[ui]);}

```

Note that the final `%` doesn't get printed out (at least in the tester provided by the poster and with my local copy of GCC 4.8; Clang refused to compile this code).

# Answer
> 5 votes
# Python, size 41, by Sp3000

```
xx=x=6;exec("x*=6*6;xx*=x;"*xx);print(xx)

```

I racked my brains for half an hour trying to get to `6**49` by some combination of `x*=6`, `x**=6`, and `x*=x`, but there were never enough `*`s. Then I remembered something about squares being the sum of consecutive odd numbers... From there it was easy. ;^)

# Answer
> 5 votes
# CJam, size 34, by Dennis

```
"!,wcoo tkea"Jb" n heyre srwe"Bbma

```

Other solutions:

```
"newk,r !ywsre"Bb" e cto aeho"Jbma
"erwy !tro"Jb" knsecew,ho"Bbma  ea
"rese ohro  cn"Bb"!ew,a yektw"Jbma
"sr  k!oore,"Bb"nyeewtwch"Jbma  ea
"nwetkhs yr "Bb"o!eerc w,"Jbma eao
"!,wcoo tkea"Jb" n heyre srwe"Bbma

```

This is mainly based on Martin Büttner's idea. First assume the solution is either `"..."Jb"..."Bbma` or `"..."Bb"..."Jbma`. Then find some small fractions `p/q` whose tangent value is rounded to that number. Try every `k` and search for a pair of string which can be decoded into `kp` and `kq`. The search program is proven fast in cracking of the previous answer.

At first we have overestimated the probability and started with only two pairs of `p` and `q`. Nothing is found. But finally I changed the program to enumerate all possible `p`s and `q`s, and it worked.

There should be other ways to generate the two numbers other than `kp`, `kq`. But I don't know where to start the search in that case.

# Answer
> 5 votes
# C++, size 192, Arcinde

```
#include<stdio.h>
#define d double
d i7(int y){return y- -1;}d g(d x,int i){return x?x/i- -g(x*i/4/i7(i),i7(i7(i))):x>x;}int (main)(d***dfffgy){printf("%.15f%",7?g(3,1):0,0.,-0.,0,1,2,2,2,4);}

```

I used the series for pi from here for which "history books credit Sir Isaac Newton." After making a short program based on that, the main difficulty I had with using the provided characters was that while I used three additions, I had no `+` available, and was one `-` short of using all double-minuses. I resolved this by creating a function `i7` which subtracts -1 from a number. An unfortunate thing that happened is that I used all the `/` for division, meaning I had a large volume of unused characters to stick in various spots instead of simply commenting them out.

# Answer
> 5 votes
# JavaScript, size 82, by Ismael Miguel

```
var v='',i=0;for(;i<(21<<2)-~1;)v+=i^++i;console.log(v+i)//,.13<<=[[[[]]]]iiijnozz

```

Previous version:

```
var v='',i=0;for(;i<(21<<2)-~1;)v+=i^++i;console.log(v+i);//,.13<<=[[[[]]]]iiijnzz

```

# Answer
> 5 votes
# Marbelous, size 36, es1024

```
9C
Dr=0
^3
+O
+O!!

:Dr
}0
++
/\{>{0

```

There is no trailing line break, so that we remain at 9.

After another very fruitful discussion session with Sp3000, at last, one of the Marbelous submissions is cracked! :)

I can't really explain Marbelous in the scope of this answer, so if you have no idea what I'm talking about, have a look at this reference.

Let's look at the output first: it's 100 ones and zeros, 8 of them at a time (with some offset in the cycle). This suggests that we have some loop that increments a marble 100 times, and printed 0 or 1 depending on the 4th byte. Both of those are pretty convenient because, starting at `9C` (in hex) is 156. Incrementing 100 times overflows, so we can abort the loop with a `=0`. Furthermore, we have access to the fourth bit with `^3`. And if we increment *before* outputting, then we will also correctly start with 3 ones.

Setting this up was a bit trickier though. Especially, since we got really stuck on the idea of naming the board `Or`, so that we would have the `D`s as hex digits (and we also thought there were two `++` devices). But we just couldn't find a way to add 48 to the `0` or `1` resulting from `^3` (which is necessary to turn them into 0 or 1 characters). But at some point I had an epiphany, and realised that `O` is 24 in base 36, so we could actually increment by 48 using `+O` twice.

The rest was fairly simple to deduct from the available characters and the requirement to have no empty cells in the boards. In particular, there is no way to move a marble upwards in this, so the only way to create a loop is horizontally. The clue here was the cylindrical board, which allows you to just constantly push things to the right, until `=0` lets the marble fall. This also meant that the `++` device *had* to go inside the subboard, because you can't prevent it from letting the marble fall.

So in summary:

* `9C` is a literal marble which starts its life at value 156.
* There is a subboard `Dr` which takes in a marble, increments it, and spits out the result both downwards and to the right.
* `=0` lets the result fall if we hit `0`, otherwise pushes it to the right, and back into `Dr`.
* `^3` takes the marble that falls out of `Dr` and returns 0 or 1 depending on the 4th bit.
* `+O` increments by 24 (twice).
* When the result falls off the bottom of the main board, the corresponding ASCII character is printed.
* `!!` terminates execution. This isn't necessary to break the loop (that wouldn't continue anyway), but it swallows the null byte, that would be printed if the `00` marble were allowed to fall off the board. It's important to put the `!!` in the last row, otherwise the final `0` character wouldn't have time to get printed.

# Answer
> 5 votes
# Python 2, size 132, by Vi.

EDIT: Solved the original given that it didn't use `exec` at all. For some reason, even though I came up with using `compile()` to trigger the except in the `from __future__` import instead of `exec()`, I didn't think to use `compile+eval` for the rest.

```
eval(compile('try: compile("from __future__ import braces","1","single")\nexcept SyntaxError as q:\n\tprint q[0][6:]',"2","single"))

```

I'm pretty sure the answer to the hint given "Don't count ones which exist. Count ones which do not exist" is "braces".

How it works: The easter egg import `from __future__ import braces` triggers a `SyntaxError: not a chance`. The idea was to catch this exception and extract the last word from it; but you can't use `try:from __future__ import braces` because `from __future__` imports must occur at the top of the file (this is because they aren't really imports, they're directives to the interpreter at compile-time to enable features). This is why you can trigger the exception by compiling the import without executing it. Additionally, to compile the `try/except` in `single`-statement mode, you need the `\n\t` after the `except`. I'm not sure why this is necessary; it works without the `\n\t` if you use `exec`-mode. Additionally, the `"1"` and `"2"` aren't strictly necessary; those could be left empty.

EDIT: Cracked shorter variant.

```
exec('try:exec("from __future__ import braces")\nexcept SyntaxError as q:print q[0][6:]\t\n12')

```

I'm not sure what to do with the `12\\nt` characters. They didn't seem to fit, but putting them at the end like that works fine.

This works on basically the same idea as the original, but leverages `exec` instead. The second `exec` isn't strictly necessary, though, since all you have to do is compile the import statement.

Personally, I think it would have been a little more interesting to use `StandardError` instead of `SyntaxError`, or perhaps an `import sys;` and `sys.last_value[0][6:]`, but with the dot in there I imagine a whole lot of other solutions would crop up.

# Answer
> 5 votes
## JavaScript, size 69, by Shawn Holzworth

```
f=f=(f=0x76f2156a6c[r='toString'](30))+f+f+' '+((0x25a1335*7)[r](30))

```

That took a while. This should be similar to the original, though the constants are probably different.

# Answer
> 4 votes
# Python 3, size 37 by matsjoyce

```
print(*[_*_ for _ in range(2*2*2+2)])

```

Let's add some more text so that this one doesn't get auto-converted to a comment.

# Answer
> 4 votes
## Python 2, 29 bytes, by Dennis

```
emnsssssyyy= str().strip;ord;

```

Please, good bot, do not convert me to a comment!

# Answer
> 4 votes
# JavaScript, size 26, by hsl

```
alert(998|(103>8>0&41>-0))

```

And some random text to prevent it converted into a comment.

# Answer
> 4 votes
# Python, size 56 by Fox Wilson

```
print("".join([chr((i+70)^32)for i in (2,3,-70,7,9,7)]))

```

# Answer
> 4 votes
## C++, 56, by hosch250

```
int main(){for(int c=33;c<251-124;+4)c+=printf("%c",c);}

```

Note that in order to get this to compile with GCC as a C++ program, I had to tell GCC to include `stdio.h`:

```
$ g++ -include stdio.h -o 40974 40974.cpp
$ ./40974
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

```

The program does compile without `-include` in GCC's C99 mode though:

```
$ gcc -std=c99 -o 40974 40974.c
40974.c: In function ‘main’:
40974.c:1:1: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
 int main(){for(int c=33;c<251-124;+4)c+=printf("%c",c);}
 ^
40974.c:1:41: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
 int main(){for(int c=33;c<251-124;+4)c+=printf("%c",c);}
                                         ^

```

# Answer
> 4 votes
# Pyth, size 35, by FryAmTheEggman

```
llo    oCGd"ProgrammingPuzzesandef"

```

Simply `lg(len("Length 22 string"))`, extra characters disposed of at the front.

# Answer
> 4 votes
## JavaScript, 94, by Shawn Holzworth

```
v=['0',01,7,8,5,7,8,4,44,11,8,41,1,1+1];a=alert;r='';for(x in v)r+=(a+(1==0))[v[x]]||'h';a(r);

```

Works only in SpiderMonkey, it seems (i.e. Firefox). This took me forever, and if it was slightly more clever with the indices I think I'd've given up.

# Answer
> 4 votes
## Python, size 34, by Sp3000

```
print(str([{.6,}])[-4])
_=...;__=_

```

The trickiest part was trying to get rid of the leftover characters. :P

# Answer
> 4 votes
# C, size 48, by es1024

```
main(f){f='ma'-lgamma(0xfe.dp9),printf("%d",f);}

```

I'm very unsure about this one. It depends on implementation defined behavior (character constants with more than one character, see C99 6.4.4.4 point 10), but happens to produce the right result on Linux with gcc and MacOS with clang. Depending on ASCII I wouldn't even mention, but this is so unusual that it feels very dodgy.

# Answer
> 4 votes
# Ruby, size 35, by histocrat

```
(_=->h{:shadily.display})[_]||_===_

```

Interesting, I did not know you could invoke lambdas with `===`... I mean... why?

# Answer
> 4 votes
# CJam, size 19, by Ypnypn

```
923"4593*JJ#%"786*~

```

Test it here.

That was close... the seven days had already passed, by Ypnypn did not yet claim immunity by releasing the original source.

## Explanation

```
923                 "Push 923 on the stack.";
   "         "786*~ "Repeat that string 786 times and eval it. Just a loop, basically.";
    4593*           "Multiply by 4593.";
         JJ#        "J is a variable initialised to 19, so compute 19**19.";
            %       "Modulo.";

```

## Cracking

I was fairly certain that `"_"_*~` was used to make a loop, and that `%` was used as modulo to keep the numbers small. (We've seen other ways to do that, but I don't think that would have worked here very well, because you couldn't put the result of your computation in a string.).

So first guess I ventured was that the divisor of the modulo could be 19<sup>19</sup>. Looking up how much that is, it turned out to be on the same order as the desired result (about 4 times the result), which suggested that this is actually a very likely choice. That left only `*`, so I figured the code would be of the form

```
 _"_*JJ#%"_*

```

Where the `_` are filled from the numbers. That's \*10!/2/2 * binomial(9,2) = 32,659,200\* possible permutations. That seemed to be doable by brute force. :)

The only thing that would blow this up is having a large number before the `*`... with up to 8 digits, it could basically square the number of iterations needed. So I thought, let's limit that to at most 3 digits (which was apprently quite lucky, seeing that solution actually had three digits there). Then I just reimplemented this framework in Mathematica and wrapped it in a loop over all such permutations:

```
perms = Permutations@{2, 3, 3, 4, 5, 6, 7, 8, 9, 9};
big = 19^19;
Map[
  (
    If[#[[2]] != perm[[2]], Print@#];
    perm = #;
    For[i = 2, i <= 9, ++i,
     a = FromDigits[perm[[1 ;; i - 1]]];
     For[j = Max[i + 1, 8], j <= 10, ++j,
      b = FromDigits[perm[[i ;; j - 1]]];
      c = FromDigits[perm[[j ;; 10]]];
      x = a;
      For[k = 0, k < c, ++k,
       x = Mod[x*b, big];
       ];
      If[x == 500827930823087774653348, Print@{a, b, c}]
      ]
     ]
    ) &,
  perms
];

```

After about two hours (shortly before completing the full search) this produced

```
{923,4593,786}

```

which I was able to verify in CJam. :)

# Answer
> 4 votes
# Python 2, size 69, by muddyfish

```
import tabnanny as t;print(t.__name__[:3])or((({3:_efisssw[[]][:]})))

```

`tabnanny` is a standard Python module, but I am just borrowing its name here to get the "tab" string.

# Answer
> 4 votes
# Interactive Python 2.6, 15, MrWonderful

```
43**(314)/(1+2)

```

I did some (imprecise) brute force for `i` and `j` where `math.log(N * j, i)` is very close to an integer.

# Answer
> 3 votes
# Golfscript, size 20, by Josiah Winslow

```
print "hello world!"

```

Tested at http://golfscript.apphb.com/.

# Answer
> 3 votes
# CJam, size 12, by COTO

```
T1mp!+~[]_^oE

```

# Answer
> 3 votes
## PHP, 14, by Tryth

```
aa:a?:a?:a::a;

```

Tested working in PHP 5.5:

```
$ php -nr 'aa:a?:a?:a::a;' | wc -c
0

```

# Answer
> 3 votes
# Java 6+, 101 bytes, by Rodolvertice

```
class ou{public static void main(String[]h){for(int t='l'|'s';t>0;t/=2)System.err.append(t+"4"+t);;}}

```

Outputs to stderr.

**Demo on ideon**

I figure out the pattern of the output quite easily:

```
127 4 127
63 4 63
31 4 31
15 4 15
7 4 7
3 4 3
1 4 1

```

This suggests the tokens `/=2`, `for(;;)`, `t+"4"+t`, `>0`. `for` is taken from `short free;`.

The number 127, the 4 `'` and `|` also suggests the use of `|` with 2 `char`.

The tricky part is to pick out `t` from the rest of the code (`out -> err`, `println -> append`, `class t`, the remaining part of `short free;`).

# Answer
> 3 votes
# Befunge-93, size 17, by user23013

I'm not sure what all that extra stuff on line 2 is doing there...

```
"@",69+#
>_-/*%pv

```

Try it out here

# Answer
> 3 votes
# JavaScript, size 61, by jsh

```
x=function() {return 1;};alert((typeof (typeof x)).slice(-4))
```

# Answer
> 3 votes
# BBC BASIC, 187, by Beta Decay

This just prints out a long sequence of ASCII codes:

```
PRINTCHR$(121)CHR$(111)CHR$(117)CHR$(39)CHR$(108)CHR$(108)CHR$(32)CHR$(110)CHR$(101)CHR$(118)CHR$(101)CHR$(114)CHR$(32)CHR$(99)CHR$(114)CHR$(97)CHR$(99)CHR$(107)CHR$(32)CHR$(109)CHR$(101)

```

# Answer
> 3 votes
# PHP, Size 30, by Tryth

```
__halt_compiler();t101hant.net

```

Just stopping the parser and ignore everything else to have no output.

# Answer
> 3 votes
# Pyth, size 71, by FryAmTheEggman

```
*tC"y"l"Han Solo: Never Tell Me The Odd
-3P0: Sir, the possibii,... s!"

```

There have to be a ridiculous number of possiblities here, but this seemed to be the easiest - get 120 from chr('y')-1, and 31 as the length of a string, and multiply. Newline is a super-comment.

# Answer
> 3 votes
# MATLAB, COTO, size 41

```
disp(magic(all(cos(eye(rank(now))))))

```

# Answer
> 3 votes
# CJam, size 32, by Dennis

```
"tb srcr wB!eyo awm ,kheeonae"Jb

```

Just guess the answer should be something like `"..."Jb` and then brute-forced it.

# Answer
> 3 votes
# PHP, 33, by kenorb

This one was quite easy:

```
<?=strlen(highlight_string(0,1));

```

In case you were wondering, `highlight_string(0,1)` produces this result (with a total of 52 characters):

```
<code><span style="color: #000000">
0</span>
</code>

```

# Answer
> 3 votes
# Bash, size 33, by Debasis

```
echo shellpower|awk '{print $1}'

```

Had to ssh into uni to test that...

# Answer
> 3 votes
# JavaScript, size 10, by Chris

```
{newa:(1)}

```

That was finally solvable...

# Answer
> 3 votes
# SAS, size 17, by user3490

```
%put%eval(a>1>b);

```

Simply evaluates the expression a\>0\>b left to right (giving the results of FALSE, which is represented in SAS by 0) and prints the result to the log.

(Thanks to Sp3000 for noting I originally wrote a\>0\>b.)

# Answer
> 3 votes
# Java, size 70, Rodolvertice

```
enum n{s;public static void main(String[]acl){System.out.print((s));}}

```

I had no idea how `enum`s even worked, with a default `toString()` returning their name in the source code and all, but there were so few non-boilerplate characters available that it was easy to discover.

# Answer
> 3 votes
# Python 2, 16, by imallett

Produces no output in Python 3, but outputs "-2" in Python 2. This technically depends on two's complement arithmetic, which is a reasonable assumption on Python-supporting architectures:

```
eval("\x7eTrue")

```

# Answer
> 3 votes
# Javascript, size 285, by Beta Decay

```
alert(String.fromCharCode(65,90))//      """"""(((((()))))),,,......../////001111222222333334666677777788999:========AEGHJLLLMNORTTX[]_aaaaaaaaaaaaaaaabbbccdddeeeeeeeeeeeeeeeeffffghhhhiiiiiiiijmmmmnnnnnnnnoooooooooooooopppppqrrrrrrrrrrrrrrssssssssssssssstttttttttttttuuuvvvwwwwxz

```

and some newlines after that.

# Answer
> 3 votes
# Ruby, size 33, by Doorknob

```
puts [?\[+?*+?]]-[$?..$\]*$$.next

```

I don't know Ruby and have no idea what does `$?..$\` really mean. Apparently `$?` and `$\` are the only things having the same type (or both undefined?) which will not throw an error.

# Answer
> 3 votes
# Python, size 41, by Sp3000

```
exec("import re\x0Aprint(re.__all__[1])")

```

Fairly sure this is the intended solution.

# Answer
> 3 votes
# Ruby, size 37, by Rodolvertice

```
puts 5423187690^2351479806^1523406978

```

I noticed that the code had exactly three of each digit 0-9, so I guessed the solution would be three numbers that were permutations of 1234567890. Rather than check all of those, I decided to start with numbers of the form 1234500000, xor them, and see if the first 13 bits were correct; if so, then I would fill in the last five digits of each number with a permutation of 67890 and check the final result. The Python 3 script I threw together found this solution within a few seconds.

# Answer
> 3 votes
# C#, size ~600, eshansingh1

```
using System;class Program{static void Main(string[]a){Console.WriteLine("Hello, World!");Console.WriteLine("Other World!");

String c=""+""+""+"wwTxRExpphk=   hckhew@hm.cm hw Csole.Reae how al vod old); ry  statc bool othval try ex) bool retur >catch us Excepton(); } ex) { Excepton(); } { new { { checker) Check(someval); } } catch } Console.rteine(ther } (Exception ystem; usin { finally { catch (Exception new { Console.riteLine(ello @^A-Z0-9._%-@[A-Z0-9.-].[A-Z]{24}$); ain(string[] try Regex.IsMatch(checker, args) static { } } } Exception(Uh rogram bool CopsAndRobbers { oh.);";}}

```

I found a size of 587 rather than the claimed 604, but it hardly matters as it's all dead weight. I wouldn't have done this as I didn't have any interest in installing C#, except that I noticed that I already had a C# SDK on my computer, and it seemed simple enough to figure out how to print a string without needing to look at any documentation. Oddly `string` and `String` both appear to be types.

# Answer
> 3 votes
# QBasic, 42 bytes, by DLosc

```
A=2+EMOORT
1PRINT"QBasic!"
IF A THEN RUN 1

```

There isn't `WHILE`, `NEXT`, `DO`, `GOTO`, `GOSUB` or `CALL`, and there isn't a second `PRINT` or other ways to get a new line. So I must find some other weird control structures.

# Answer
> 3 votes
# JavaScript, 29, by Joe

```
[,,].join([,,,].join(3))|74*2

```

Probably not unique, because I didn't really use one `join`.

So the idea was to somehow find the number with repetition of digits, multiplication and bitwise or. All of those operations increase the resulting number, so I could limit my search to numbers below `181`. Conveniently `181` is prime, so the final operation had to be `|` (I doubted I could get to `[1,1].join(8)`). So I just looked at all pairs of numbers that I could bit-or to 181, and looked through those that have at least one operand completely from the available digits. One way is `33|148`, and the latter could be found as the product of `74` and `2`, so here we are.

# Answer
> 3 votes
## JavaScript, 46 characters, by FireFly

```
alert(/ordered/.source)
this.    aaeeefnnrstvw

```

# Answer
> 3 votes
# JavaScript, size 28, by Shawn Holzworth

```
var eeivy;((atob['length']))

```

~~I guess, that's not what we were looking for...~~ Turns out it's exactly the original. :)

# Answer
> 3 votes
# C, 44, Art

```
n;main(aaa){while(1-printf(&"a%nb"[n],&n));}

```

Lacking any assignment operators to use for flow control, it seemed a good idea to look for some function which would take an address and write something to it. I found a `%n` specifier for `printf` which does this. I think this was the intended general idea. I had to test on ideone because there was some bug in the implementation on my computer where it refuses to write anything after a `%n`... Something to do with this maybe.

# Answer
> 3 votes
# JavaScript, 42, by Shawn Holzworth

```
(function nn(n){return !n||n+nn(--n)})(58)

```

And to test it :

```
alert((function nn(n){return !n||n+nn(--n)})(58))
```

# Answer
> 3 votes
# Java, 134, Olavi Mustanoja

```
class Shit{public static void main(String[]rtr){for(int n=74;n<=84<<19;n=n<<3^911-'g')System.out.print(""+(char)94+n+(char)(5<<1));;}}

```

At the beginning I checked the logarithms of the numbers and noticed that the later ones differed by almost exactly 3 log 2. Then it was easy to find that excluding the first number, the next could be obtained by `(n << 3) - 728`. Instead of the subtraction, an xor operation can give the next number for all of them.

# Answer
> 3 votes
## JavaScript, size 73, by Mig

```
alert([o=(eval.e+'(((()))),-....0cceefgillpprrrssst')[2],o].join('enie'))

```

Thanks for the string literal to dump all the excess characters in! I'm pretty sure this is an unintended solution, but it seems to work nonetheless.

# Answer
> 3 votes
# Marbelous, 48, by es1024

```
@110&1
@0@111
@011..
\/=0..

:.-
}0}0}0
{0&0-0<<

```

So what's the challenge?

# Answer
> 3 votes
# Marbelous, 55, by es1024

```
1111
11<<
10/\
10
10
&0..&0

:--.....01=@@@@}}
{0}00000

```

# Answer
> 3 votes
# Python 2, 13 by Emil

```
print (070-7)

```

I'm not sure either why Python has octal literals. Ruby has them too, I was thinking of including one in a puzzle myself.

# Answer
> 2 votes
# CoffeeScript, size 25, by Martin Büttner

```
alert /hees  /.test []

```

Try it out at http://jsfiddle.net/33qa3guk/.

# Answer
> 2 votes
# JavaScript, size 13, by Caridorc

```
{}-[]+[]+([])

```

I'm not sure though if the cop's submission is valid, because it requires a REPL environment.

# Answer
> 2 votes
# CJam, size 18, by Ypnypn

```
987"12268*"0*~543%

```

Probably not the original solution.

# Answer
> 2 votes
# Python, size 154, by Fox Wilson

```
print("".join(chr(int(130-o))for o in [51%35,13,ord("         (()),..////00188==[]________aaccddeeeeffffgiiiiiiiiijjjjllnnnoopprrrrttuu"[1]),sum([8,1])]))

```

This is almost certainly not the intended solution.

# Answer
> 2 votes
# Python, size 54, by kgull

```
'head'#(o)op'/r),2\x'12.)w/)],c'dp*((rx:(h('r'ol'e)[re

```

This most likely is not the intended answer, but it works; the `#` comments out everything but the result. The OP stated that this is supposed to be run in a shell, so there is no `print` statement.

# Answer
> 2 votes
# Perl *5*, size 47, by chilemagic

```
print((0..$])x$]); ""."$$$$()**.///[[~==1fors";

```

I think this is valid. The `$]` part took me a while.

# Answer
> 2 votes
# Python, size 48, by kgull

```
print('h'+hex(ord('\r')*pow(ord('#')//2,2))[2:])

```

# Answer
> 2 votes
# PHP, size 22, by kenorb

```
echo(1.*0+(int)(7.1));

```

Or something like that... it's not really unique.

# Answer
> 2 votes
# Python 2, size 38, by FryAmTheEggMan

```
print(`[].__iter__`[::2].split()[-~1])

```

Taking letters from `object at`.

# Answer
> 2 votes
# C - 43, by Allbeert

This solution really `,sux`, but it does actually work if you ignore the grumbling from gcc:

```
main(){printf(&__DATE__[10],1+1+1+',sux');}

```

(It will stop working in a few weeks, however...)

# Answer
> 2 votes
# PHP, size 23, by bwoebi

```
echo@$c=b,$b.$$c=$c.$c;

```

I'm confused by why `echo@$$c=b,$$c.$$cc.=b;` doesn't work, while calling `echo@$$c=b,${""}.$$cc.=b;` directly does.

# Answer
> 2 votes
# Ruby - 58, by Rodolvertice

There are probably lots of solutions to this one.

```
puts 0x7d556657^0x3ffd88f9^0x1221442e^0xdd48ad1^0x08c58a00

```

# Answer
> 2 votes
## Perl, size 39, by GentlePurpleRain

```
$_=(~0);s/(\d\d)/ge_$2/;print$_=chr$1*4

```

With help from chilemagic.

# Answer
> 2 votes
# JavaScript, length 32, by hsl

Interesting use of the `map()` function there:

```
[atob('cHVHaVht')].map(alert)//+

```

# Answer
> 2 votes
# JavaScript, size 47, by palerdot

```
alert("a surprise!")//if("est")(it will tell  )
```

This was super easy though. There can be so many solutions to this too.

# Answer
> 2 votes
# PHP, size 44, by kenorb

```
$_=get_class_methods(@new phar);die($_[70]);

```

IMO, that one was pretty obvious (took me 10 minutes after first look).

I did a quick google search and observed that there were a lot of class having valid() as method... An coincidentally `get_Class_methods()` was in the string. After extracting that one, no issues anymore.

# Answer
> 2 votes
# C, size 30, Ethiraric

```
main(){printf("%d",__LINE__);}

```

# Answer
> 2 votes
# CJam, size 19, by Martin Büttner

```
"hunt !tacos" 'hiCt

```

This one seemed easy...

# Answer
> 2 votes
## PHP, 21, by kenorb

This one is easy if you know that one of the new features in PHP 5.6 (the version of PHP the code was tested in) is a `**` operator for exponentiation:

```
<?=27**5;///***134689

```

Or alternatively:

```
<?=3**15;///***246789

```

# Answer
> 2 votes
# C, size 39, imallett

```
_;main(){putchar(_^'_');_++<9&&main();}

```

# Answer
> 2 votes
# Little Man Computer, size 63, The Wolf

```
503902000051000000000001111122223334455555666777888999999999999

```

If I'm understanding this correctly, all I have to do is put the number in the out box and then halt? OK...

# Answer
> 2 votes
# Haskell, size 42, by proud haskeller

```
{data S=S{}deriving Show;main=print S;S=S}

```

Some clever things were done here: the empty record in the definition of `S` to reduce the number of spaces (this confused me a long time!), and it looked awful hard to use that extra equals sign from the extraneous `S=S` equation.

# Answer
> 2 votes
# Lua, size 28, by ChipperNickel

```
a=math print(a.asin(1)*a.pi)

```

Wow, this was actually really simple, why did I not try this earlier? Also, I learned that you can separate statements with nothing but a space in Lua.

# Answer
> 2 votes
# Mathematica, size 18, by Arcinde

```
D[2#&@d!!,d]/.d->0

```

That was quite interesting. :)

# Answer
> 2 votes
# Ruby, 49, by Doorknob

```
$><<"'"+'
""'

%''
%''
%"'<<<<<<<<>>>>>>>>>% ?;"

```

I think I found a tiny shortcut?

# Answer
> 2 votes
# Python (2), size 41, muddyfish

```
print(sum(map(ord,repr(exit.__repr__))))

```

I observed the result `6831` from this code for both Pythons 2 and 3 on my local machine. However, I managed to reproduce the output `6314` with (http://ideone.com/700qVt). Ideone's Python 3 didn't even recognize the `exit` function.

# Answer
> 2 votes
## C, size 53, by FireFly

```
s(x){return x?x*s(~-x):!x;}main(){printf("%x",s(9));}

```

Nice factorial program :)

# Answer
> 2 votes
# Arithmetic, size 31, by Cris

```
(((((2*2+1)*2+1))*(1+(1+2)*2)))

```

This may not have been the intended solution because of the unused parentheses, or maybe they were red herring.

# Answer
> 2 votes
# Cris, ECMAScript, 66

```
eval(atob("J2slzzuuuspmlkihgccbbbaZZYYWSSKKKED995555222S2AnCjsx"))

```

...

# Cris, ECMAScript, 70

```
eval(atob("DScg12224599ACDDMMNNNOQQTTYZZbcgjklmpssuuuwwyzzzOScKMSY1"))

```

......

# Answer
> 2 votes
# Python 2, muddyfish, 37

```
print(memoryview(str(Ellipsis)).ndim)

```

I'm glad I made that Python builtins anagrammer.

# Answer
> 2 votes
# Java, 108, durron597

```
class o{{ }public static void main(String...r){System.out.printf("%.6f",('a'*'+'/'\t'-'l')/('m'+'\n'-6.));}}

```

This was my second pi-printing program today. Given the low precision of this one, the second-most famous rational approximation, namely 355/113, was sufficient to produce the correct digits. It seemed like this fraction should be obtainable with some math on character literals. After some trial and error I finally found an expression `('a'*'+'/'\t'-'l')/('m'+'\n'-6.)` which used all the characters it needed to. One convenient thing was that I had the choice between `printf` or `format` which both behave identically here.

# Answer
> 2 votes
## QBasic, 37 bytes, by DLosc

```
PRINT 1E7 AND 11053811

R=LEN("*?RY")

```

I immediately noticed that all the letters of `AND` were present in the code. (In QBasic, the Boolean operators are bitwise, and true is `-1`.) Then I wrote a script to find possible combinations of operands by brute force, ignoring zeros to allow for E notation. Once I found a usable combination in the list, all that was left was to deal with the remaining characters.

A single space is printed before the number (where the minus sign would go for a negative number). The scrambled code also prints a space before the number it prints, and that is not described as part of its output, so I assume that that detail is insignificant or was mistakenly omitted.

# Answer
> 2 votes
# PHP, size 46, by Ismael Miguel

```
$i=az;echo++$i,nd;$i[((E<<H)<=$m&oorrYYz)^$f];

```

Quite sure this isn't the intended solution.

Turning off notices is recommended for running this.

`$i` is first set to `az`, then incremented, which yields `ba`.

`echo` can take a list of strings to print; here it prints `$i`(`ba`), and then `nd`.

The rest of the code (`$i[((E<<H)<=$m&oorrYYz)^$f];`) does nothing.

# Answer
> 2 votes
# Python, size 55, by FireFly

```
____acdfiimmnooprrt={2:.9,}
print(801**sum(range(5))+1)

```

The funny thing is, my initial solution only worked on Python 3 and it was only until FireFly pointed out that I should inline my `801**sum(range(5))` instead of assigning it to a variable that I got this working for both Python versions.

# Answer
> 2 votes
# Java, Size 97, Olavi Mustanoja

```
class _{public static void main(String[]s){for(int b:"534g".getBytes())System.out.write(b^'m');}}

```

There are not too many possibilities with only 1 character `^` usable as operator and lack of `p` (for printing operation).

I wither the input down to `345_gsm` and do some math to map it to the output.

# Answer
> 2 votes
# Ruby, 23 by MegaTom

```
p %++.methods[80][1..-1]

```

Edit: So that's where the answer went. Converting back to an answer, hopefully. Thanks for specifying an interpreter, `methods[80]` is definitely version- and implementation- dependent. Using `+` for the percent-string delimiter is a nice touch.

I think I found this easier than I would've just because I'd been thinking of doing some similar tricks.

# Answer
> 2 votes
# Ruby, size 17, by Stephen Touset

```
$><<$-W?$?:$:>-pi

```

Test it on ideone.

Most certainly not the original code. `$-W` is the value of the command-line argument `-W` (warning level) which defaults to `1`. The rest is just to get rid of the other characters, so I'm putting some undefined variables and operators in the else branch of a ternary.

# Answer
> 2 votes
# Python, 37, MrWonderful

```
print 4123.*3
" +++3:==deefinorsuu"

```

Probably not intended solution, but this solution is so obvious that I can't help.

Python 2 assumed.

# Answer
> 2 votes
## J, 25, Caridorc

```
echo 3%##++-/-/i.!/i.3345

```

There has to be many ways of getting rid of the extra characters...

# Answer
> 2 votes
# C, 19, by Olavi Mustanoja

```
int main;retunr(){}

```

# Answer
> 2 votes
# C - size 33, by Olavi Mustanoja

```
#define p 2+57
main(){return p*p;}

```

Returns 2 + (57\*2) + 57 = 173

# Answer
> 2 votes
# Javascript, 35 (36?), by user3863227

Too easy. After I took out `Math` and `alert`, `log` was the only option.

```
l=Math.log;alert(l(l(l(1234))));1279

```

(By the way, I counted 36 characters, not 35.)

# Answer
> 2 votes
# JavaScript, 10, by Jamie Barker

```
btoa(self)

```

There weren't that many options...

# Answer
> 1 votes
# Mathematica, size 29, by Fox Wilson

```
$PrePrint=Function[{x},5];
2+2

```

Learned something new today! :) (`$PrePrint`)

# Answer
> 1 votes
# Lua, size 18, by user3155415

```
print(3<math.huge)

```

I actually haven't tested this, but it should work.

# Answer
> 1 votes
# Python, size 68, by horns

```
o=ord;print(chr(35),o('{'),o("-"),o("C"),o("Y"),sep="")#''''"02blpst

```

I *think* I've got the characters right. Either way, if I miscounted the number of quotes, the rest go after the comment (consulting the ASCII table helped).

# Answer
> 1 votes
# CJam, size 52, by user23013

```
33,33,33f+:cm*33)%",,,:::')@\&++++3333333333cfffff";

```

Test it here.

Thanks for providing `"...";`. ;)

# Answer
> 1 votes
# PHP, size 13, by kenorb

```
@die(_(abc));

```

~~I have no idea what `_(...)` does.~~ Now I do.

# Answer
> 1 votes
# Python 2, size 57, by FryAmTheEggman

```
print''.join(map(chr,(40+58,90+4+10+0b100,113+4,101++0)))

```

The `++` is a lazy way to get rid of a `+`.

# Answer
> 1 votes
# PHP, size 27, by kenorb

```
$_=hex2bin(7069);die($_());

```

(`hex2bin(7069)` evaluates to `"pi"` which is then called)

# Answer
> 1 votes
# Mathematica, size 35, by Tally

```
$PrePrint=$Pre=e=p=esPrint&''    ;a

```

Definitely not unique. Basically, I'm creating a constant function, take the second derivative (which is a constant-0 function) and make sure that function is applied to any expression that is evaluated or printed. Then I evaluate `a`.

# Answer
> 1 votes
# Brainfuck, size 118, Sp3000

```
+++[->++++<]>[->+++[->>+++>+>++>+>+++>++>+[<]<]>>>>+>+>+>+<<<<<<<<]>>>+++++>>++>++++>+[>]+++[-<-<->>]<[<]>[.>]<<<++++>

```

Brainfuck is really not so bad, as long as it's not golfed too much. Since the alphabet is so limited, you can write whatever program you want as long as it's shorter than the original, and then make slight adjustments to balance the symbol counts.

# Answer
> 1 votes
# JavaScript, size 25, by Cris

```
alert.apply(self,[alert])

```

# Answer
> 1 votes
# JavaScript, size 29, by Cris

```
new Event("flushPs15").CHANGE

```

Works in the console.

# Answer
> 1 votes
# C, size 28, Mig

```
main(s){s=2189640;puts(&s);}

```

Depends on the endianness of the system.

# Answer
> 1 votes
# JavaScript, size 26, by Cris

```
eval("new function $(){}")

```

Tested in Chrome's console.

# Answer
> 1 votes
# Python 3, size 46, hosch250

```
(print("'(otlotb)'")
==
'bffiilnnoopprrrr01*')

```

I don't think the idea is to let me simply print the output string in a plain literal...

# Answer
> 1 votes
# Java, size 226, nhhhhtdh

```
enum
u{u;public
static
void
main(String...a){
System.out.print(0x17+68+"\u0020\125nmatched closing \u0027)\u0027u\"((()),.00008;DEIPP\\aaaaaaaacccceeeeeeeeefgiiijlnnooppprrrrrsstttttttttuuuvxyyz{{}}".split(u.toString())[0]);}}

```

A quick search revealed that it was easy to generate a `PatternSyntaxException` with the message `Unmatched closing ')'`, but it proved to be unnecessary as the abundance of backslashes, `u`s and digits allowed me to create any character I didn't have via escapes.

# Answer
> 1 votes
# Python 2, size 89, Beta Decay

```
   ''''''''((()))*,,,,...12;;=BFGGIIIILPRaaaaaabceeeeeeffgggggiiiiiklmmmmmmnnoopprrrsttvw

```

Really I would recommend to output something........

# Answer
> 1 votes
# JavaScript, size 30, by Qwertiy

```
with(Math)alert(max^min)

```

Interesting use for `with`. :)

# Answer
> 1 votes
# JavaScript, 41 bytes, by Ismael Miguel

```
(function(){return this})('ccnoorrsttu.')

```

Tested in Chrome's console.

# Answer
> 1 votes
# PHP, size 80, by Ismael Miguel

```
priNt(a^Z^P^Q);$A^=$A^=$C+=$F.=($I^$I^$O<$PTTUWWXX______________aaabffjkory);;;;

```

There are many ways to get a short output like `:`.

# Answer
> 1 votes
# QBasic, 43 bytes, by DLosc

```
DATA?
DIM P AS STRING
READ P
?P;P;CEEEEH36$

```

# Answer
> 1 votes
# ECMAScript, 90 bytes, by Cris

```
(function(t){t.n=t;t.n(t.n.FFFbcdeehhiiiinooopprrrsstuuy)}) ((function(){alert(this+"")}))

```

The original solution is probably (based on Martin Büttner's work in the chat):

```
Function.prototype.F=function(){return this.bind(this)()};(function(){alert(this+"")}).F()

```

# Answer
> 1 votes
# PHP, 33 bytes, by Ismael Miguel

```
echo  0X1^BXcdeilnu08DFHTTTgk467;

```

Tested on ideone.

This might actually also work on Windows. All it does is `xor` a hexadecimal `1` with an undefined constant which yields `0`.

For the Windows one you can use

```
echo  7^'6cdeilnudBXX4';

```

which should also work on both platforms, because the string is simply coerced into an integer (being `6`), and then we xor that with `7`.

I'm curious what those were supposed to be.

# Answer
> 1 votes
# QBasic, 79 bytes, by DLosc

```
print"Iodine"
if f then scReen         BLaaabbefgghhhiiiiiiiikkllnnossstt,u-u.u

```

# Answer
> 1 votes
# Python, 60, f.rodrigues

This post was so bad it had to be stopped.

```
print(60132)

4 or((odad95oamamarrdsn,nn.m7dtit.rminnrope8ed))

```

# Answer
> 1 votes
# Bash, 47, Vi.

If you saw a $100 bill lying on the ground, wouldn't you pick it up?

Don't know much about bash, but I tested it and it works.

```
printf pp;o='${cel-sr(xe\     pp/pp/) fec1/; }'

```

# Answer
> 1 votes
# DC, 28 bytes, by MichaelT

```
[ls+dn11ls1+dss<n]sn1ss0lnx

```

But I counted 27 bytes. Maybe there is a newline...

# Answer
> 1 votes
# CJam, 51, by Optimizer

```
"JamesBdo,"YZ+/)BA*c+Y*Y%:BS@SB)))[JW:Z____)ci+*]U*

```

# Answer
> 1 votes
# Python, 45, by muddyfish

```
print(eval((chr(32)+chr(45)).join(str(413))))

```

Interesting idea, I have to say. Wasn't hard to brute force though.

# Answer
> 1 votes
## Brainfuck, 39, by Mig

```
+++++++[->++++++<]>[->++<]>-.----.++++.

```

# Answer
> 1 votes
# Python shell, size 15, xnor

```
1215954^1548696

```

Obtained by brute force in 1.42 seconds.

Code used to find solution:

```
#include <iostream>
#include <algorithm>

int main(){
    int digits[] = {1,1,1,2,4,4,5,5,5,6,6,8,9,9};
    int ndigits = sizeof(digits)/sizeof(digits[0]);

    do{
        int n1 = 0, n2 = 0;
        for(int i = 0; i < ndigits - 1; ++i){
            n1 = (n1 * 10) + digits[i];
            n2 = 0;
            for(int j = i+1; j < ndigits; ++j)
                n2 = (n2 * 10) + digits[j];
            if((n1 ^ n2) == 339018){
                std::cout << n1 << ' ' << n2 << std::endl;
                return 0;
            }
        }
    }while(std::next_permutation(&digits[0], &digits[ndigits]));
}

```

# Answer
> 1 votes
# Python shell, size 21, xnor

```
6446781078^9350512293

```

Obtained by brute force in ~27 minutes.

Code used:

```
#include <iostream>
#include <cinttypes>
#include <cmath>

inline bool check(int64_t a, int64_t b){
    int used[10] = {};
    do{
        auto r = std::div(a,10ll);
        ++used[r.rem];
        a = r.quot;
    }while(a);
    do{
        auto r = std::div(b,10ll);
        ++used[r.rem];
        b = r.quot;
    }while(b);
    if(used[0] > 2) return false;
    for(int i = 1; i < 10; ++i)
        if(used[i] != 2)
            return false;
    return true;
}

int main(int argc, char **argv){
    int64_t i = 1ll << 32;
    while(!check(i,i ^ 15788895283ll)) ++i;
    std::cout << i << ' ' << (i^15788895283ll) << std::endl;
}

```

This checks every integer starting from 2^32 until it and its matching integer use up all the characters provided.

# Answer
> 1 votes
# C++, 244 bytes, by Gabe Evans

```
#include<iostream>
int main(){int(CCDD)='%';char(a)[14]={'h','e','l','l','o',22+20/2,'w','o','r','l','d','!'};CCDD+=CCDD<=a[0];{{}};aa:adffillllllnnnnnnnnnnnnooooooooooooorrrrrrrrrssstttttttttttttttuuuuuuuuuuuuwwwwww:cout<<a;}

```

It was a bit of a struggle getting all those spare characters out of the way. You can see the code working here.

# Answer
> 1 votes
# Insomnia, 14, by n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

```
e9-i|yig9s pre

```

# Answer
> 1 votes
# C, size 62, by Olavi Mustanoja

```
#include<stdio.h>
#define _ +8
int*main(){printf("%d",1 _ _);}

```

# Answer
> 1 votes
# Python, 28, by user3863227

```
print(int(bin(1234)[2:])**2)

```

Factorizing the output gave this one away quite easily:

```
100220321420320200100 = 2² × 5² × 457² × 2190593²
sqrt(100220321420320200100) = 10011010010
int('10011010010',2) = 1234

```

# Answer
> 1 votes
Perl - 26 bytes by primo

```
f:print po=>glob q$t{a,o}$

```

The `q` was easy to recognise. I took the `potato` letters away and shuffled the rest to discover `glob` suddenly. Then, I realised `$$` will be used instead of `{}` and that `=>` can be created. The last thing was `f:`, it took me a while to think of a label.

# Answer
> 1 votes
# CJam, 14, by User23013

```
92e8.17 5e6.3%

```

I started by making some assumptions: that the exponent in each case was a floating point number, and that it had at least one digit after the dot (otherwise it's just the same as using an integer) and one or two before it (otherwise the result would be too small or too large). Then I used Python's `itertools` library to do some permutations. I got a result in under a minute.

Here's my cracking code:

```
from itertools import permutations
target = 108183.05975155532

def e(mantissa, exponent):
    return mantissa * 10 ** exponent

def ePartition(digits):
    """Generator function: gives every way to partition digits into an
    integer mantissa and a floating point exponent that is > 1 and < 100."""
    for eIndex in range(1, len(digits) - 1):
        for dotIndex in range(eIndex + 1, min(len(digits), eIndex + 3)):
            yield (digits[:eIndex],
                   digits[eIndex:dotIndex] + "." + digits[dotIndex:])

for p in permutations("12356789"):
    for spIndex in range(3,6):
        digList1 = "".join(p[:spIndex])
        digList2 = "".join(p[spIndex:])
        for mant1, expt1 in ePartition(digList1):
            for mant2, expt2 in ePartition(digList2):
                value = eval("e(%s,%s)%%e(%s,%s)" % (mant1,
                                                     expt1,
                                                     mant2,
                                                     expt2))
                if value == target:
                    print("%se%s %se%s%% -> %s" % (mant1,
                                                   expt1,
                                                   mant2,
                                                   expt2,
                                                   value))

```

# Answer
> 1 votes
# JavaScript, 36, by MegaTom

```
x=alert;x(("x"+x)["substring"](6,9))

```

Tested in Chrome's console.

# Answer
> 1 votes
# Python 2, 13, by mbomb007

```
71e0//36/0x92

```

The output is `0.00684931506849315` on my machine. But it worked on http://repl.it/.

# Answer
> 1 votes
# Python, 39 bytes, Reticality

```
print("{0}{2}{1}{1}{1}".format(0,5,6,))

```

You could also swap the {0} & {2} and the 0 and 6.

# Answer
> 1 votes
# JavaScript, 15, by Jamie Barker

```
Math.sin(1)+'O'

```

EZ PZ, as you said. ;)

# Answer
> 1 votes
# Python, 13 bytes, by Reticality

To be run on an interactive Python console:

```
len("printi")

```

Outputs `6`.

# Answer
> 1 votes
# CMD, 9, by unclemeat

```
set/a!!!0

```

There are too few possibilities here. The 4 alphabet characters are most likely command name, so I attack in that direction.

# Answer
> 0 votes
# Bash, size 23, by The Wolf

```
q=echo;_(){ $q $q;};""_

```

I think the original solution (or red herring) should be:

```
q(){ q=;};q ""echo;$_ $_

```

which is invalid because it has one more space character.

# Answer
> 0 votes
# C, size 63, es1024

```
main(_){int __=_;_<<=_;__=_<<_<<__;printf("%d",_<<__|__);_|__;}

```

What I'm trying to get is `2 << 16 | 16`. Three leftover underscores, woohoo.

# Answer
> 0 votes
# Rust, size 123, by Vi.

```
fn x(r:int)->int{for i in range(0,2){if i==r/r{{}}else if i==0{}}r%222*912}fn main(){print!("{}",x(993+2))}

```

This shouldn't be the intended solution because of the no-op `for` loop, but it produces no warning in play-pen anyway.

(I'll leave the Clojure part for others.)

# Answer
> 0 votes
# PHP, 62, aks.

```
for($i=1;$i<3.;)echo"$i. ".((($i++==2))?'Tues':'Mon').'day ';

```

Quite easy compared to other crazy PHP submissions.

# Answer
> 0 votes
# JavaScript, 24 bytes (by fogcityben)

```
'.+';console.log( 'hi' )

```

Not sure what he really did with that `.` and `+`.

# Answer
> 0 votes
# Python 3, 21 bytes, Reticality

```
print(str(...)[4::2])

```

Prints the `p` and final `i` from `Ellipsis`.

# Answer
> 0 votes
# Python, size 26, by Oliver

```
print 2 * 3 * 37037,
print

```

The 2 `print`s threw me off a bit.

# Answer
> 0 votes
# Python 2, Oliver

```
r =int= 2**2**2*2**2**2*2**2**2**2*2**2*2**2*2**2*2**2*2**2*2
print 16777216,

```

**Demo on ideone**

There is nothing tricky here. All the numbers are there, only need some rearrangement to comply with the syntax.

You can pipe the output to `xxd` to see that it has a trailing new line:

```
$ python -c 'r =int= 2**2**2*2**2**2*2**2**2**2*2**2*2**2*2**2*2**2*2**2*2;print 16777216,' | xxd
0000000: 3136 3737 3732 3136 0a                   16777216.

```

# Answer
> 0 votes
# CMD, 21, by unclemeat

```
set /a!!"echo>>tfile"

```

Repeating the `set /a` trick and `!` operator is reducing the search space for otherwise a tough nut to crack.

I'm not too sure how `set /a` works, but when I evaluate `set /a "tfile"`, it returns `0`. Not sure if all strings evaluates to 0, but in this case, we end up evaluating `(!!0) >> 0`, which is `0`.

# Answer
> 0 votes
# Python, size 15, by mbomb007

There are at least 5 permutations that work. This is one of them:

```
`3*.7/50`[::~4]

```

It was pretty obvious that the original code was something of the form ``«expression»`[«range»]`, so it wasn't difficult to place the backticks, colons and square brackets. On a hunch, I assumed that the range specifier was `[::~i]` for some value of `i`, leaving only 8 characters to permute. This took only a fraction of a second. Here's the code I used:

```
from itertools import permutations

perms = [''.join(p) for p in permutations('03457*./')]
for p in perms:
    try:
        e = '`'+p[:-1]+'`[::~'+p[-1:]+']'
        if eval(e)=='6991':
            print e
    except:
        continue

```

(The original code is actually a bit flakey, since the result of `3*.7/50` isn't guaranteed to be `0.041999999999999996` all of the time.)

# Answer
> 0 votes
# Python, size 30, by mbomb007

Didn't need much unscrambling:

```
' rsin[~(ddf) 0]rot13'[9+6: :]

```

# Answer
> 0 votes
# Python 2, Oliver

```
rt =in= 2**2**2*2**2**2*2**2**2**2*2**2*2**2*2**2*2**2*2**2*2,
print 16777216

```

All actual credit to n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ with this solution. I just stole it and corrected it.

---
Tags: cops-and-robbers
---


title: Logical Dot Shapes

text:
# Question
Title: Logical Dot Shapes
### The Game

Recently, much of my time has been taken up by an addicting game on my phone, called Logic Dots, which inspired me to write this challenge. It's easier to explain the rules if I show you the game display, so here is a screenshot of an unsolved, and solved puzzle:

Now here, there are three main things to notice.

1. The game board (the 4x4 grid of squares in the center)
2. The required shapes (the linked dots in the second bar from the top, under the score and menu, etc.), which are all lines, or `a` by 1 rectangles
3. The numbers over the rows and columns, which denotes how many dots need to be in the column, for a solution

The objective of the game is to fit the required shapes into the grid. You can rotate the shapes, but they cannot go in diagonally.

In the solution, notice that all shapes are created exactly once (because they are only in the required shapes once), and in this case they are all horizontal but they can also be vertical. The pink filled in squares denote squares not used.

Here is a bigger, and slightly more complicated grid:

Notice that in the unsolved puzzle, there are already a few squares filled i.n The greyed out squares signify blocked squares that you **CANNOT** place a dot on. The dots with tails tell you that a dot is in that spot, and it links to **at least** one more dot in the direction of the tail, but not in any other direction (including the opposite direction).

### Notation

For the rest of this post, I will refer to the board using the following symbols:

* **\<, \>, ^, v -** Signifies a pre-placed dot with a tail extending in the direction of the point
* *** -** Signifies a dot. If given on an unsolved grid (input), it is an individual shape. If in output, then it is connected to the dots around it.
* **\# -** Signifies a blocked grid square (where you cannot place a dot)
* **-, | (hyphen and bar) -** Signify a dot with a right and left tail, and a dot with an up and down tail respectively
* \** (space character) -\** Signifies an empty space

Using these symbols, the latter example case (unsolved) can be represented as follows:

```
 <

    #
 ^ #

```

And the solution can be represented as:

```
*< * *
   *
     *
 *   *
 * *#*
 ^ # *

```

Note that no two shapes can touch horizontally, vertically **or diagonally**, so the following case is not valid:

```
 ***
**
  **

```

## Challenge

Your challenge is to solve any logic dots puzzle, from 4x4 to 9x9 inclusive. You will receive four lines of input, then the game board. The lines will be as follows:

* 1st line, Shapes - The shapes to find, each given in the form `sizexquantity` (eg. `3x2` for two shapes of length three) and separated by a space. Example line: `3x1 2x1 1x1`
* 2nd line, Columns - A space separated list of the required dot count for each column. Example line: `1 1 2 2`
* 3rd line, Rows- A space separated list of the required dot count for each row. Example line: `3 0 3 0`
* 4th line, Board size - A single integer, the board size, `B`

The board is then given, and is `B` lines of input representing the board using the notation mentioned above. For example, the complete input for the latter example case is as follows:

```
4x1 3x1 2x2 1x2
1 4 0 3 0 5
4 1 1 2 3 2
6
 <

    #
 ^ #

```

Your program will then output the solved board, in the same notation. The matching output for the above input is as follows:

```
** * *
   *
     *
 *   *
 * *#*
 * # *

```

Note that a game board can have multiple solutions. In this case, just output one valid solution. Also, your program must output a correct solution within 10 seconds on a reasonable desktop computer for a complicated 10x10 grid.

This is code golf, so least bytes wins.

---

# Test Cases

**Input 1**

```
3x2 1x4
2 2 3 1 2
4 0 3 0 3
5

    #
  #
    *

```

**Output 1**

```
*** *

 ***#
  #
* * *

```

**Input 2**

```
3x1 1x6
2 0 4 0 3
3 1 2 1 2
5
*

   #

```

**Output 2**

```
* * *
  *
  * *
*  #
  * *

```

**Input 3**

```
5x1 4x1 2x1 1x2
1 2 3 3 2 2
0 5 0 4 0 4
6
#
  -

 #
   <

```

**Output 3**

```
#
 *****

 ****
 #
* ** *

```

# Answer
# Python 2: ~~766~~ ~~739~~ ~~696~~ ~~663~~ 633 bytes

```
def f(B,S,o=0):
 if[]==S:print'\n'.join(B);exit()
 s=S[0]
 for i in r:
  for j in R(Z-s+1):
   if(B[i][j]in' '+'>v'[o])*(B[i][j+s-1]in' '+'<^'[o])*({' ','-|'[o]}>=set(B[i][j+1:j+s-1]))*all(B[x][y]in'# 'for x,y in [(x,y)for y in R(j-1,j+s+1)for x in i-1,i+1]+[(i,j-1),(i,j+s)]if 0<=x<Z>y>=0):q=B[:];q[i]=q[i][:j]+'*'*s+q[i][j+s:];q=(q,t(q))[o];any((t(q)+q)[k].count('*')>m[k]for k in R(Z+Z))or f(q,S[1:])
 o or f(t(B),S,1)
y=raw_input;S=[];s=str.split
for i in s(y()):u,v=map(int,s(i,'x'));S+=[u]*v
m=map(int,s(y())+s(y()));Z=input();R=range;r=R(Z);B=[y()for _ in r];J=''.join;t=lambda x:map(J,zip(*x))
f(B,S[:len(S)-J(B).count('*')])

```

See it working online: Ideone.com (The online version may be too slow for large and difficult grids, offline it should be fine)

Input is via stdin, just copy and past the lines from the OP (but be careful, stackexchange sometimes deletes spaces or lines).

Some basic ideas of this code: It uses a recursive function `f`. `f` tries to place one shape at the board. For each possible location it calls itself with the modified board. There are 3 loops in it. `o` determines the orientation (2 - horizontal, 3 - vertical). It will always place the shape horizontal, therefore at the end of `o=2`, it will transpose the board with the function `t`. `i` is the row and `j` are all possible starting columns. Then a lot of checks happen, if the ends of the shape have valid chars, if the middle of the shape has valid chars and if the surrounding is empty.
> 3 votes

# Answer
# JavaScript (ES6) 661 ~~667 695 702 745 755 786 790 784 798~~

~~Work in progress, can be shortened.~~ Probably too slow on a complex grid. Maybe not.

**Edit** A bit longer, a lot faster.
**Edit 2** Bug fix, columns/rows check. Incidentally, now it's faster

The M function is the main. The w parameter is a multiline string with all the input. The function parses the input and prepare a starting board. Characters `<>^v|-*` in the starting board are replaced with `,`, each `,` has to be replaced with `*` in the correct solution.

The R function tries recursively to place all shapes in the board. When a shape is placed, it calls itself passing a shorter list of shapes and the modified board. When all shapes are placed, a solution can still be invalid if there are `,` not replaced by `*`.

The P function test if a shape can be placed a a given position and orientation. It checks all the costrains (inside the board, no overlap, no touch, valid row and column count)

```
M=w=>(
  [x,c,r,z]=w=w[S='split'](n='\n'),
  (b=[...w.slice(4).join(n)])
  .map((c,p)=>~(k='*<>-*^v|'.indexOf(c))&&[(q=k>3?z:1,0),k&1&&-q,k&2&&q].map(o=>b[p+o]=0),
    c=c[S](e=' '),r=r[S](e),w=z++,f='*',s='',x[S](e).map(v=>s+=v[0].repeat(v[2]))),
  R=(s,b,x=0,y=0,n=s[0],V=i=>b[i]>'#',
    P=(p,o,q,t,g,l,d=[...b])=>{
        if(l<z-n&!V(p+o*l-o)&!V(p+o*l+o*n))
        {
          for(i=-1;v=d[p],++i<w;p+=o,t-=v==f)
            if(i>=l&i-n<l)
              for(v!=e&v!=0|[q,w,~z].some(w=>V(p+w)|V(p-w))?t=0:d[p]=f,j=o*i,u=k=0;
                  ++k<z;(u+=d[j]==f)>g[i]?t=0:j+=q);
          return t>=n&&d.join('')
        }
    })=>{
    if(b){
      if(!n)return~b.search(0)?0:b;
      for(s=s.slice(1);y<w||(y=0,++x<w);++y)
        if(h=R(s,P(y*z,1,z,r[y],c,x))||n>1&&R(s,P(x,z,1,c[x],r,y)))return h
    }
  })(s,b)

```

**Test** In FireFox/FireBug console

```
;['3x2 1x4\n2 2 3 1 2\n4 0 3 0 3\n5\n     \n     \n    #\n  #  \n    *\n'
,'3x1 1x6\n2 0 4 0 3\n3 1 2 1 2\n5\n*    \n     \n     \n   # \n     \n'
,'5x1 4x1 2x1 1x2\n1 2 3 3 2 2\n0 5 0 4 0 4\n6\n#     \n  -   \n      \n      \n #    \n   <  \n'
,'4x1 3x1 2x2 1x2\n1 4 0 3 0 5\n4 1 1 2 3 2\n6\n <    \n      \n      \n      \n    # \n ^ #  \n']
.forEach(x=>console.log(x,M(x).replace(/ /g,'`'))) // space replaced with ` for clarity

```

*Output* (total execution time \< 1sec)

3x2 1x4
2 2 3 1 2
4 0 3 0 3
5

    #
  #
    *

***`*
`````
`***#
``#``
*`*`*

3x1 1x6
2 0 4 0 3
3 1 2 1 2
5
*

   #

*`*`*
``*``
``*`*
*``#`
``*`*

5x1 4x1 2x1 1x2
1 2 3 3 2 2
0 5 0 4 0 4
6
#
  -

 #
   <

#`````
`*****
``````
`****`
`#````
*`**`*

4x1 3x1 2x2 1x2
1 4 0 3 0 5
4 1 1 2 3 2
6
 <

    #
 ^ #

**`*`*
```*``
`````*
`*```*
`*`*#*
`*`#`*

> 3 votes

---
Tags: code-golf, puzzle-solver
---


# Question
Title: Anagramming Stack Exchange question titles into programs
Stack Exchange currently has 134 question and answer sites. This includes all beta sites (such as PPCG) but not Area 51 proposals nor any meta sites, except for the "mother meta".

To answer this question, choose one of those sites and write a program where every line of code is an anagram of the title of a different question on that site. Any questions from that site may be used **as long as they have not been deleted, and were asked before this question**.

The title of a question includes *all* characters that appear in the `Title` textbox when the `edit` link is clicked below a question, be they whitespace, mathjax formatting, crazy Unicode characters, whatever. (You can use the Stack Exchange API if you want to query a bunch of question titles at a time.)

The program you write must output the string that reliably appears at the top of every Stack Exchange page:

```
Questions Tags Users Badges Unanswered Ask Question

```

This exact text, plus an optional trailing newline, is the only thing your program should output. There is no input. The output should go to stdout or, if that's not possible, a similar alternative.

Since doing this with only anagrams of question titles may be kind of tricky, you may optionally add **one** character of your choice to each line in your program, in any column. Not all lines need to have an extra character and it does not have to be the same character across lines. The character may be anything except for a line terminator. The characters in the line minus this one new character should still be a perfect anagram of a question title.

# Scoring

Your score is `(number of lines with no added character) + 2 * (number of lines with an added character)`. The lowest score wins. In case of ties the earlier answer wins.

# Details

* **You must provide links to all the questions you have used the titles from.**
* You may choose the same Stack Exchange site as someone else though you are encouraged to choose unused sites, just for some variety.
* If a question you used gets deleted before the winner is chosen, your submission will be invalid, so it's best to choose well established questions.
* If titles are edited on some of your questions then your submission is still valid as long as the edit history shows that your titles were correct when you posted your answer.
* Comments in your program are fine.
* Editing question titles to suit your needs is very bad form.

# Answer
## Python 2, score = 2

```
print '''               &''(()),..===>>?''HHIMMMMPPaaaaabccdddeeeeeeeeeegggimmmmnnnnnoooooprrrrsstwyy''' and 'questions tags users \
badges unanswered ask question'.title() or '             $.?IIWaaabbccccccceeefghhhhhhiijjkklllllmmnnnoooprrrstttttttuxyyz'

```

I couldn't quite get it in one line, so here's a fairly straightforward solution in two.

I found the questions on Stack Overflow by regexing through the 50,000 longest titles:

Here's my best attempt at a one-liner for anyone who's going for it (feel free to use it):

```
print "questions tags users badges unanswered ask question".title() or AHHRUaacccceeeeeeeeeffghikkllmnnnooooooorrrrrrrtwwwy

```

How to guarantee uniqueness of a referrer who clicks on a link in a remote webpage("Request.UserHostAddress" not working correctly)?
> 11 votes

# Answer
# Golfscript, 3 lines with no added characters

```
"Questions Tags Users Badge"'exception SLSATE[HY000][1049]eymfny incnue while pn chma afte intallin FOSBundl'or
"s Unanswered Ask "'Reoccurring error The current idetity(NT THORITY\NETWORK SERVICE)oe ot have it cc toC:\WINDOWS\Microsoft.NET\Framewor\v2.0.50727\Tempary ASP.NET Files'or
"Question""D he 'S'  SL stand f standard or strctured?"or

```

I hit StackOverflow, since it probably had the most (useful) posts. A lot of Qs could be found in jQuery and SQL.

**Bibliography:**

Uses two strings each line, and takes the first one with `or`. I don't know any proper Golfscript, but I tested it here.

It's possible to get the necessary quotes in two lines, but you'll need a language that lets you dump chars.
> 11 votes

# Answer
# Pyth, 2, 1 line with 1 extra character.

```
r"questions tags users badges unanswered ask question"tyhgkk)            (.?AHHRUaacccceeeeeeeeeeffiiilllmnnnnooooooooprrrrrrrrtttwww

```

Uses grc's How to guarantee uniqueness of a referrer who clicks on a link in a remote webpage("Request.UserHostAddress" not working correctly)?, which unfortunately requires an extra `s` to work.
> 4 votes

---
Tags: string, code-challenge, source-layout, permutations
---


title: Find the inverse of a matrix

text:
# Question
Title: Find the inverse of a matrix
Write a full program to calculate the inverse of a 4-by-4 matrix.

# Rules

The sixteen values of the initial matrix must be hard-coded to variables, as follows:

```
_       _
|a b c d|
|e f g h|
|i j k l|
|m n o p|
-       -

```

Then print the values of the inverse matrix, row by row, with each number separated by some delimiter. You may assume that the given matrix has an inverse.

The results must be completely accurate, limited only by the programming language. For example, you may assume that (1 / 3) * 3 = 1, there's no such thing as integer overflow, and so on.

You may use only the following operations:

* Addition - 10 points
* Subtraction - 15 points
* Multiplication - 25 points
* Division - 50 points
* Assignment to a variable - 2 points
* Printing a variable (not an expression) and a delimiter - 0 points
* Recalling a variable or numeric constant - 0 points

For example: `x = (a + b) / (a - 2)` would score 77 points.

To clarify, you **may not** use any other operations or structures, such as arrays, functions (outside the main method, if needed), if-statements, etc.

The initial hard-coding of the variables does not give any points.

Fewest points wins.

# Testcases

Note that all testcases can be used in reverse.

```
a=1; b=1; c=2; d=-1; e=-2; f=0; g=-2; h=1; i=-1; j=2; k=1; l=0; m=2; n=-1; o=0; p=2

```

Print, in order: `9 7 -4 1 10 8 -4 1 -11 -9 5 -1 -4 -3 2 0`

```
a=1; b=2; c=3; d=0; e=2; f=2; g=1; h=0; i=4; j=4; k=4; l=4; m=2; n=1; o=-2; p=0

```

Print, in order: `-5 7 0 -4 6 -8 0 5 -2 3 0 -2 1 -2 .25 1`

```
a=-.25; b=.5; c=0; d=.5; e=1; f=.25; g=-.5; h=0; i=-1; j=-.5; k=.5; l=.25; m=.25; n=1; o=0; p=0

```

Print, in order: `-2 4 4 2 .5 -1 -1 .5 -3.75 5.5 7.5 4.25 .5 3 3 .5`

# Answer
> 2 votes
# Java: 3974

Now this is a totally new version of the prgoram, that satisfies the updated conditions. Note that I did use an array for printing in this version here, but I counted as if every assignment was an own new variable. The for loops save some space for those who want to see the code here...

I am using the only possible approach (i think) under the restrictions via minor determinats that form the adjoint matrix.

For those who want to check the correctness of the formula.

## Stats:

```
= :  2* 42
+ : 10* 44
- : 15* 60
* : 25*100
/ : 50*  1

public static void main(String[] args){
    double a=4,b=1,c=1,d=2,
           e=4,f=4,g=1,h=5,
           i=2,j=1,k=5,l=1,
           m=4,n=2,o=4,p=3;
    double af=a*f;
    double kp=k*p;
    double lo=l*o;
    double ag=a*g;
    double jp=j*p;
    double ln=l*n;
    double ah=a*h;
    double jo=j*o;
    double kn=k*n;
    double be=b*e;
    double bg=b*g;
    double lm=l*m;
    double bh=b*h;
    double io=i*o;
    double km=k*m;
    double ce=c*e;
    double cf=c*f;
    double ip=i*p;
    double ch=c*h;
    double in=i*n;
    double jm=j*m;
    double de=d*e;
    double df=d*f;
    double dg=d*g;

    double z = 1/(af*(kp-lo)+ag*(ln-jp)+ah*(jo-kn)+be*(lo-kp)
               +bg*(ip-lm)+bh*(km-io)+ce*(jp-ln)+cf*(lm-ip)
               +ch*(in-jm)+de*(kn-jo)+df*(io-km)+dg*(jm-in));

    double[] inv = {h*(jo-kn)+g*(ln-jp)+f*(kp-lo) , d*(kn-jo)+b*(lo-kp)+c*(jp-ln) , (ch-dg)*n+(df-bh)*o+(bg-cf)*p , (dg-ch)*j+(bh-df)*k+(cf-bg)*l,
            h*(km-io)+g*(ip-lm)+e*(lo-kp) , d*(io-km)+c*(lm-ip)+a*(kp-lo) , (dg-ch)*m+(ah-de)*o+(ce-ag)*p , (ch-dg)*i+(de-ah)*k+(ag-ce)*l,
            h*(in-jm)+f*(lm-ip)+e*(jp-ln) , d*(jm-in)+a*(ln-jp)+b*(ip-lm) , (bh-df)*m+(de-ah)*n+(af-be)*p , (df-bh)*i+(ah-de)*j+(be-af)*l,
            g*(jm-in)+e*(kn-jo)+f*(io-km) , c*(in-jm)+b*(km-io)+a*(jo-kn) , (cf-bg)*m+(ag-ce)*n+(be-af)*o , (bg-cf)*i+(ce-ag)*j+(af-be)*k};

    for(int u=0;u<16;u++){
        inv[u] = inv[u]*z;  //counting as 16 assignments and 16 multiplicatiosn

    }
    //printing all the values
    for(int u=0;u<16;u++){
        if(u%4 == 0){
            System.out.println("");
        }
    System.out.print(inv[u]+" ");

    }

}

```

---
Tags: math, number, matrix, atomic-code-golf, linear-algebra
---