20
1
A string of characters repeats if it contains two consecutive substrings that are equivalent.
For example, 2034384538452
repeats as it contains 3845
twice, consecutively.
Therefore, your challenge is to decide whether a string contains a repeating substring. You may take the input as a string or an array of characters.
You will never receive an empty input, and the length of the substring (if it exists) may be 1 or more.
I use 1
and 0
here as my truthy and falsy values, but you may use different values, as long as they are truthy and falsy in your language.
Examples:
abcab -> 0
bdefdefg -> 1
Hello, World! -> 1
pp.pp/pp -> 1
q -> 0
21020121012021020120210121020121012021012102012021020121012021020120210121020120210201210120210121020121012021020120210121020121012021012102012021020121012021012102012101202102012021012102012021020121012021020120210121020121012021012102012021020121012021020120210121020120210201210120210121020121012021020120210121020120210201210120210201202101210201210120210121020120210201210120210121020121012021020120210121020121012021012102012021020121012021020120210121020120210201210120210121020121012021020120 -> 0
(The last example was generated from the amount of ones between each zero in the Thue-Morse sequence)
2Can I use inconsistent values, as long as they're still appropriately truthy or falsey? – Erik the Outgolfer – 2017-06-10T10:18:00.673
@EriktheOutgolfer Of course – Okx – 2017-06-10T10:22:18.533
@trichoplax I think he means consecutive subsequences of length >= 1. – Erik the Outgolfer – 2017-06-10T10:31:49.450
@EriktheOutgolfer "consecutive" was the word I missed. Thank you - it makes perfect sense now. – trichoplax – 2017-06-10T10:33:37.843
Can we output 1 for falsey and 0 for truthy instead? – user41805 – 2017-06-10T10:57:22.310
@KritixiLithos Only if it's truthy and falsy in your language. – Okx – 2017-06-10T11:01:32.187
I'm surprised this isn't a dupe. – Shaggy – 2017-06-10T11:12:58.217
@Shaggy, so am I, but it doesn't seem to be. – Gryphon – 2017-06-10T12:27:52.587
Why is the last one falsey? It contains
210
repeatedly. – spraff – 2017-06-10T14:22:18.913@spraff But not consecutively. – Okx – 2017-06-10T14:25:15.143
I'm not sure I understand. Does subsequence mean non-empty substring? Does consecutive mean adjacent? – Dennis – 2017-06-10T14:43:15.123
@Dennis Consecutive means adjacent. Sub-sequence means non-empty sub-string. – Okx – 2017-06-10T14:58:17.237
@Gryphon, I was thinking in the broader terms of "Execute a RegEx test in your chosen language". – Shaggy – 2017-06-10T20:07:00.393
Can we assume printable ASCII? – Titus – 2017-06-10T21:15:10.263
@Titus Yes, that would make sense. – Okx – 2017-06-11T07:49:59.147