29
\$\begingroup\$

For the main cops' challenge, click here

NOTICE - This challenge is now closed. Any cracks which are posted now will not be counted on the leaderboard and the accepted answer will not change.

Challenge

Given the original program, its output and the output of the changed program, you have to find out which characters need to be changed, removed or added to get the expected output.

When you crack someone's code, leave a comment with a link to your crack on their answer.

Formatting

# [<language>, <username of program owner>](<link to answer>)

## Description

<description of change and how you found it>

## Code

<changed code>

Winning

The person who has cracked the most solutions wins.

Leaderboard

13 cracks:

  • Dennis

8 cracks:

  • Alex Van Liew

5 cracks:

  • Sp3000
  • isaacg

3 cracks:

  • Luis Mendo
  • jimmy23013
  • Dom Hastings

2 cracks:

  • mbomb007
  • Sluck49

1 crack:

  • TheNumberOne
  • Jakube
  • ProudHaskeller
  • David Zhang
  • samgak
  • paul.oderso
  • rayryeng
  • mgibsonbr
  • n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳
  • Stewie Griffin
  • abligh
\$\endgroup\$
1
  • 1
    \$\begingroup\$ @mbomb007 Can you refrain from editing this post, because it makes it harder for me to know where I am when updating the leaderboard \$\endgroup\$
    – Beta Decay
    Commented Aug 13, 2015 at 20:25

61 Answers 61

3
\$\begingroup\$

APL, Mauris

Description

This was pretty much trial and error. I knew I had to insert a ¯ (negative number) and use mathematical functions like (trigonometic) or (logarithm) that yield complex number for negative input, or directly insert a J (imaginary part).

After a lot or errors, I finally tried inserting a ¯ before 7 and a before /.

Code

-⍟/3⍴15¯7

Try it online in ngn/apl demo, the online interpreter recommended by the cop.

Note that this won't work in, e.g., Dyalog APL, which requires a space before the high minus.

\$\endgroup\$
1
  • \$\begingroup\$ Wow, you just don't stop! :O \$\endgroup\$
    – Beta Decay
    Commented Aug 15, 2015 at 21:07
3
\$\begingroup\$

APL, Mauris

Description

Unlike the two APL answers I cracked before, the indented output of this one reveals very little about the required changes, so I decided to try a brute force approach.

Two characters aren't enough for loops, so the added characters (if any) had to be parts of numeric literals, mathematical functions or .

I chose a subset and hoped I'd get lucky. Using this CJam script, I generated all source codes (many of them with syntax errors) at an edit distance of 2 or less that only add character from the chosen set. This yielded 28,014 different potential solutions.

Aside from the online interpreter, ngn/apl is available for NodeJS. It even has a command-line flag (-l) that executes code linewise, which is almost perfect for this purpose.

After a minor change that condensed error output to a single line, I was able to grep the output to find the line number of the correct source code. The interpreter powered through the roughly 28,000 possible solutions in less than 6 seconds.

This sums up what I did:

$ diff apl.js `which ngn-apl`
4806c4806
<                       return e + '\n';
---
>                       return ('' + e).replace(/\n/g, '') + '\n';
$ cjam gen-edit-dist-2.cjam > brute-force.apl
3⍟877
0123456789.¯+-÷×⌈⌊*!|⍟○⊥⊤⍨
$ wc -l brute-force.apl 
28014 brute-force.apl
$ time ngn-apl -l < brute-force.apl | grep -n '0\.2001649'
3791:0.20016493054644696
20128:0.20016493054644696

real    0m5.506s
user    0m5.516s
sys     0m0.252s
÷3⍟○77
3⍟⍨○77

This reveals two possible solutions: replacing 8 with and inserting ÷ before 3, or replacing 8 with ⍨○.

Code

÷3⍟○77

or

3⍟⍨○77

Try them online in the ngn/apl demo.1

These modifications calculate 1 / log3 77π = log77π 3, which yields the desired output.


1 Note that the last digit may be a 3 on some machines.

\$\endgroup\$
2
  • \$\begingroup\$ Nice work. But if the digits change from browser to browser that is a huge problem... Maybe jimmy23013's 4 byte APL cop is impossible in some environments simply depending on floating point rounding \$\endgroup\$
    – lynn
    Commented Aug 16, 2015 at 17:47
  • \$\begingroup\$ This seems to be a simple 32 vs 64 bit issue. jimmy23013's modified code works on my desktop and my phone, so it doesn't seem to have the same issue. Writing truly platform-independent code should pretty much be impossiboe once you involve fixed width floats... \$\endgroup\$
    – Dennis
    Commented Aug 16, 2015 at 18:13
2
\$\begingroup\$

C++, f41lurizer

Good old trigraphs.

#include <iostream>
int main()
{
    //can you figure it out??/
    std::cout << "I like cake and";
}
\$\endgroup\$
2
  • \$\begingroup\$ g++ won't accept the trigraph without additional compiler flags. Removing the newline should work with all compilers. \$\endgroup\$
    – Dennis
    Commented Aug 11, 2015 at 22:11
  • \$\begingroup\$ Heh, I suppose that does work, huh? I'm pretty sure this was the intended solution, but it doesn't really matter since the original is invalid anyway. \$\endgroup\$ Commented Aug 11, 2015 at 22:29
2
\$\begingroup\$

Python 2, muddyfish

Description

Change `i` to `id` = '<built-in function id>' and 1234 to 01234 (octal). Found by recalling the wise words of Sir @xnor (paraphrased): "If you ever need a string that's 22 chars long..."

Code

i=long;j=map;print reduce(i.__mul__,j(i,j(ord,`id`)))/01234
\$\endgroup\$
2
\$\begingroup\$

VBA, JimmyJazzx

Description

First of all the call of a(2) was strange since only a(0) and a(1) get used, that was actually a big hint.

Next i looked into what the function IRR really does (see here). There is no combination of integer a(0) and a(1) that can possibly yield the modified output.

So I looked for combinations of a(0) and a(2) (<- first character changed) that resulted in the desired output and found a(0) = -1 and a(2) = 8. Since multiplying a(0) and a(2) with the same number doesn't change the outcome I simply multiplied both with 5 so a(0) would stay the same.

Code

Sub q()
Dim a(2) As Double
a(0) = -5
a(2) = 40
MsgBox IRR(a, 0.253)
End Sub
\$\endgroup\$
1
  • \$\begingroup\$ Though this may yeild the correct result this is not what I had done. mbomb007 did get what i had done correct. Good try though and im not sure which one the judge will accept as this one did come in first and ends up with the same result as the real answer. As for the a(2) that was there to mislead people, as it took the same amount of bytes as a(1) would have. But wanted to keep people away from seeing what IRR really does. \$\endgroup\$
    – JimmyJazzx
    Commented Aug 13, 2015 at 17:50
2
\$\begingroup\$

Clojure, Bob Jarvis

Base conversions are fun.

(printf "%d\n" 7r2155263413256326162)
\$\endgroup\$
2
\$\begingroup\$

PHP, Ismael Miguel

print_r(range(1,07));

I guess it really was that simple.

\$\endgroup\$
3
  • \$\begingroup\$ Yup, it was that simple. I didn't put that much effort on it, I was just warming up. \$\endgroup\$ Commented Aug 12, 2015 at 21:35
  • \$\begingroup\$ PHP could be a great language for this challenge because of all the wonky stuff it's got in there. \$\endgroup\$ Commented Aug 12, 2015 at 21:37
  • \$\begingroup\$ Yeah, I think I will come up with something \$\endgroup\$ Commented Aug 12, 2015 at 21:37
2
\$\begingroup\$

Matlab/Octave, paul.oderso

Description

I took the natural log, and recognized it as near pi ^ 2. From there it was easy.

Code

e^(pi*pi)+2

Added a p, 1 -> 2

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

modern Perl 5, msh210

Description

The s/// call has to only apply to the first element in the @array and using each with the for covers it off!

Code

@array = (qw smiles) x 11;
s/.*// for each @array;
print "@array\n";

Added space in between for and each. I

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Works in ideone. You can just add an arbitrary space for the second changed character. \$\endgroup\$ Commented Aug 13, 2015 at 2:10
2
\$\begingroup\$

MATLAB, Jonas

Description

Change 1+1 to 49+1. I don't actually have MATLAB so I can't test this, but the number looks right

Code

sin(49+1)
\$\endgroup\$
3
  • \$\begingroup\$ yes - thought that's not what I had in mind. \$\endgroup\$
    – Jonas
    Commented Aug 13, 2015 at 12:46
  • 1
    \$\begingroup\$ @Jonas: What was the hard solution? Do you mind sharing? \$\endgroup\$ Commented Aug 13, 2015 at 12:46
  • \$\begingroup\$ @StewieGriffin: Here's a better version of the question instead: codegolf.stackexchange.com/a/54625/18 \$\endgroup\$
    – Jonas
    Commented Aug 13, 2015 at 12:57
2
\$\begingroup\$

Wolfram Language Mathematica or WolframAlpha, belisarius

Original Code

8.!

Changed Code

8.^i!

Original Output

40320.

Changed output

2.67182 - 0.891969 I
\$\endgroup\$
2
\$\begingroup\$

GolfScript, Dennis

Description

9,:n9 doesn't work because n9 would be one variable name. In GolfScript you usually get rid of this by using a symbol as the variable name, so...

Code

9,: 9

More explanations.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Did... Did you assign something to the space character? \$\endgroup\$ Commented Aug 14, 2015 at 16:48
  • \$\begingroup\$ @AlexVanLiew Yes. The full program executed would be 9,:space 9]print space n space print. \$\endgroup\$
    – jimmy23013
    Commented Aug 14, 2015 at 18:54
  • \$\begingroup\$ That's amazing. \$\endgroup\$ Commented Aug 14, 2015 at 20:20
2
\$\begingroup\$

JavaScript, Razvan

Description

Changed 1 to .1 and added a semicolon.

Code

a=(((b=(a=.1)+a)+a)-b-a)*(a=[b]);['length'];
alert(a);
\$\endgroup\$
1
  • \$\begingroup\$ Yes! That's what I had in mind. \$\endgroup\$
    – Razvan
    Commented Aug 14, 2015 at 8:20
2
\$\begingroup\$

PHP, Razvan

Description

Inserted ( and ), so $T_I_(M_E * $A_U_T_U_M_N) executes TAN(M_E * 2), where M_E is Euler's natural number.

Code

$S_U_M_M_E_R = 1;
$A_U_T_U_M_N = 2;
$T_I_M_E = 1;

if ($T_I_M_E == $S_U_M_M_E_R) {
    $A_C_=$T_I_=$O_N= 'SWIM' ? 'TAN' : 'DRINK';
}

print $T_I_(M_E * $A_U_T_U_M_N);
\$\endgroup\$
2
\$\begingroup\$

Octave, Daniel

Description

111 is the code point of the ASCII character o, so the desired output can be achieved by replacing cos with "o".

(1) retrieves the first character of the string and *1 casts to integer.

Code

format long;
"o"(1)*1
\$\endgroup\$
2
\$\begingroup\$

Ruby, histocrat

Description

Need to make the regex at the end work on the string literal ?9 so we need to make the variable $_ instead of _, also need to start the regex itself. Didn't realise that you could omit the {} when interpolating variables into regex in ruby.

Code

p $_=?9;p$.+=1until /#$./
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Confirmed working on ideone (Ruby 2.1.5), but it doesn't work on my machine (Ruby 2.1.5). Odd. \$\endgroup\$
    – Dennis
    Commented Aug 15, 2015 at 15:32
  • \$\begingroup\$ Nice one. works fine for me in ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] \$\endgroup\$
    – gnibbler
    Commented Aug 15, 2015 at 17:45
2
\$\begingroup\$

APL, jimmy23013

Description

The output is obviously 1/9 with rounding errors and the code already contains a (logarithm), so using it together with * (exponentiation) seems a natural choice for introducing that error.

In fact, inserting between and 9, and * between 9 and 9 produces the intended output.

reverses the arguments of the preceding dyadic function, so this calculates log999 ≈ 1/9 with the intended error.

Code

9⍟⍨9*9

Try it online in the ngn/apl demo.

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

Matlab / Octave, Jonas

Description

Just change tragic by magic in the second line.

tragic is a symmetric, integer-valued matrix. The difference between both inputs is integer-valued but not symmetric. So a new kind of matrix was needed. The integer values and the name traffic looked familiar.

Code

mistake=-1;tragic=rosser;a=hilb(8)*42;
a(:,:)+magic(8)/mistake
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I guess I should have put a call to det in there to make it harder, but I wanted this to remain fun (also, det doesn't easily fit into a sentence) \$\endgroup\$
    – Jonas
    Commented Aug 13, 2015 at 16:33
  • 1
    \$\begingroup\$ A magic mistake, eh? \$\endgroup\$ Commented Aug 13, 2015 at 17:02
  • \$\begingroup\$ @Jonas Yes, with det it would have been much harder \$\endgroup\$
    – Luis Mendo
    Commented Aug 13, 2015 at 18:51
1
\$\begingroup\$

PHP, Dom Hastings

Comment out the first two lines so they all append together.

define('E','!');

$x = 4;
$t = " Hello World";
$t .= #;
$t .= #;
$t .= E;

print($t);
\$\endgroup\$
1
  • \$\begingroup\$ Not quite, I get: ` Hello World!tt`... UsingPHP 5.4 if that makes a difference... I'll update the other with the version. \$\endgroup\$ Commented Aug 12, 2015 at 12:11
1
\$\begingroup\$

Lua, TreFox

In Lua, # is the "sizeof" operator. The discrepancy in the original behavior (15 or 23) is because the solution involves the size of the string created by converting a table to a string, and that string contains the address of the table (which is 16 characters on a 64-bit system and 8 on a 32-bit system). It looks like the particular distribution TreFox has is 64-bit. Also, apparently arguments in Lua work like arguments in Javascript, in which they don't seem to care how many arguments are passed, so changing the . to a , only causes G to be printed.

G={string="gs_hSDrGSFG5;U*ts"}
print(#tostring(G,string))

Secretly, I think this challenge was designed to make you think about skimpy underwear the whole time you were working on it.

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

Matlab / Octave, rayryeng

Description

Change eig to eigs and sin to sind.

The main clue was that the modified output has six eigenvalues sorted by magnitude, which is what eigs returns.

Code

eigs(cov(reshape(sind(1:60),5,[])))
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Very well done! How long did that take you to figure out? :) \$\endgroup\$
    – rayryeng
    Commented Aug 12, 2015 at 22:46
  • 2
    \$\begingroup\$ It took quite a while... but I see now that the main clue had already been given in Matlab's chat room ! \$\endgroup\$
    – Luis Mendo
    Commented Aug 12, 2015 at 23:34
1
\$\begingroup\$

SWI-Prolog, Fatalize

Description

Replace an E for an F (or the other way around) and change a single digit in one of the numbers input.

Code

assert(d(F,F):-(print(E),print(F))). d(123456,123457).
\$\endgroup\$
2
  • 1
    \$\begingroup\$ That's not how I did it, but that works nonetheless! Well done. The way I did it was changing d(123456,123456) to dif(123456,123456), to call the builtin predicate dif/2 which returns false if its two arguments are the same. \$\endgroup\$
    – Fatalize
    Commented Aug 13, 2015 at 5:17
  • 1
    \$\begingroup\$ @Fatalize I really wish I've seen this earlier :P \$\endgroup\$
    – mgibsonbr
    Commented Aug 13, 2015 at 5:47
1
\$\begingroup\$

SWI-Prolog, mgibsonbr

Description

Change , (conjunction) to ; (disjunction).

Add a space to make the distance 2.

Code

assert((o(X,Y,Z):-ABC is X**X; print(ABC))). o(99,y,z).
\$\endgroup\$
1
\$\begingroup\$

JavaScript, Razvan

Description

The changed output being 10/3 was a dead giveaway.

Code

one = 1;
two = one + one;
three = two + one;
zero = three - two - one;
numbers = [three, two, one];

for (i = numbers.length - 1; i <= zero; i--) {
    numbers.pop();
}

infinity = 10 / numbers['length'];
alert(infinity);
\$\endgroup\$
2
  • \$\begingroup\$ No worries - I had == in the for loop, but yeah 10/3 was a dead giveaway :) \$\endgroup\$
    – Sp3000
    Commented Aug 13, 2015 at 13:15
  • \$\begingroup\$ Correct, I didn't notice this obvious solution. \$\endgroup\$
    – Razvan
    Commented Aug 13, 2015 at 13:17
1
\$\begingroup\$

Pyth, Beta Decay

Description

This one's just obvious.

Code

.!10

77 -> 10

\$\endgroup\$
1
  • \$\begingroup\$ Actually, I went for .!&77T. I guess I didn't really give it much thought ;) \$\endgroup\$
    – Beta Decay
    Commented Aug 14, 2015 at 12:35
1
\$\begingroup\$

CSS, Qwertiy

Description

After seeing that the first number was a zero what needed changed seemed pretty clear

Code

body:after{counter-reset:b 512;content:counter(a)"%"}

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

Stuck, Vioz-

Change the first two numbers both to 3.

3R3R3R4R5R6R7R8R9R9z]

Zipping in Stuck works like zipping in Python (I imagine z is backed by zip()), which is the shortest sequence is taken as the max length. Without the ], the output is a list of tuples, and I don't really know what ] does. Pops the list at the top of the stack and pushes everything in it onto the stack, it looks like.

@Vioz-: Particularly for your scipy module, you should make sure that if the numpy or scipy libraries aren't available it doesn't crash with ImportError, but rather defines any methods that module supplies to just raise NotImplementedError or something similar. Also, you probably shouldn't commit .pyc files to your repo.

\$\endgroup\$
2
  • \$\begingroup\$ Nice! My solution was actually 12R3R4R5R6R7R8R9R8z] (remove the first R, change the last 9 to 8). I guess I didn't think of the obvious solution :P. Also, thanks for the tips, I'm sort of new to this whole "my own language thing". ] just pops each element from the top list of the stack and adds it to the stack. I don't think I said that clearly in my explanation. \$\endgroup\$
    – Kade
    Commented Aug 14, 2015 at 18:49
  • \$\begingroup\$ @Vioz- You'll get the hang of it! \$\endgroup\$ Commented Aug 14, 2015 at 20:17
1
\$\begingroup\$

Python, rp.beltran

Description

Changed dis to this.

import this is an easter egg which prints The Zen of Python.

Code

import this
def torun():
 print "hello world"
try:
 print dis.dis(torun)
except:
 pass
\$\endgroup\$
4
  • \$\begingroup\$ Beat me by 30 seconds. \$\endgroup\$
    – isaacg
    Commented Aug 14, 2015 at 19:54
  • \$\begingroup\$ Dang it. I was hoping that trick was more obscure. Good job. \$\endgroup\$
    – rp.beltran
    Commented Aug 14, 2015 at 19:56
  • 1
    \$\begingroup\$ @rp.beltran I mean, if you google "The zen of python"... A more obscure trick I saw in an old cops/robbers was using from __future__ import braces and some clever stuff to extract the string "chance". \$\endgroup\$ Commented Aug 14, 2015 at 20:20
  • \$\begingroup\$ Fair point, and I figured it would get cracked pretty quickly. 2 people in 4 minutes though, I'm impressed. \$\endgroup\$
    – rp.beltran
    Commented Aug 14, 2015 at 20:25
1
\$\begingroup\$

CJam, Basset Hound

Description

Finding the proper changes is easier if we work from the desired output. 5010670554118 looks like an integer in base 8 or higher.

5010670554118Ab8b
S
5010670554118Ab9b

prints 344786655312 1415926558979, and the second group of digits look a lot like the decimal expansion of Pi.

In fact, Ps pushes "3.141592653589793" (Pi cast to string), "3."- (added 3) removes all occurrences of 3 and ., i converts the result to the integer 1415926558979 and 9b (replaced 2 with 9) performs the required base conversion.

Code

Ps"3."-i9b

Try it online.

\$\endgroup\$
1
  • \$\begingroup\$ Yep, that's it... \$\endgroup\$ Commented Aug 14, 2015 at 20:01
1
\$\begingroup\$

Perl, Adam Katz

Description

$_=cos 99 saves 0.0398208803931389 in the variable $_. If we multiply this amount by 0x7275, we obtain 1166.79161639936, which is roughly 4 times the original output and 8 times the modified output.1

The original code archives almost-division-by-4 by substituting the first 3 in $_ with a 0 by executing s/[3-8]/0/, which modifies $_ and returns the number of substitutions (1), by which $_ is then divided.2

After noting that there are eight digits between 3 and 8 in the unmodified value of $_, attempting to replace all of them by appending g to s/[3-8]/0/ seemed natural, since this will divide the (modified) value of $_ by the number of substitutions.

Finally, to diminish the effect of the almost-division-by-4, it suffices to replace the first 3 (and all occurrences of 3 and 8 that follow) with a 3 by replacing s/[3-8]/0/ with s/[3-8]/3/.

Code

$_=cos 99;printf"%.14f",0x7275*sin $_/s/[3-8]/3/g

1 The code actually applies sine to $_ before multiplying, but sin x ≈ x when x is close to 0.
2 Again, this completely ignores the sine, which is almost linear near 0.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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