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.