Two Makes All The Difference - Robbers

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.

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.

• Dennis

8 cracks:

• Alex Van Liew

• Sp3000
• isaacg

• Luis Mendo
• jimmy23013
• Dom Hastings

• mbomb007
• Sluck49

1 crack:

• TheNumberOne
• Jakube
• David Zhang
• samgak
• paul.oderso
• rayryeng
• mgibsonbr
• n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳
• Stewie Griffin
• abligh
• @mbomb007 Can you refrain from editing this post, because it makes it harder for me to know where I am when updating the leaderboard – Beta Decay Aug 13 '15 at 20:25

C++, f41lurizer

Good old trigraphs.

#include <iostream>
int main()
{
//can you figure it out??/
std::cout << "I like cake and";
}

• g++ won't accept the trigraph without additional compiler flags. Removing the newline should work with all compilers. – Dennis Aug 11 '15 at 22:11
• 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. – Alex Van Liew Aug 11 '15 at 22:29

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


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

• 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. – JimmyJazzx Aug 13 '15 at 17:50

Clojure, Bob Jarvis

Base conversions are fun.

(printf "%d\n" 7r2155263413256326162)


PHP, Ismael Miguel

print_r(range(1,07));


I guess it really was that simple.

• Yup, it was that simple. I didn't put that much effort on it, I was just warming up. – Ismael Miguel Aug 12 '15 at 21:35
• PHP could be a great language for this challenge because of all the wonky stuff it's got in there. – Alex Van Liew Aug 12 '15 at 21:37
• Yeah, I think I will come up with something – Ismael Miguel Aug 12 '15 at 21:37

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

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

• Works in ideone. You can just add an arbitrary space for the second changed character. – Alex Van Liew Aug 13 '15 at 2:10

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)

• yes - thought that's not what I had in mind. – Jonas Aug 13 '15 at 12:46
• @Jonas: What was the hard solution? Do you mind sharing? – Stewie Griffin Aug 13 '15 at 12:46
• @StewieGriffin: Here's a better version of the question instead: codegolf.stackexchange.com/a/54625/18 – Jonas Aug 13 '15 at 12:57

Wolfram Language Mathematica or WolframAlpha, belisarius

Original Code

8.!


Changed Code

8.^i!


Original Output

40320.


Changed output

2.67182 - 0.891969 I


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

• Did... Did you assign something to the space character? – Alex Van Liew Aug 14 '15 at 16:48
• @AlexVanLiew Yes. The full program executed would be 9,:space 9]print space n space print. – jimmy23013 Aug 14 '15 at 18:54
• That's amazing. – Alex Van Liew Aug 14 '15 at 20:20

JavaScript, Razvan

Description

Changed 1 to .1 and added a semicolon.

Code

a=(((b=(a=.1)+a)+a)-b-a)*(a=[b]);['length'];

• Yes! That's what I had in mind. – Razvan Aug 14 '15 at 8:20

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


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


Ruby, histocrat

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 /#$./

• Confirmed working on ideone (Ruby 2.1.5), but it doesn't work on my machine (Ruby 2.1.5). Odd. – Dennis Aug 15 '15 at 15:32
• Nice one. works fine for me in ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] – gnibbler Aug 15 '15 at 17:45

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.

• Wow, you just don't stop! :O – Beta Decay Aug 15 '15 at 21:07

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.

• 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 – Lynn Aug 16 '15 at 17:47
• 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... – Dennis Aug 16 '15 at 18:13

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

• 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) – Jonas Aug 13 '15 at 16:33
• A magic mistake, eh? – Alex Van Liew Aug 13 '15 at 17:02
• @Jonas Yes, with det it would have been much harder – Luis Mendo Aug 13 '15 at 18:51

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

• Not quite, I get:  Hello World!tt... UsingPHP 5.4 if that makes a difference... I'll update the other with the version. – Dom Hastings Aug 12 '15 at 12:11

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.

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,[])))

• Very well done! How long did that take you to figure out? :) – rayryeng Aug 12 '15 at 22:46
• It took quite a while... but I see now that the main clue had already been given in Matlab's chat room ! – Luis Mendo Aug 12 '15 at 23:34

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

• 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. – Fatalize Aug 13 '15 at 5:17
• @Fatalize I really wish I've seen this earlier :P – mgibsonbr Aug 13 '15 at 5:47

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


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'];

• No worries - I had == in the for loop, but yeah 10/3 was a dead giveaway :) – Sp3000 Aug 13 '15 at 13:15
• Correct, I didn't notice this obvious solution. – Razvan Aug 13 '15 at 13:17

Pyth, Beta Decay

Description

This one's just obvious.

Code

.!10


77 -> 10

• Actually, I went for .!&77T. I guess I didn't really give it much thought ;) – Beta Decay Aug 14 '15 at 12:35

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)"%"}

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.

• 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. – Kade Aug 14 '15 at 18:49
• @Vioz- You'll get the hang of it! – Alex Van Liew Aug 14 '15 at 20:17

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

• Beat me by 30 seconds. – isaacg Aug 14 '15 at 19:54
• Dang it. I was hoping that trick was more obscure. Good job. – rp.beltran Aug 14 '15 at 19:56
• @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". – Alex Van Liew Aug 14 '15 at 20:20
• Fair point, and I figured it would get cracked pretty quickly. 2 people in 4 minutes though, I'm impressed. – rp.beltran Aug 14 '15 at 20:25

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.

• Yep, that's it... – The_Basset_Hound Aug 14 '15 at 20:01

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.

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.