18
\$\begingroup\$

How well do you know the site? Let's find out.

This is a challenge. Cop's thread.

As a robber, you need to:

  1. Find a non-deleted, non-closed challenge that matches a cop's submission. The challenge cannot have the following tags: , , , , , , , . The challenge must have restrictions on valid output.
  2. Post the challenge here, and link to the cop you are cracking
  3. Add a "Cracked" comment to the cops' post, with a link back to this answer

You will receive 1 point, plus 1 point for each 24-hour period the submission had remained uncracked (max 7). Tiebreaker is the total number of cracked submisisons.

Notes:

  • If a challenge requires an output of X, and you output XY or YX where Y is anything besides whitespace, the submission is not valid for that challenge.
  • A challenge newer than 2016-11-17 is not allowed.
  • I reserve the right to ban certain challenges if they are widely applicable (could be applied to the majority of all submissions).
  • Make sure you add a sentence or two as an explanation (it also helps your submission from being converted to a comment)
  • Thanks to Daniel for the initial idea!
\$\endgroup\$

17 Answers 17

5
+50
\$\begingroup\$

Calculate probability of getting half as many heads as coin tosses.

Cops entry (posted by Conor O'Brien): https://codegolf.stackexchange.com/a/100521/8927

Original question: Calculate probability of getting half as many heads as coin tosses.


The posted solution had a couple of obfuscation techniques applied, followed by multiple layers of the same obfuscation technique. Once past the first few tricks, it became a simple (if tedious!) task to extract the actual function:

nCr(a,b) = a! / ((a-b)! * b!)
result = nCr(x, x/2) / 2^x

Took a while to realise what I was looking at (for a while I suspected something to do with entropy), but once it twigged, I managed to find the question easily by searching for "probability of coin toss".


Since Conor O'Brien challenged an in-depth explanation of his code, here's a rundown of the more interesting bits:

It starts by obfuscating some built-in function calls. This is achieved by base-32 encoding the function names, then assigning them to new global-namespace names of a single character. Only 'atob' is actually used; the other 2 are just red-herrings (eval takes the same shorthand as atob, only to be overridden, and btoa simply isn't used).

_=this;
[
    490837, // eval -> U="undefined"       -> u(x) = eval(x) (but overwritten below), y = eval
    358155, // atob -> U="function (M,..." -> u(x) = atob(x)
    390922  // btoa -> U="function (M,..." -> n(x) = btoa(x), U[10] = 'M'
].map(
    y=function(M,i){
        return _[(U=y+"")[i]] = _[M.toString(2<<2<<2)]
    }
);

Next there are a couple of trivial string mix-ups to hide the code. These are easily reversed:

u(["","GQ9ZygiYTwyPzE6YSpk","C0tYSki","SkoYSkvZChhLWIpL2QoYikg"].join("K"))
// becomes
'(d=g("a<2?1:a*d(--a)"))(a)/d(a-b)/d(b) '

u("KScpKWIsYShFLCliLGEoQyhEJyhnLGM9RSxiPUQsYT1D").split("").reverse().join("")
// becomes
"C=a,D=b,E=c,g('D(C(a,b),E(a,b))')"

The bulk of the obfuscation is the use of the g function, which simply defines new functions. This is applied recursively, with functions returning new functions, or requiring functions as parameters, but eventually simplifies right down. The most interesting function to come out of this is:

function e(a,b){ // a! / ((a-b)! * b!) = nCr
    d=function(a){return a<2?1:a*d(--a)} // Factorial
    return d(a)/d(a-b)/d(b)
}

There's also a final trick with this line:

U[10]+[![]+[]][+[]][++[+[]][+[]]]+[!+[]+[]][+[]][+[]]+17..toString(2<<2<<2)
// U = "function (M,i"..., so U[10] = 'M'. The rest just evaluates to "ath", so this just reads "Math"

Although since the next bit is ".pow(T,a)", it was always pretty likely that it would have to be "Math"!

The steps I took along the route of expanding functions were:

// Minimal substitutions:
function g(s){return Function("a","b","c","return "+s)};
function e(a,b,c){return (d=g("a<2?1:a*d(--a)"))(a)/d(a-b)/d(b)}
function h(a,b,c){return A=a,B=b,g('A(a,B(a))')}
function j(a,b,c){return a/b}
function L(a,b,c){return Z=a,Y=b,g('Z(a,Y)')}
k=L(j,T=2);
function F(a,b,c){return C=a,D=b,E=c,g('D(C(a,b),E(a,b))')}
RESULT=F(
    h(e,k),
    j,
    function(a,b,c){return _['Math'].pow(T,a)}
);


// First pass
function e(a,b){
    d=function(a){return a<2?1:a*d(--a)}
    return d(a)/d(a-b)/d(b)
}
function h(a,b){
    A=a
    B=b
    return function(a){
        return A(a,B(a))
    }
}
function j(a,b){ // ratio function
    return a/b
}
function L(a,b){ // binding function (binds param b)
    Z=a
    Y=b
    return function(a){
        return Z(a,Y)
    }
}
T=2; // Number of states the coin can take
k=L(j,T); // function to calculate number of heads required for fairness
function F(a,b,c){
    C=a
    D=b
    E=c
    return function(a,b,c){return D(C(a,b),E(a,b))}
}
RESULT=F(
    h(e,k),
    j,
    function(a){return Math.pow(T,a)}
);


// Second pass
function e(a,b){...}
function k(a){
    return a/2
}
function F(a,b,c){
    C=a
    D=b
    E=c
    return function(a,b,c){return D(C(a,b),E(a,b))}
}
RESULT=F(
    function(a){
        return e(a,k(a))
    },
    function(a,b){
        return a/b
    },
    function(a){return Math.pow(2,a)}
);


// Third pass
function e(a,b) {...}
C=function(a){ // nCr(x,x/2) function
    return e(a,a/2)
}
D=function(a,b){ // ratio function
    return a/b
}
E=function(a){return Math.pow(2,a)} // 2^x function
RESULT=function(a,b,c){
    return D(C(a,b),E(a,b))
}

The structure of the function nesting is based around utility; the outer-most "D" / "j" function calculates a ratio, then the inner "C" / "h" and "E" (inline) functions calculate the necessary coin flip counts. The "F" function, removed in the third pass, is responsible for connecting these together into a usable whole. Similarly the "k" function is responsible for choosing the number of heads which need to be observed; a task which it delegates to the ratio function "D"/"j" via the parameter binding function "L"; used here to fix parameter b to T (here always 2, being the number of states the coin can take).

In the end, we get:

function e(a,b){ // a! / ((a-b)! * b!)
    d=function(a){return a<2?1:a*d(--a)} // Factorial
    return d(a)/d(a-b)/d(b)
}
RESULT=function(a){
    return e(a, a/2) / Math.pow(2,a)
}
\$\endgroup\$
  • \$\begingroup\$ Good job! This is slightly incorrect--eval is set to f. But the rest is correct! Also, a bit of elaboration as to how RESULT is derived might be worthy ;) \$\endgroup\$ – Conor O'Brien Nov 21 '16 at 1:30
  • \$\begingroup\$ @ConorO'Brien sure; I added my notes and an explanation of the utility of each function before collapsing them all. \$\endgroup\$ – Dave Nov 21 '16 at 1:58
  • \$\begingroup\$ @ConorO'Brien thanks for the bounty! \$\endgroup\$ – Dave Dec 2 '16 at 19:14
  • \$\begingroup\$ Always a pleasure :) \$\endgroup\$ – Conor O'Brien Dec 2 '16 at 20:06
3
\$\begingroup\$

MATL, Luis Mendo, Count number of hefty decimals between 2 numbers

&:"@FYAYm7>vs

I figured out what it does by playing with the inputs, but I couldn't figure out for what challenge you'd have to calculate the number of integers in a range whose sum was greater than 7 times the number of digits. After reading the MATL docs, I put together an rough explanation of what this does:

&    % Change default input format
:    % Implictly input two integers, create inclusive range
"    % For each item in this range:
  @    % Push the item
  F    % Push false
  YA   % Convert to base N digits; N is false, so this produces base-10 digits
  Ym   % Calculate arithmetic mean
  7>   % Push 1 if this is greater than 7, 0 otherwise
  v    % Concatenate result into array with previous result
  s    % Sum
     % Implicitly end loop and output

I then switched from searching "digit sum greater than 7 times length" to "average digit greater than 7", which yielded the challenge I was looking for.

\$\endgroup\$
3
\$\begingroup\$

아희(Aheui), JHM, Shortest infinite loop producing no output

Tried it online, code just keeps running and there's no output.

\$\endgroup\$
2
\$\begingroup\$

Reverse a 1-dimensional array

I think this is it, its hows up as the first answer for it.

https://codegolf.stackexchange.com/a/100368/31343

\$\endgroup\$
2
\$\begingroup\$

C#, Yodle, Given an input, move it along the keyboard by N characters

Input a string and int and changes each char of the string to the char that's N keys away on the keyboard (wrapping around).

\$\endgroup\$
2
\$\begingroup\$

Perl, Gabriel Benamy, Convenient palindrome checker

The code was obviously some kind of palindrome. Once I picked out the y- - - structure and noticed what was being transliterated, I knew what challenge it was.

\$\endgroup\$
  • \$\begingroup\$ You beat my by a few seconds ... but it took so long to download perl. \$\endgroup\$ – Laikoni Nov 18 '16 at 21:19
  • \$\begingroup\$ @Laikoni Honestly, after a couple tries on Ideone, I gave up on running the code and tried reading it instead. ;) \$\endgroup\$ – DLosc Nov 18 '16 at 21:27
2
\$\begingroup\$

Pyth - https://codegolf.stackexchange.com/a/100391/31343

I quickly found out what the program did, but finding the challenge took pretty long.

Different Way Forward

this is my buffer.

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 27 bytes, Adnan

Evaluating the score based from a chess FEN string

I decompressed the string and searched, and came up with this challenge.

\$\endgroup\$
1
\$\begingroup\$

MATL, Luis Mendo, Calculate hamming weight with low hamming weight

dP7EGn:q^1J2/h)ts_hX=Gs[BE]Wd=~>~GBz*

I tested putting in numbers, and found the hamming weight thing on OEIS.

Then I searched on PPCG, tried putting in strings and it worked.

\$\endgroup\$
  • \$\begingroup\$ As I commented in the cops challenge, this doesn't actually crack my submission. Unfortunately, I guess this answer needs to be deleted \$\endgroup\$ – Luis Mendo Nov 21 '16 at 14:42
1
\$\begingroup\$

C++, Karl Napf, Substring Sum Set

Online demo showing the first test case from the question.

\$\endgroup\$
1
\$\begingroup\$

Ruby, histocrat, Implement a Truth-Machine

The code defines an iterated function system f(n) = n*(3*n-1)/2 that runs until n mod 7 is 0. Input of 0 therefore terminates right away (after printing 0 once). Input of 1 gives 1, leading to an infinite loop of printing 1. Other input terminates after 1-3 steps if the initial n is congruent to 0, 2, 3, 5, or 6 mod 7, or grows forever if it is congruent to 1 or 4 mod 7. But that's irrelevant.

\$\endgroup\$
1
\$\begingroup\$

Hexagony, 548 bytes, Martin Ender

This is the "Print every character your program doesn't have" challenge!

Prints:

Elizabeth obnoxiously quoted (just too rowdy for my peace): "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG," giving me a look

Which is very similar to the output in this one. The clue here was that the last . wasn't printed. Also, the code itself had no letters, and we all know that the phrases in the output contains all letters in the alphabet.

\$\endgroup\$
1
\$\begingroup\$

Python, 935 Bytes, Mega Man, What is the smallest positive base 10 integer that can be printed by a program shorter (in characters) than itself?

I didn't actually try it. But I guess it prints a number longer than the program.

\$\endgroup\$
  • \$\begingroup\$ It prints 99**9999, which is just a tad larger. \$\endgroup\$ – Peter Taylor Dec 2 '16 at 10:06
0
\$\begingroup\$

Python 3, https://codegolf.stackexchange.com/a/100381/31343

Use xkcd's formula to approximate the world population

I just searched for challenges that involved leap years (because of the decoded divisibility by four checker) and that took no input.

\$\endgroup\$
  • \$\begingroup\$ Yep! I knew it would be obvious because of the %4 and the strftime, but good job for spotting the important parts of the code (most of it was gibberish) \$\endgroup\$ – FlipTack Nov 18 '16 at 21:40
  • \$\begingroup\$ Ah dangit, I was getting close, too. I had figured out it was something to do with dates, was getting 2005 and 2016/2017. Nice job. \$\endgroup\$ – Yodle Nov 18 '16 at 21:41
  • \$\begingroup\$ I'm surprised that neither of you simply ran the code, which generates the output 7.3 328, and searched that. The challenge comes up straight away. \$\endgroup\$ – FlipTack Nov 18 '16 at 23:36
0
\$\begingroup\$

Brainfuck, FinW, Print the ASCII table

That was easy, since he posted his answer on that challenge.

Link to his answer

\$\endgroup\$
0
\$\begingroup\$

Mathematica, JHM, Natural construction

The unary operator ± computes a set-theory based representation of the natural numbers.

\$\endgroup\$
0
\$\begingroup\$

Ruby, wat, 400th Question Celebration/Challenge

That was the first thing I found when searching for "400". That said, the challenge seems to be mistagged and should be a popcon and should probably also be closed for not having objective requirements.

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