41
4
UPDATE : isaacg's Pyth submission is the winner!
Many of you must have heard that there is a cooler version of JavaScript in town (read ES6) which has a method String.prototype.repeat
so that you can do
"Hello, World!".repeat(3)
and get
"Hello, World!Hello, World!Hello, World!"
as the output.
Your job is to write a function or a program in a language of your choice which detects if a string has been gone under such transformation.
i.e. The input string can be represented as an exact n
times repetition of a smaller string. The output (as function's return statement or STDOUT) should be truthy if the string can be or falsy if the string cannot be represented as a repetition of smaller string.
Some sample input:
"asdfasdfasdf" // true
"asdfasdfa" // false
"ĴĴĴĴĴĴĴĴĴ" // true
"ĴĴĴ123ĴĴĴ123" // true
"abcdefgh" // false
Note that the last input is false, thus n
should be greater than 1
Complete rules
- Write a function/program in any language to input (via function argument/command line args/STDIN) a string
- Return/Print truthy value if the given string is formed via an exact repetition of a smaller string, repeating at least twice.
- Maximum size of the input string is ideally Infinity
- String can have all possible ASCII characters
- This is a code-golf so smallest code in characters wins.
What should "" - the empty string - return? (It contains an infinite number of copies of the empty string.) – billpg – 2014-09-17T13:29:00.587
@billpg falsy value – Optimizer – 2014-09-17T13:42:39.630
Are you tie-breaking by votes? The common practice is earlier submission I think (well, the first one that got golfed down to the tying score). But I'm not sure that's written down as the default tie-breaker anywhere, so ultimately it's up to you. – Martin Ender – 2014-09-17T16:54:28.193
Time between their posting is only 30 minutes. I will not consider that to be enough for winning :) . Since that time won't change now, but votes can, I went with votes – Optimizer – 2014-09-17T17:03:27.997
This question should be renamed into xnor :) He is the man! – Silviu Burcea – 2014-09-19T08:52:11.037