# Repeating terms of a given sentence [closed]

Program

Write a program to display repeating terms of a given sentence.

Explanation

The program must output the repeating terms of two or more letters from the given input (input is a sentence separated by spaces without any punctuation except the full-stop indicating the end.) Repeated terms may not span across or include a space. For example, if input is the sentence "I am an ameture mathemagician" the output must be am, ma, an. (note that "em" is not a valid output as it is separated by space).

Repeated terms may overlap with each other. For example if the input is "ababa", the output should include "aba", even though the two instances of it overlap.

ababa
aba
aba


Example

Input:

International competitions are better than intercollege ones.

Output:

Inter, ti, er, tion, io, on, ion, tio, co, on, .......etc (t, l must not be included as they are 1 letter.) (Upper lower Cases do not matter)

Test cases

aabcde cdec -> cde, cd, de

aab aacab -> aa, ab

aaa aabcaaa ababa -> aaa, aa, ab, aba, ba

abababa-> ab, aba, abab, ababa, ba, bab, baba


Winning Criterion

• I'm going to VTC because this isn't really clear enough. There's no point using the sandbox if you're not going to address the feedback. I'd recommend reading through the Things to avoid when writing challenges page. – pxeger Apr 13 at 9:42
• Suggested test case: abababa, which I think should result in ab, aba, abab, ababa, ba, bab, baba. BTW, can you confirm that overlapping matches must be taken into account? (This is the only way to match aba in the last test case.) – Arnauld Apr 13 at 10:31
• Note that adding test cases is not the same as adding explanation. Both are nice but the latter is what is needed to clarify a question. – Wheat Wizard Apr 13 at 12:29
• I've made some edits to clarify this based on your test cases. I can't be sure that this is what you meant, so feel free to roll back. But I would like this question to address the order of the outputted terms. Does the order matter? If it does matter what order should they be in? – Wheat Wizard Apr 13 at 12:39
• I think the case insensitivity should be mentioned in more than an example. I'd edit it myself, but I'm unclear what's intended. Can the output strings be in any case even if they don't appear in that form in the sentence? Might the input be capitalized in more than its first letter? You could also change it to be case sensitive instead or guarantee the input is lowercase. – xnor Apr 13 at 16:50

# JavaScript (ES10), 99 bytes

s=>new Set([...s].map((q,i,a,j=i)=>a.map(_=>s.lastIndexOf(q+=s[++i])>j&!/ /.test(q)?q:[])).flat(2))


Try it online!

# Python 3, 119 bytes

lambda s:{''.join(y) for x in range(2,len(s))for y in permutations(s,x)if s.count(''.join(y))>1}
from itertools import*


Try it online!

Extremely slow... Works by calculating permutations

• This is not matching aba in ababa and would therefore fail on the last test case. (Unless this test case is invalid and overlapping matches should not be taken into account.) – Arnauld Apr 13 at 10:33

# Japt-g, 14 bytes

ã køS fÅü lÉ y


Try it

• saved 4 thanks to @Shaggy
    ã       - substrings
køS     - remove if contains space
fÅ     - take longer than 1
ü       - sort and group
lÊ     - take groups longer than 1
y      - transpose
-g flag to return first element

• 15 bytes, with the -g flag: ã køS lÉ ü lÉ y – Shaggy Apr 13 at 22:00
• 14: ã køS fÅü lÉ y – Shaggy Apr 13 at 22:05
• Thanks a lot dude! I don't know why I though about the l-1 method but I didn't considered because of empty lists resulting in -1 hence not False o.O – AZTECCO Apr 14 at 12:43