Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
4 of 10
Added a Levenshtein distance calculator.
  • 7k
  • 18
  • 47

Recover the mutated source code

In a very unusual accident involving a small sample of radium, an electrocuted whale, and three gummy bears, some of The Management™'s source code has been mutated. Little does The Management™'s boss know, it was actually the Cops© who had been responsible, in an attempt to thwart The Management™'s "evil" plans. So the Robbers® have been hired in an attempt to retrieve the original code, because who doesn't like being evil sometimes?

note: This challenge was heavily inspired by Unscramble the Source Code


This is a challenge.

  • The cops will write a program (the mutated code) that performs Task #1 (and also write a program that performs Task #2, but is kept secret).
  • The robbers will attempt to reverse the "mutation" and change this original code into code that performs Task #2.

In this challenge, Task #1 will be to output the nth prime number, and Task #2 will be to output the nth Fibonacci number (which is somehow evil, according to the Cops© anyway). The Fibonacci sequence is defined as (n=11; n=21; n=32; ...), and the prime numbers are defined as (n=12; n=23; n=35; ...).

The cops' goal is to minimize the difference between the programs that complete Task #1 and Task #2, while preventing the robbers from recreating the code that completes Task #2.

Cop Rules

The cops will write two programs (one that completes Task #1, and one that completes Task #2), and make the following information public:

  • The first program (that outputs the nth prime number)
  • The Levenshtein edit distance between the first program and the second program
  • The programming language that both programs are written in (must be the same language for both programs)

The following restrictions apply to both programs:

  • They must be 128 characters in length or less.
  • They must only use printable ASCII (plus newlines, which are also allowed).
  • They must take less than 10 seconds to run for n=45, and they are not required to produce the correct output for any n>45.
  • They must not use any hashing or cryptographic functions.

Robber Rules

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


If a cop's program remains uncracked for 1 week, the cop can post the original code that completes Task #2 (in the specified edit distance), and the submission is from then on considered "safe." The safe submission that has the smallest edit distance will win. In the event of a tie, the shortest program (the original that completes Task #1) wins. If two submissions are still tied, the one posted earlier wins.

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.


There are no submissions yet.

A small tool to compute the Levenshtein distance

var f=document.getElementById("f"),g=document.getElementById("s"); function h(){var a=f.value,e=g.value;if(128<a.length)a="<span style='color:red'>First program is too long!</span>";else if(128<e.length)a="<span style='color:red'>Second program is too long!</span>";else{if(0===a.length)a=e.length;else if(0===e.length)a=a.length;else{var d=[],b;for(b=0;b<=e.length;b++)d[b]=[b];var c;for(c=0;c<=a.length;c++)d[0][c]=c;for(b=1;b<=e.length;b++)for(c=1;c<=a.length;c++)d[b][c]=e.charAt(b-1)===a.charAt(c-1)?d[b-1][c-1]:Math.min(d[b-1][c-1]+1,Math.min(d[b][c-1]+1,d[b-1][c]+ 1));a=d[e.length][a.length]}a="Distance = <strong>"+a+"</strong>"}document.getElementById("d").innerHTML=a}f.onkeyup=h;g.onkeyup=h;
<h3 id=ft>First program</h3>
<textarea id=f rows=7 cols=80 style="width:100%"></textarea>
<h3 id=st>Second program</h3>
<textarea id=s rows=7 cols=80 style="width:100%"></textarea>
<p id=d></p>

  • 71.5k
  • 20
  • 143
  • 383