Your boss has found out that quite a bunch of his employees (including you) like to steal code from others. He ordered you to write him a program that he can use to find people who steal code from others.


Write a program/function that detects if somebody copied (part of) his code from somewhere else.

The program will get all the existing programs and the program that it should test from two separate inputs. Edit: Since there are no answers so far, you may use regular expressions!


  • The program should then output all the stolen pieces of code, separated by either a space or a newline. (It may have a space or a newline at the end.)
  • A piece of code is considered to be stolen/copied if it consists of 10 or more successive bytes. (Sorry, Java fans!)
  • You have to output as much as possible, but if there are overlapping ones, you may ignore one of them or output both of them.


As mentioned before, you also love duct tape coding. That means, everything in your code will be copy-pasted from a stack exchange site! You can copy whatever you want (not limited to code in code blocks) and as much as you want. (But at least 10 bytes) (Same rule as above about what is considered to be stolen/copied.) (Please do note that any answers that were posted after this question may not be used.) Please provide links to where you got your code from.


x = document.getElementById("ninja'd"); (The first input)
y = document.getElementById("id"); (The second input)


 = document.getElementById("

foo (The first input)
foo+bar (The second input)


public static void main(String[] args) (The first input)
public static void main(String[] args) (The second input)


 main(String[] args)

for(var i=0; i<x.length; i++){} (The first input)
for(var i=0; i<oops.length; i++){break;} (The second input)


for(var i=0; i<
.length; i++){


for(var i=0; i< .length; i++){
  • 1
    \$\begingroup\$ It's missing rules for which strings can be copied and how (for the code). \$\endgroup\$
    – feersum
    Nov 23, 2015 at 18:27
  • 5
    \$\begingroup\$ Do the copied strings have to come from code blocks, or any parts of an SE answer? If it comes from a code block does it need to use the entire block, or can a substring be used? Can the strings come from either the formatted text or the Markdown source? Can code blocks newer than this question be used? Can old revisions of a question be used? \$\endgroup\$
    – feersum
    Nov 23, 2015 at 18:35
  • 3
    \$\begingroup\$ You say the substrings have to length 10 or more. Can I place a substring inside another substring? (Do the substrings have to be continuous?) \$\endgroup\$
    – Blue
    Nov 23, 2015 at 20:12
  • 1
    \$\begingroup\$ @sysreq I decided to allow regular expressions! \$\endgroup\$
    – Stefnotch
    Nov 24, 2015 at 17:45
  • 6
    \$\begingroup\$ Easy answer: Use Unary \$\endgroup\$
    – lirtosiast
    Nov 24, 2015 at 17:51

1 Answer 1


Python 2, 224 bytes

from difflib import SequenceMatcher
def similar(a, b):
    return SequenceMatcher(None, a, b).get_matching_blocks()
for start, _, size in similar(a, b):
 if(size > 9):
  print a[start:start+size]

Copied from this answer:

from difflib import SequenceMatcher
def similar(a, b):
    return SequenceMatcher(None, a, b).

get_matching_blocks() is copied from this answer


is copied from this question

for start, _, size in is copied from this answer and the second occurence of similar(a, b) is copied from the same place as the first.

if(size > 9) is copied from this question.


is copied from this question

a[start: is copied from this answer.

and finally, start+size] is copied from this questipn

Finally answered after one and a half years ...

  • \$\begingroup\$ +1 Though, stackoverflow.com/questions/37386311/… was posted after this challenge was posted. I decided to remove that restriction, so your answer is fine. :) \$\endgroup\$
    – Stefnotch
    Jul 13, 2017 at 15:36
  • 1
    \$\begingroup\$ @Stenfoch You don't need to; an earlier answer contains the same phrase \$\endgroup\$ Jul 13, 2017 at 16:14
  • 2
    \$\begingroup\$ One thing I learned about duct-tape-coding challenges: It is tricky to keep track of where you got all of your code. \$\endgroup\$ Jul 13, 2017 at 16:19
  • \$\begingroup\$ Wow, the score of this post has been rising very quickly ... \$\endgroup\$ Jul 14, 2017 at 22:49

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.