Recover the mutated source code (for robbers)

8

This is the companion thread to the main Recover the mutated source code (link) challenge. If you have successfully cracked a cop's answer, post your solution as an answer to this question.

As a reminder, here are the robber rules from the main challenge again:

The robber will attempt to change the cop's program (which completes Task #1) into a program that completes Task #2 (not necessarily the original program written by the cop) in the edit distance specified by the cop.

An already-cracked submission cannot be cracked again (only the first robber who cracks a submission gets credit).

After cracking a submission, please do the following:

  • Post an answer to this challenge's accompanying question (link), providing the language, your solution, and a link to the original answer.
  • Leave a comment with the text "Cracked" that links to your posted answer.
  • Edit the cop's answer if you have edit privileges (if you do not, either wait until someone else with the required privileges does so for you or suggest an edit).

And scoring:

If a robber successfully cracks a cop's submission, the robber's score goes up by the edit distance of that submission. For example, a robber that cracks a submission with an edit distance of 3 and one with a distance of 5 earns 8 points. The robber with the highest score wins. In the event of a tie, the robber who earned the score first wins.

Leaderboard

There are no cracked submissions yet.

Doorknob

Posted 2014-12-29T02:37:38.453

Reputation: 68 138

2Who is maintaining the leaderboard? And also, I think reader's score should go up more if the distance is less, since that would seem harder to me. – Timtech – 2014-12-30T14:07:14.843

Answers

3

Python 2, FryAmTheEggman

x=n=1;j=input();
while j>2:
    x,n=n,x+n;j-=1;
    ##while~-all(n%i for i in range(2,n)):n+=1;
print n

Used 12 edits. Put in an extra # to make it 13.

Sp3000

Posted 2014-12-29T02:37:38.453

Reputation: 58 729

You need to use all 13 edits, but that can easily be fixed by adding another character in the comment. – Doorknob – 2014-12-29T04:23:09.523

Dammit, I forgot comments were a thing :/ Originally I changed the range to start at 1 and removed the ~ ;P – FryAmTheEggman – 2014-12-29T04:24:11.233

@FryAmTheEggman If you want no comments, you can change the range to be from n to n, so that the all evaluates to True. But ~-True is False, so the while won't run. – Sp3000 – 2014-12-29T04:25:17.287

I didn't "want" no comments, it just made this much easier than I thought it would be. Besides that, that is a much neater idea than what I came up with ;) – FryAmTheEggman – 2014-12-29T04:29:39.403

3

Python 2, Sp3000

from fractions import*
n=input()
k,=P=[1]
while n>len(P):k+=1;z=reduce(lambda x,y:x+y,P[~1:]);P+=[z]#*(gcd(z,k)<2)
print P[-1]

feersum

Posted 2014-12-29T02:37:38.453

Reputation: 29 566

On closer inspection, this is slightly different to the approach I originally had. Interesting... – Sp3000 – 2014-12-29T15:29:05.543

3

J, grc

   f=:3 :'{.+/(!|.)i.y'

   f 45
1134903170

randomra

Posted 2014-12-29T02:37:38.453

Reputation: 19 909

2

Python 3, Sp3000

x=n= int(input())       # 3
P = [1,1]               #+2 = 5
k = 2
while n >=len(P):       #+1 = 6
 k += 1
 for x in P:
  if k%x ==~0: break    #+1 = 7
 else: P += [P[-2]+x]   #+7 = 14
print(x)

feersum

Posted 2014-12-29T02:37:38.453

Reputation: 29 566

1

Python 3, matsjoyce

a,c,n=1,1,int(input())
while n-1:
 #c+=1
 ##########list(map(c.__mod__,range(2,46))).count(0):
 a,c=a+c,a
 n-=1
print(c)

The Fibonacci program was strangely already in there...only needed 5 edits to get it.

feersum

Posted 2014-12-29T02:37:38.453

Reputation: 29 566

Yeah, I designed it from the wrong end (and posted it, until Sp3000 spotted it), so it looks a little weird. – matsjoyce – 2014-12-29T19:15:38.793

1

JAGL, globby

T~2]d]2C{cSdc+c]}wSP

It might not be the most efficient approach, it it is almost definitely not the Cop's code, but it works, and its 12 away.

matsjoyce

Posted 2014-12-29T02:37:38.453

Reputation: 1 319

1

CJam by Martin Büttner

T1l~({_2$+}*p];

Takes input n from STDIN

Optimizer

Posted 2014-12-29T02:37:38.453

Reputation: 25 836

1

Python 2, Pietu1998

f=lambda p,i:p if p[45:]else f(p+[i]#f all(i%q for q in p[1:])else
,p[-1]+i)
print f([1,1,1],2)[input('!')]

I used 9 edits to get a Fibonacci program.

feersum

Posted 2014-12-29T02:37:38.453

Reputation: 29 566

@MartinBüttner I do have 12. See the pointless argument to input. – feersum – 2014-12-29T22:59:45.147

Well... I believe this would output the !. Still accepting this as valid, you could put any chars in the comment, – PurkkaKoodari – 2014-12-30T13:33:06.960

@Pietu1998 What's wrong with having a prompt on user input? – feersum – 2014-12-30T18:51:11.733

Nothing, but this is operationally different. – PurkkaKoodari – 2014-12-30T19:26:55.943

1

Ruby, histocrat

p [x=1,y=1,*(1..200).map{|i|z=y;y+=(y*x**(i-1)+x%2).divmod(i)[2-1]?x:1;x=z;y}].-([x-1])[gets.to_i-1]

Vectorized

Posted 2014-12-29T02:37:38.453

Reputation: 3 486