[Question]
  [
Given a list of strings, replace each string by one of its non-empty substrings which is not a substring of any of the other strings in the list and as short as possible.
### Example
Given the list `["hello","hallo","hola"]`, `"hello"` should be replaced by just `"e"` as this substring is not contained in `"hallo"` and `"hola"` and it is as short as possible. `"hallo"` could be replaced by either `"ha"` or `"al"` and `"hola"` by any of `"ho"`, `"ol"` or `"la"`.
### Rules
* You can assume that the strings will be non-empty and only contain alphabetical characters of the same case.
* You can assume that such a substring exists for each string in the list, i.e. no string in the list will be a substring of any of the other strings.
* Input and output can be in any reasonable format.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so try to use as few bytes as possible in the language of your choice.
### Test Cases
Only one possible output is given for most cases.
```
["ppcg"] -> ["p"] (or ["c"] or ["g"])
["hello","hallo","hola"] -> ["e","ha","ho"]
["abc","bca","bac"] -> ["ab","ca","ba"]
["abc","abd","dbc"] -> ["abc","bd","db"]
["lorem","ipsum","dolor","sit","amet"] -> ["re","p","d","si","a"]
["abc","acb","bac","bca","cab","cba"] -> ["abc","acb","bac","bca","cab","cba"]
```
---
Related: [Shortest Identifying Substring](https://codegolf.stackexchange.com/questions/49704/shortest-identifying-substring) - similar idea, but more involved rules and cumbersome format.
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~12~~ 9 bytes
```
Ẇ€ŒpẇþÞ⁸Ḣ
```
**[Try it online!](https://tio.run/##y0rNyan8///hrrZHTWuOTip4uKv98L7D8x417ni4Y9H/w@3e//9HK2UAFeUr6ShlJELp/JxEpVgA "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8///hrrZHTWuOTip4uKv98L7D8x417ni4Y9H/w@1AUff//6OjlQoKktOVYnW4FKKVMoB68pV0lDISoXR@TiJUKjEpGSiQlJwIIhOTUUQTk1KAZEoSTDQnvyg1FyiSWVBcCqJT8oEiQLo4swSkOje1BFV7chLUUJgFyYkgkeQkoOWxAA "Jelly – Try It Online") (takes ~35s)
[Answer]
# [Pyth](https://pyth.readthedocs.io), 12 bytes
```
mhf!ts}LTQ.:
```
[Try it here!](https://pyth.herokuapp.com/?code=mhf%21ts%7DLTQ.%3A&input=%5B%22abc%22%2C%22abd%22%2C%22dbc%22%5D&test_suite=1&test_suite_input=%5B%22ppcg%22%5D%0A%5B%22hello%22%2C%22hallo%22%2C%22hola%22%5D%0A%5B%22abc%22%2C%22bca%22%2C%22bac%22%5D%0A%5B%22abc%22%2C%22abd%22%2C%22dbc%22%5D%0A%5B%22lorem%22%2C%22ipsum%22%2C%22dolor%22%2C%22sit%22%2C%22amet%22%5D%0A%5B%22abc%22%2C%22acb%22%2C%22bac%22%2C%22bca%22%2C%22cab%22%2C%22cba%22%5D&debug=0)
### How it works
Basicaly filters the substrings of each that only occur in one of the strings in the list (that is, it is unique to that string) and gets the first one.
```
mhf!ts}LTQ.:     Full program, Q=eval(stdin_input())
m         .:     Map over Q and obtain all the substrings of each.
  f              And filter-keep those that satisfy (var: T)...
      }LTQ       ... For each string in Q, yield 1 if it contains T, else 0.
   !ts           ... Sum the list, decrement and negate. 
 h               Head. Yields the first valid substring, which is always the shortest.
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~175~~ 163 bytes
```
S/L/R:-sub_string(S,_,L,_,R).
[H|T]+[I|R]:-string_length(H,L),between(1,L,X),H/X/I,T+R.
R+R.
L-R:-L+R,forall(member(E,L),findall(_,(member(F,R),\+ \+ E/_/F),[_])).
```
[Try it online!](https://tio.run/##fVDBisMgFLz3K0pOSl4ive5lTy0p5GR7KGSDqLGJYGIwll7679nn0p52t6AzMG/mOTgH73xfLHe7ridWM/5RLDcllhjs1JMTCKjxclpumupxbvPm@OAten7mwpmpjwOpoKagTLwbM5EdJi4UKnZhRzjnvNzwBHWBq@ucw9UH6RwZzahMIPsUvdqpS5qAl3zAJ@Er3@LZM8EOFBrRUlqun0WTzbPus7bgsL0HG42bSOqXJoNxzmeQDfLJ3sm/nVJpnCstE0r9ziRVh9ipf0zOBzOiwc7LLXGHHxqQFxtTeDTx7XKtng1ebbRMila/i6/f "Prolog (SWI) – Try It Online")
Most of the things here should be fairly obvious, but:
### Explanation
Signatures: (`+` = input, `?` = optional, `-` = output, `:` = expression)
* `sub_string(+String, ?Before, ?Length, ?After, ?SubString)`
* `string_length(+String, -Length)`
* `member(?Elem, ?List)`
* `between(+Low, +High, ?Value)`
* `findall(+Template, :Goal, -Bag)`
* `forall(:Cond, :Action)`
`\+ \+` is just `not not` (i.e. converts a match to boolean (in this case, prevents it from matching both `p`s in `ppcg` separately))
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 25 bytes
Thanks ngn for [saving](https://chat.stackexchange.com/transcript/message/48103605#48103605) one byte
```
⊃¨1↓≢~⍨/(,⍨(,∘↑⍳∘≢,/¨⊂)¨)
```
[Try it online!](https://tio.run/##TUw7DoJAEO09Bd1KgiEeaXYWkGTJbgQLGwtNCJCQaGysqbb3BnuUuQjOKiY07zfzHli9U2fQppjnnNo7DTfv9tQ@qZ8uNLp0mzAydC9qHzS@g@inJPWOhmvsXcy9iKWwFguxySNxyLQ2ghkWNhq@B5DIViIEBFxlIBWjkr9Mm2NWsS9tfQqsDCfMddmE3ypr1lWUy9x/GiEkKEF8AA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), ~~30 29~~ 25 bytes
```
1(|:(0{-.&,)"_1]\.)<\\.&>
```
[Try it online!](https://tio.run/##y/r/P81WT8FQo8ZKw6BaV09NR1Mp3jA2Rk/TJiZGT83uf2pyRr5CmoK6jnpyaYmCekZqTk6@TkYimMzPSVTnQlNQUJCcjiGYk1@UmquTWVBcmquTkg/k6RRnlugk5qaWqP//DwA)
```
                   <\\.&>        a 3-dimensional array of substrings
1 |:                             transpose each matrix to sort the substrings by length
1              ]\.               all choices where one word is missing
    (0{-.&,)"_1                  for every matrix, flatten, remove substrings
                                  that are present in the corresponding complement,
                                  pick first
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
Ẇ€ṙƬ1ḟ/Ḣ$€
```
[Try it online!](https://tio.run/##y0rNyan8///hrrZHTWse7px5bI3hwx3z9R/uWKQCFPh/uB1Iuv//Hx2tVFCQnK4Uq8OlEK2UAdSUr6SjlJEIpfNzEqFSiUnJQIGk5EQQmZiMIpqYlAIkU5Jgojn5Ram5QJHMguJSEJ2SDxQB0sWZJSDVuaklqNqTk6CGwixITgSJJCcBLY8FAA "Jelly – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 116 bytes
```
def f(a):g=lambda s,S:s not in`set(a)-{S}`[3:]and min(s,g(s[1:],S),g(s[:-1],S),key=len)or S;return[g(s,s)for s in a]
```
[Try it online!](https://tio.run/##VZBLbsMgFEXHzSreDFvCg7QzqnQTHiKkPD7@qBgQkEEUde0u4EZVRhydq3tBhHtevHvfd20mmDrs2XyxuEmNkOjIEjifYXXXZHIJh8f4c@UfTKDTsK2uS3TuEj8zQce@IRvOjb/N/WKN632E8TOafIuOl5ymfioqlUlAsVfGypwTREKBSEkEBU5CUPNBi7HW12jBJ3iLR4ZStZI6uqheNEpdDy3/tPXRbNWsId0aaF9chbTm1thMfp1Q8rn8f4/CJpUsrxDs9Bbi6jIgJcMXofUPT/sv "Python 2 – Try It Online")
[Answer]
# JavaScript (ES6), 93 bytes
```
a=>a.map(s=>(L=s.length,g=n=>a.every(S=>S==s|!~S.search(u=s.substr(n%L,n/L+1)))?u:g(n+1))(0))
```
[Try it online!](https://tio.run/##fU9Na8QgEL33V2yFgtJs0l4Lpn8gtxyXPYzGNSlGxTELhdK/nmo2JXTZ7cXnvI9h3gecAWUYfNxb16n5xGfgNZQjeIq8pg3H0iirY19obrOizip80pbXLef49fjdlqggyJ5OyYqTwBiofWoKWzXPr4yx9@lNU5u/9IWxWTqLzqjSOE1P9EC8l5ocGdtV1S5N5Phw7eiVMY4UpIcVnYEtoRZloW9kQcgkCZkNAuQWA5GYlb6bA9GltxN/csvCC38jaFxQYxIHj1PGziUmIQ4xLxxV3HaFfLvPpsWQ9funSLFW@K0jLxUEXB/3r3X@AQ "JavaScript (Node.js) – Try It Online")
### How?
For each string **s** of length **L** in the input array **a[ ]** and starting with **n = 0**, we use the recursive function **g()** to generate all substrings **u** of **s** with:
```
u = s.substr(n % L, n / L + 1)
```
For instance, with **s = "abc"** and **L = 3**:
```
 n | n%L | floor(n/L+1) | u
---+-----+--------------+-------
 0 |  0  |       1      | "a"
 1 |  1  |       1      | "b"
 2 |  2  |       1      | "c"
 3 |  0  |       2      | "ab"
 4 |  1  |       2      | "bc"
 5 |  2  |       2      | "c"
 6 |  0  |       3      | "abc"
 7 |  1  |       3      | "bc"
 8 |  2  |       3      | "c"
```
Some substrings are generated several times, but it doesn't matter. What's important is that all substrings of length **N** have been generated before any substring of length **N+1**.
We stop the process as soon as **u** cannot be found in any *other* string **S** in **a[ ]**, which is guaranteed to happen when **u == s** in the worst case, as per challenge rule #2:
> 
> *no string in the list will be a substring of any of the other strings*
> 
> 
> 
Therefore, in the above example, steps **7** and **8** will actually never be processed.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 107 bytes
```
($a=$args)|%{$(for($i=0;$i++-lt($g=($s=$_)|% Le*)){0..($g-$i)|%{$s|% s*g $_ $i}|?{!($a-match$_-ne$s)}})[0]}
```
[Try it online!](https://tio.run/##HYxBCsMgFAWvksIraIIh@yK9QG8QikhrE0Fr8Fu6SDz7r3Q5M7y3pa/LtLoQmAWshs0LyeO8Q7xSFvB6usAPgwpFYNECpGFa726ul3KfxrFpBf@fUPPULx1MB1@P635qlyra8lhh1NuBZK1ynu6VmUPKLrLf6BP5mRox@cI2uvID "PowerShell – Try It Online")
## Explanation
For each string supplied (and assign the whole array to `$a`):
* Do a `for` loop over each substring length (1 based) of the string (assigning the string itself to `$s` and the length to `$g`)
* For each length (`$i`):
	+ Make an index loop, from 0 to to length - `$i`, then for each index:
		- Get the substring of the current string (`$s`) at position `$_` (index) and of length `$i`
		- Pass that substring to `Where-Object` (`?`), and return it if:
			* The subset of array (`$a`) that does not contain the current string `$s`, does not have a match for the current substring `$_`
Back at the string level, we have all of the substrings of this string that were not found in the others, so take the first one `[0]` since we only need one of them, then continue with the next string.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 149 bytes
```
a=>a.Select(s=>{var t=s;for(int j=0,k,l=s.Length;j++<l;)for(k=-1;j+k++<l;)if(!a.Where(u=>s!=u&u.Contains(t=s.Substring(k,j))).Any())j=k=l;return t;})
```
[Try it online!](https://tio.run/##jY89a8MwEIb3/ArHQ5GII9rZkSGUFgodCil0KB1OsmzLliWjj5YS8ttdiaRLG0iWe7n3nvvibs2dnB@D5punBx1GYYEpsXHeSt1WxRmvypqMzkArIDuhBPfI0Wr/CTbz1JWNsUhqn/X0thgKRR15Frr1XdmvVhtV4lQf6Pou5sPRkQ1aAnnrhBUo0MotabgJ5N5oD1I7FIeSXWDH5Wgoeowx2epvhHFPB6pKK3ywOvPlAc/lYvESOY8apMXX@8c@nybe5gdMXs3WWkhd/5lOKGXyIu/gpEbBpR5gPJKMQ4rAr8OB1THW7CKujBVjROXkQtLaRCeqkz6NGYW/ciFnp/t@b@WQHM7@Pjj/AA "C# (Visual C# Interactive Compiler) – Try It Online")
Less golfed...
```
// a is an input array of strings
a=>
  // iterate over input array   
  a.Select(s=>{
    // t is the result string
    var t=s;
    // j is the substring length
    for(int j=0,k,l=s.Length;j++<l;)
      // k is the start index
      for(k=-1;j+k++<l;)
        // LINQ query to check if substring is valid
        // the tested string is collected in t
        if(!a.Where(u=>s!=u&u.Contains(t=s.Substring(k,j))).Any())
          // break loops
          j=k=l;
    // return result
    return t;
  })
```
]