44
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ Perl 5, size 27, by Morot - print'pin'=~tr(a-za)(za-z)r \$\endgroup\$ – user15244 Nov 6 '14 at 14:34
  • \$\begingroup\$ @WumpusQ.Wumbley We've all been there... ;) \$\endgroup\$ – Martin Ender Nov 6 '14 at 14:35
  • 3
    \$\begingroup\$ I refuse to waste my time attempting to appease it. \$\endgroup\$ – user15244 Nov 6 '14 at 14:35
  • \$\begingroup\$ Given the two question bodies, it appears that the scrambled/unscrambled answers are reversed \$\endgroup\$ – Mooing Duck Nov 6 '14 at 23:31
  • \$\begingroup\$ Ruby, 23 by MegaTom = p %++.methods[80][1..-1] \$\endgroup\$ – histocrat Nov 11 '14 at 22:31

182 Answers 182

31
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ That's insane - how did you figure out what the number was? \$\endgroup\$ – Sp3000 Nov 6 '14 at 4:14
  • 1
    \$\begingroup\$ I searched the logarithm (and others) of that number but didn't get any result. Now I found I was using too high precision. \$\endgroup\$ – jimmy23013 Nov 6 '14 at 4:32
  • 2
    \$\begingroup\$ @Sp3000: I've edited my answer. \$\endgroup\$ – Dennis Nov 6 '14 at 4:52
  • \$\begingroup\$ Very nice! I should have taken out two more characters from the string I guess. In my original I actually had the spaces still inside the string, but an mr before taking the length. Not that you wouldn't have figured that out as well at some point. ;) \$\endgroup\$ – Martin Ender Nov 6 '14 at 10:30
25
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ In Python 3 IDLE, this outputs (). \$\endgroup\$ – 23fc9a62-56de-47fb-97b4-737890 Nov 4 '14 at 21:14
  • \$\begingroup\$ @hosch250 Since its in a program (a python file), nothing is outputted, as there is no print. \$\endgroup\$ – matsjoyce Nov 4 '14 at 21:15
  • \$\begingroup\$ I see. I was running from the command line thing. \$\endgroup\$ – 23fc9a62-56de-47fb-97b4-737890 Nov 4 '14 at 21:16
  • 47
    \$\begingroup\$ ...."thing".... \$\endgroup\$ – TheDoctor Nov 4 '14 at 23:21
  • 3
    \$\begingroup\$ @Imray Because of short-circuiting - Python loads the tuple and checks if the tuple's value is true, since it's empty, it is false. The code to load the variable bciprt is never executed, so it never produces a NameError. \$\endgroup\$ – Mateon1 Nov 10 '14 at 14:13
20
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Nice job! My solution was quite similar: list(\nprint(range is range)for aacdeeeeehmppprrrrssvwy in\noct(int is int)). \$\endgroup\$ – xnor Nov 7 '14 at 1:46
  • \$\begingroup\$ @xnor LOL that variable name. Is it bad that I would have never thought of that? :P \$\endgroup\$ – FryAmTheEggman Nov 7 '14 at 2:23
  • 2
    \$\begingroup\$ @FryAmTheEggman I think everyone was expecting me to use the trick from my first cop. \$\endgroup\$ – xnor Nov 7 '14 at 2:24
  • \$\begingroup\$ @FryAmTheEggman Don't worry, you're not the only one :P \$\endgroup\$ – Sp3000 Nov 7 '14 at 2:25
13
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Have a point :) For reference, original was print 2**2**2**2/2**2**2/2**2**2/2-2**2**2*2**2-22, but it's not surprising at all that more than one option is correct. \$\endgroup\$ – Geobits Nov 4 '14 at 20:33
13
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Spot on. This was inspired by a sequence in OEIS which I can't find now. \$\endgroup\$ – Peter Taylor Nov 6 '14 at 12:29
  • 3
    \$\begingroup\$ And this is why having a separate thread for robbers is a good idea. Nice job! \$\endgroup\$ – Dennis Nov 7 '14 at 3:52
11
\$\begingroup\$

Python 3, size 16, by matsjoyce

import __hello__
\$\endgroup\$
  • 1
    \$\begingroup\$ Bah, beaten by 20 seconds >< \$\endgroup\$ – Geobits Nov 4 '14 at 21:17
  • \$\begingroup\$ Correct, one point to you (should we have a list with this info on it too?) \$\endgroup\$ – matsjoyce Nov 5 '14 at 7:39
11
\$\begingroup\$

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

\$\endgroup\$
  • 10
    \$\begingroup\$ Props to Doorknob for being insanely misleading with print, only to split it up into p for printing, %r for regexes and i for case-insensitive regex matching. \$\endgroup\$ – Sp3000 Nov 5 '14 at 19:15
11
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ For reference, my original: print@substr(new exception,~$$mn+=2+$$a+++$$i++); \$\endgroup\$ – bwoebi Nov 6 '14 at 1:54
  • \$\begingroup\$ Btw. I hope all the dollar signs and the fact that all the letters for main were in the string mislead you a lot. Also, a rather unusual method for extracting {main}, I think ;-) \$\endgroup\$ – bwoebi Nov 6 '14 at 1:58
  • \$\begingroup\$ @bwoebi The main didn't really mislead me, after spotting exception, new and substr. I thought they would just be variable names. It took me a bit to come up with using variable variables and than I spent most of the time on figuring out some order of operations that would actually yield a 5 which I could complement without using another set of parentheses. \$\endgroup\$ – Martin Ender Nov 6 '14 at 2:01
  • \$\begingroup\$ Well, for next time, if there are more dollars than characters, it usually are variable variables. (In this case I also abused varvars to force left-to-right evaluation.) How long did it take you then to spot the substr new exception? Also by the way, I have deeper knowledge of the Zend engine, so I can perfectly explain to myself why things are evaluated in which order and that's nice for these challenges ;-) If there's a specific thing you don't get, I'll happily explain it to you. \$\endgroup\$ – bwoebi Nov 6 '14 at 2:08
  • \$\begingroup\$ @bwoebi Come in chat tomorrow, and we can talk about it, but I've spent long enough on this today. ;) As for your first question, exception was obvious, which left stray characters for substr and new lying around. It was literally the first thing I saw when starting to work on it. \$\endgroup\$ – Martin Ender Nov 6 '14 at 2:12
9
\$\begingroup\$

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.

\$\endgroup\$
9
\$\begingroup\$

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.

\$\endgroup\$
  • 8
    \$\begingroup\$ Ruby is a scary-looking language. \$\endgroup\$ – feersum Nov 8 '14 at 14:16
8
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ I added a comment to the original answer for you. \$\endgroup\$ – FireFly Nov 14 '14 at 20:44
  • \$\begingroup\$ This is awesome (and close to the intended answer), but technically not valid because it doesn't have output. \$\endgroup\$ – histocrat Nov 14 '14 at 20:59
  • \$\begingroup\$ *facepalm Well I still had fun. \$\endgroup\$ – charredUtensil Nov 14 '14 at 21:29
  • 2
    \$\begingroup\$ @charredUtensil if you don't mind running your script for some more, I think the printing is just moving the p to before the expression. Presumably the remaining characters can be used to form the constants as you've done. \$\endgroup\$ – FireFly Nov 14 '14 at 21:34
  • \$\begingroup\$ I don't actually need to run it again. The last few characters of the string can be rearranged without changing the result - p %q[zyfnhvjkwudebgmaclrsx].to_i(36)/51074892 I know I broke my actual cracking attempt though :) \$\endgroup\$ – charredUtensil Nov 15 '14 at 6:32
7
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Just for reference the original programme is [__name__ for ___name__ in range(1,4)][2][3] \$\endgroup\$ – Caridorc Nov 5 '14 at 12:47
7
\$\begingroup\$

Perl, size 36, by squeamish ossifrage

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

Another difficult one.

\$\endgroup\$
  • 1
    \$\begingroup\$ Well done :-) That's it exactly. \$\endgroup\$ – squeamish ossifrage Nov 6 '14 at 10:03
  • \$\begingroup\$ @squeamishossifrage Thanks. You had some very nice 'Perl features' hidden in that program. \$\endgroup\$ – grc Nov 6 '14 at 10:22
7
\$\begingroup\$

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 dth 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 fs.

I first assumed that the fs 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.";
\$\endgroup\$
7
\$\begingroup\$

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

\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Should the Pprint be print, or at least pprint? \$\endgroup\$ – FireFly Nov 15 '14 at 0:56
  • \$\begingroup\$ @FireFly That's what the debug output stated. Maybe the Pyth interpreter defines its own Pprint? \$\endgroup\$ – Martin Ender Nov 15 '14 at 0:57
  • \$\begingroup\$ Oh, okay, never mind then. \$\endgroup\$ – FireFly Nov 15 '14 at 0:59
6
\$\begingroup\$

Python, size 69, by Sp3000

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

That was hard...

\$\endgroup\$
  • 1
    \$\begingroup\$ Nice! For reference, the original was print(sum(map(ord,str((dict(list(((str(),str(dict())),))),list()))))), but obviously a lot of different permutations of keywords would work. \$\endgroup\$ – Sp3000 Nov 5 '14 at 13:01
  • 2
    \$\begingroup\$ That's a LISP-level of parens there! \$\endgroup\$ – xnor Nov 7 '14 at 2:16
6
\$\begingroup\$

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!'

\$\endgroup\$
  • \$\begingroup\$ Ahaha nicely done, I thought the Ellipsis might trip people up but I guess not \$\endgroup\$ – Sp3000 Nov 8 '14 at 0:20
  • \$\begingroup\$ I saw the ellipsis and zfill, but didn't know about the bytes objects. Those could be useful in golfing arrays of integers! \$\endgroup\$ – feersum Nov 8 '14 at 0:22
  • \$\begingroup\$ Great job! I only saw the print and the .zfill, and I knew sum might be part of it, but I couldn't solve it. Have a +1. \$\endgroup\$ – 23fc9a62-56de-47fb-97b4-737890 Nov 8 '14 at 0:40
6
\$\begingroup\$

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

\$\endgroup\$
  • 3
    \$\begingroup\$ Wow, nice detective work! \$\endgroup\$ – Sp3000 Nov 8 '14 at 15:28
6
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ Heh, nice. Wondering what the indended solution was... \$\endgroup\$ – FireFly Nov 12 '14 at 23:28
  • \$\begingroup\$ This is not an intended solution. The original solution does not have any "throw-away" things like fgiillmmooprrsstt or ,,,\016:::S[]____tuuvyy. \$\endgroup\$ – Vi. Nov 13 '14 at 12:34
  • \$\begingroup\$ exec? My code chould have been shorter... I was emulating it with compile+eval because of I forgot about exec... \$\endgroup\$ – Vi. Nov 13 '14 at 12:36
  • \$\begingroup\$ Implemented the shorter version. Try to figure out the original trick. \$\endgroup\$ – Vi. Nov 13 '14 at 12:42
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Dammit, I just solved it too :/ \$\endgroup\$ – Optimizer Nov 4 '14 at 21:45
5
\$\begingroup\$

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

\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ It doesn't, but congrats anyways! My code was:print''.__doc__[::2][::3].split()[1].split('.')[0][:-~-~True] \$\endgroup\$ – FryAmTheEggman Nov 5 '14 at 4:56
  • \$\begingroup\$ In hindsight, I shouldn't have included the quotes... ;) \$\endgroup\$ – FryAmTheEggman Nov 5 '14 at 4:59
  • \$\begingroup\$ @FryAmTheEggman Oh wow - nice program! I was convinced you had at least used dir() to find the 'get'. And yes, it would have been very difficult without the quotes. \$\endgroup\$ – grc Nov 5 '14 at 5:04
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Hmm... looks like I was pretty wasteful with my parens. Had print(~(~(()<())<<((()<((),))<<(()<((),))))) originally. \$\endgroup\$ – Sp3000 Nov 5 '14 at 13:49
5
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ And I don't know how did you figure it out:) Original: _:print_r(chr(3*pow(2,5)+@++$i));if(@$i<4<<1)goto _;. \$\endgroup\$ – kenorb Nov 5 '14 at 18:38
  • 3
    \$\begingroup\$ @kenorb a) you need to print something, so echo not possible; print remained; b) you need some loop, but for a for loop, there weren't enough semicolons, and well, there's a colon... so probably a label there in combination with goto; c) then it needs an if to abort the goto-loop. Having now X:print($Y);if($Y)goto X; (X and Y being placeholders); d) there's a ++, but no =, so probably some ++$Z from 1 to 8; e) to get letters from an integer, we need chr() (usually) - it was there; f) now I just needed to find numbers 96 and 8 for chr and if. Then fill in placeholders and volià. \$\endgroup\$ – bwoebi Nov 5 '14 at 18:47
5
\$\begingroup\$

PHP, size 54, by Steve Robbins

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

Not the original solution, I think.

\$\endgroup\$
  • 2
    \$\begingroup\$ Haha, that's lovely. I started by fishing out the echo and the while, but then couldn't be bothered to find a loop that produces 42. \$\endgroup\$ – Martin Ender Nov 5 '14 at 18:22
  • \$\begingroup\$ There was a while in my original. \$\endgroup\$ – Steve Robbins Nov 5 '14 at 19:17
5
\$\begingroup\$

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!

\$\endgroup\$
5
\$\begingroup\$

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

\$\endgroup\$
5
\$\begingroup\$

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
\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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