8
\$\begingroup\$

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.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Who 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. \$\endgroup\$
    – Timtech
    Dec 30, 2014 at 14:07

9 Answers 9

3
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ You need to use all 13 edits, but that can easily be fixed by adding another character in the comment. \$\endgroup\$
    – Doorknob
    Dec 29, 2014 at 4:23
  • \$\begingroup\$ Dammit, I forgot comments were a thing :/ Originally I changed the range to start at 1 and removed the ~ ;P \$\endgroup\$ Dec 29, 2014 at 4:24
  • \$\begingroup\$ @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. \$\endgroup\$
    – Sp3000
    Dec 29, 2014 at 4:25
  • \$\begingroup\$ 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 ;) \$\endgroup\$ Dec 29, 2014 at 4:29
3
\$\begingroup\$

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]
\$\endgroup\$
1
  • \$\begingroup\$ On closer inspection, this is slightly different to the approach I originally had. Interesting... \$\endgroup\$
    – Sp3000
    Dec 29, 2014 at 15:29
3
\$\begingroup\$

J, grc

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

   f 45
1134903170
\$\endgroup\$
2
\$\begingroup\$

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)
\$\endgroup\$
0
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Yeah, I designed it from the wrong end (and posted it, until Sp3000 spotted it), so it looks a little weird. \$\endgroup\$
    – matsjoyce
    Dec 29, 2014 at 19:15
1
\$\begingroup\$

CJam by Martin Büttner

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

Takes input n from STDIN

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

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.

\$\endgroup\$
4
  • \$\begingroup\$ @MartinBüttner I do have 12. See the pointless argument to input. \$\endgroup\$
    – feersum
    Dec 29, 2014 at 22:59
  • \$\begingroup\$ Well... I believe this would output the !. Still accepting this as valid, you could put any chars in the comment, \$\endgroup\$ Dec 30, 2014 at 13:33
  • \$\begingroup\$ @Pietu1998 What's wrong with having a prompt on user input? \$\endgroup\$
    – feersum
    Dec 30, 2014 at 18:51
  • \$\begingroup\$ Nothing, but this is operationally different. \$\endgroup\$ Dec 30, 2014 at 19:26
1
\$\begingroup\$

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.

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

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