4
\$\begingroup\$

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

\$\endgroup\$
9
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – pxeger
    Apr 13 at 9:42
  • 1
    \$\begingroup\$ 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.) \$\endgroup\$
    – Arnauld
    Apr 13 at 10:31
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Wheat Wizard
    Apr 13 at 12:29
  • 2
    \$\begingroup\$ 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? \$\endgroup\$
    – Wheat Wizard
    Apr 13 at 12:39
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – xnor
    Apr 13 at 16:50
2
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ 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.) \$\endgroup\$
    – Arnauld
    Apr 13 at 10:33
1
\$\begingroup\$

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 
\$\endgroup\$
3
  • 1
    \$\begingroup\$ 15 bytes, with the -g flag: ã køS lÉ ü lÉ y \$\endgroup\$
    – Shaggy
    Apr 13 at 22:00
  • 1
    \$\begingroup\$ 14: ã køS fÅü lÉ y \$\endgroup\$
    – Shaggy
    Apr 13 at 22:05
  • \$\begingroup\$ 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 \$\endgroup\$
    – AZTECCO
    Apr 14 at 12:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.