[Question]
  [
Given a string as argument, output the length of the longest(s) non-overlapping repeated substring(s) or zero if there is no such string.
You can assume the input string is not empty.
## Examples
`abcdefabc` : the substring `abc` is repeated at positions 1 and 7, so the program should output **3**
`abcabcabcabcab` : `abcabc` or `bcabca` or `cabcab` are repeated, so the program should output **6**. (the substring `abcabcabcab` is also repeated, but the occurrences overlap, so we don't accept it).
`aaaaaaa` : `aaa` is repeated at positions 1 and 4 for example, so the program should output **3**
`abcda` : `a` is repeated, so the program should output **1**
`xyz` : no repeated string → **0**
`ababcabcabcabcab` : should return **6**
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so fewest bytes wins.
  
[Answer]
## brainfuck, 226 bytes
```
,[<<<,]+[>>->[[[[>>[>>>]<+<-<[<<<]>>+<-]>[<+>-]>[>>>]<<[>[<+>-]]>[[<+>-]>+[<<<]>
>>-[+>[<<<]<[>+>[->]<<[<]>-]>[<+>>+<-]>>>[>>>]]>>]<]>+[,<<<+]->[<<<]>>>>>+[,+>>>
+]-[>>>]->]<[+<<<]+<<<++[->>>]+>>>->]<[,<<<]<[>>>+<<<-]>+>,>>>]<<.
```
Formatted:
```
,[<<<,]
+
[
  for each suffix
  >>->
  [
    for each prefix
    [
      for each suffix
      [
        for each char while no mismatch
        [
          >>[>>>]
          <+<-<[<<<]
          > >+<-
        ]
        >[<+>-]
        >[>>>]
        <<
        [
          mismatch
          >[<+>-]
        ]
        >
        [
          [<+>-]
          >+[<<<]
          >>>-
          [
            match
            +>[<<<]
            <
            [
              >+>[->]
              <<[<]
              >-
            ]
            >[<+> >+<-]
            >>>[>>>]
          ]
          >>
        ]
        <
      ]
      >+[,<<<+]
      ->[<<<]
      >>> >>+[,+>>>+]
      -[>>>]
      ->
    ]
    <[+<<<]
    +<<<++[->>>]
    +>>>->
  ]
  <[,<<<]
  <[>>>+<<<-]
  >+>,>>>
]
<<.
```
Expects input with or without a trailing newline, and outputs the result as a [byte value](http://meta.codegolf.stackexchange.com/questions/4708/can-numeric-input-output-be-in-the-form-of-byte-values/4719#4719).
[Try it online.](http://brainfuck.tryitonline.net/#code=LFs8PDwsXStbPj4tPltbW1s-Pls-Pj5dPCs8LTxbPDw8XT4-KzwtXT5bPCs-LV0-Wz4-Pl08PFs-WzwrPi1dXT5bWzwrPi1dPitbPDw8XT4-Pi1bKz5bPDw8XTxbPis-Wy0-XTw8WzxdPi1dPls8Kz4-KzwtXT4-Pls-Pj5dXT4-XTxdPitbLDw8PCtdLT5bPDw8XT4-Pj4-K1ssKz4-PitdLVs-Pj5dLT5dPFsrPDw8XSs8PDwrK1stPj4-XSs-Pj4tPl08Wyw8PDxdPFs-Pj4rPDw8LV0-Kz4sPj4-XTw8Lg&input=YWJjZGVmYWJj&debug=on)
This checks each prefix to see whether it occurs later in the string, then chops off the first character and repeats the process until there are no more characters left.
The tape is divided into 3-cell nodes,
`c 0 f`
where `c` is a character of the given string, and `f` is a flag that can be either one, negative one, or zero. Nonzero flags are placed between the two characters currently being compared, and negative ones are reserved for the cells after the end of the current prefix and before the beginning of the current suffix (i.e., before the index of the current potential match).
The result is stored to the left of the string and is updated whenever a match is found.
(The string is actually processed in reverse with a `\x01` appended to it.)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
œ-QL€
ŒṖÇ€FṀ
```
[Try it online!](https://tio.run/nexus/jelly#@390sm6gz6OmNVxHJz3cOe1wO5Dp9nBnw/@Hu7eAOZH//ycmJaekpgFJLiBGQlyJEAASTknkqqisArJQlQAA "Jelly – TIO Nexus")
### How it works
```
ŒṖÇ€FṀ  Main link. Argument: s (string)
ŒṖ      Generate all partitions of s.
  Ç€    Apply the helper link to each partition.
    F   Flatten the resulting array of lengths.
     Ṁ  Take the maximum.
œ-QL€   Helper link. Argument: P (partition)
  Q     Yield the elements of P, deduplicated.
œ-      Multiset subtraction; remove exactly one occurrence of each string in P.
   L€   Compute the lengths of the remaining strings. 
```
[Answer]
# [Perl 6](https://perl6.org), 36 bytes
```
{m:ex/(.*).*$0/.map(*[0].chars).max}
```
[Try it](https://tio.run/nexus/perl6#ZVBLboMwEN37FG@BKiCpQ1Upi7jkFN2lWbi2QyyBQRhaaESvTocAVaVa1mjm/axx6w0@9lwJ1lL3anwjWJVLh1gwVvR4UKU2SMdbcTDdLuRxxOMg2fFCVmF8Ss5cXWXtI5q7YbyUNXLrjA8j3BhQ4OBt5iupzH0GghfrqrY5AilOb5/xeUFr49uc4AnVmwkd6H1K6BHcHcR8r2axELOJmM1vwEpp4xUR4WzmlalzpMfVEvHMTouS2HpMGy7CaLtKtnOGYAPTpTOPDf2MdZkY5bvS5kIVz4zqn4s9k/OZKS3xxLr@CwlN/6RIfgA "Perl 6 – TIO Nexus")
## Expanded:
```
{   # bare block lambda with implicit parameter ｢$_｣
  m           # match ( implicitly against ｢$_｣
  :exhaustive # every possible way
  /
    (.*)      # any number of characters ( stored in ｢$0｣ )
    .*
    $0
  /
  .map(
    *\        # the parameter to Whatever lambda
    [0]\      # the value that was in ｢$0｣ for that match
    .chars    # the number of characters
  ).max
}
```
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~35~~ ~~32~~ 30 bytes
Pretty cool challenge.
```
M&!`(.*)(?=.*\1)
M%`.
O#^`
G1`
```
[**Try it online**](https://tio.run/nexus/retina#@@@rppigoaelqWFvq6cVY6jJ5auaoMflrxyXwOVumPD/f2JSYlIyEgIA)
**Explanation:**
```
M&!`(.*)(?=.*\1)    # Prints overlapping greedy substrings occuring more than once
M%`.                # Replace each line with its length
O#^`                # Sort lines by number in reverse
G1`                 # Return the first line
```
[Answer]
## JavaScript (ES6), ~~79~~ ~~68~~ 66 bytes
```
f=(s,r,l=s.match(/(.*).*\1/)[1].length)=>s?f(s.slice(1),l<r?r:l):r
```
```
<input oninput=o.textContent=f(this.value)><pre id=o>
```
Edit: Saved ~~11~~ 13 bytes thanks to @Arnauld.
[Answer]
# [Haskell](https://www.haskell.org/), 79 bytes
```
(""%)
(a:b)!(c:d)|a==c=1+b!d
_!_=0
a%c@(e:d)=maximum[a!c,""%d,(a++[e])%d]
_%_=0
```
[Try it online!](https://tio.run/##HYtLCsIwGAb3uUWCgYRU0G3hB@9RS/jy0mBTglXowrMbg7OdmTu2R1yWlujalBBSM4XRaa78GPQHRJ7OxvHALLd0YpD@omJXVLDn8i4TuB/6FwYFY6Y4axlmZmWPW0FeqT7z@jok4QDs@CPa16cFt60dfa0/ "Haskell – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), ~~75~~ 72 bytes
```
f=lambda s,n=0:s[n:]and max(n*(s[:n]in s[n:]),f(s,n+1))or n and f(s[1:])
```
[Try it online!](https://tio.run/nexus/python3#VY7BCsIwDEDP@hW5lDa6ib14KMwfKTt01kJhi2PZYfrzNdWLhiSElwdJSd0YpiEG4Ia6s2NPrg8UYQqboYNh76jPBB@OTTKiHS3iYwGC6gnxVlYlCWIQVYfhFu9JOkj9JIRvVCwHt@dLpn9Fn3ge82rQ7Xfzkmk1WrX2wtBeQUUNCuSBehMRyxs "Python 3 – TIO Nexus")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
L►L§fo↓2`xQ
```
[Try it online!](https://tio.run/##yygtzv7/3@fRtF0@h5an5T9qm2yUUBH4//9/pcSkxKRkJKQEAA "Husk – Try It Online")
Note: Husk is newer than this challenge.
## Explanation
```
L►L§fo↓2`xQ  Implicit input, say x = "ababc"
          Q  Nonempty substrings: ["a","b","ab",..,"ababc"]
    f        Keep those that satisfy this:
              Take s = "ab" as an example.
   §    `x    Split x along s: ["","","c"]
     o↓2      Drop the first two pieces: ["c"]
              This is truthy (i.e. nonempty).
             Result is ["a","b","ab","a","b","ab"]
 ►L          Take element with maximal length: "ab"
             If the list is empty, "" is used instead.
L            Length: 2
```
[Answer]
#  JavaScript, 120
```
function r(a,b,m){return b=-~b,t=a.slice(0,b),n=a.indexOf(t,b),m=b>m&&!~n?m:b,a!=t&&r(a,b,m)||(a?r(a.slice(1),m,m):~-m)}
```
[Answer]
## [Perl 5](https://www.perl.org/) with `-p`, 40 bytes
```
$_+=(sort map{y///c}/(?=(.+).*\1)/g)[-1]
```
[Try it online!](https://tio.run/##K0gtyjH9/18lXttWozi/qEQhN7GgulJfXz@5Vl/D3lZDT1tTTyvGUFM/XTNa1zD2///EpOSU1DQgyQXESIgrEQJAwimJXBWVVUAWqpJ/@QUlmfl5xf91C3IA "Perl 5 – Try It Online")
[Answer]
# Mathematica, ~~75~~ 65 bytes
*10 bytes saved due to [@JingHwan Min](http://ppcg.lol/users/60043).*
```
Max@StringLength@StringCases[#,a___~~___~~a___:>a,Overlaps->All]&
```
Anonymous function. Takes a string as input, and returns a number as output.
[Answer]
# Pyth - 16 bytes
I need to golf the converting all the strings to lengths and finding the max.
```
eSlM+ksmft/dTd./
```
[Test Suite](http://pyth.herokuapp.com/?code=eSlM%2Bksmft%2FdTd.%2F&test_suite=1&test_suite_input=%22abcdefabc%22%0A%22aaaaaaa%22%0A%22abcda%22%0A%22xyz%22%0A%22ababcabcabcabcab%22&debug=0).
[Answer]
**Clojure, 112 bytes**
```
#(apply max(for[R[(range(count %))]j R i R](let[[b e](split-at i(drop j %))](if((set(partition i 1 e))b)i 0)))))
```
loops twice over numbers `0` to `n - 1` (`n` being length of the string), drops `j` characters and splits the remainder into "beginning" and "end" parts. Creates a set of all substrings at `e` of length `b` and uses it as a function to check if `b` is found from there. Returns the length of `b` if found and 0 otherwise, returns the max of these values.
Would be interesting to see a shorter version.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 24 bytes
```
L$v`(.*).*\1
$.1
N`
G-1`
```
[Try it online!](https://tio.run/##K0otycxLNPyvquGe8N9HpSxBQ09LU08rxpBLRc@Qyy@By13XMOH//8Sk5JTUNCDJBcRIiCsRAkDCKYlcFZVVQBaqEgA "Retina – Try It Online")
A warmup for me to learn the new features of Retina 1.
### Explanation
```
L$v`(.*).*\1
$.1
```
A List stage, this returns all the matches for the regex `(.*).*\1`, wich matches any pattern of the form "ABA", where A and B are two arbitrary substrings (possibly empty). The additional options given to this stage are `v`, which considers overlapping matches, and `$` which applies a substitution to each of the matches before returning it: the substitution is indicated in the second line, and corresponds to the length (`.`) of the first capturing group (which would be the substring "A" in the previous example).
```
N`
```
We now have all the lengths of repeated substrings, this stage simply sorts them in numerical order, from the shortest to the longest.
```
G-1`
```
Finally, this grep stage (`G`) keeps only the last (`-1`) result, which is the length of the longest repeated substring.
[Answer]
## Javascript, 165 bytes
```
function a(s){var l=s.length/2,z=1,f='';while(z<=l){var t=s.substr(0,z),c=0;for(var i=0;i<s.length;i++){if(s.substr(i,z)===t){c++;if(c>1){f=t}}}z++}return f.length}
```
Test Cases
```
console.log(a('abcabcabcabc')) // Output 6
console.log(a('xyz'))          // Output 0
console.log(a('aaaaaaa'));     // Output 3
console.log(a('abcdefabc'));   // Output 3
```
]