Check if a string is entirely made of the same substring












24












$begingroup$


This is taken from this question (with permission ofcourse). I'll quote:




Create a function which takes a string, and it should return true or
false based on whether the input consists of only a repeated character
sequence. The length of given string is always greater than 1 and the
character sequence must have at least one repetition.




Some examples:



'aa' //true
'aaa' //true
'abcabcabc' //true
'aba' //false
'ababa' //false
'weqweqweqweqweqw' // false


Specifically, the check for a string strictly composed of repeating substrings (Update) can output any true or false representation, but no error output please. Strictly alphhanumeric strings. Otherwise standard code golf rules. Shortest answer in bytes for each language wins.










share|improve this question











$endgroup$








  • 3




    $begingroup$
    Hm, I was going to close this challenge as a dupe of that one, but I noticed that the other one scores on character count. So maybe we should close the other one (it also has an accepted answer) as a dupe of this one instead.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:14










  • $begingroup$
    Let us continue this discussion in chat.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:36
















24












$begingroup$


This is taken from this question (with permission ofcourse). I'll quote:




Create a function which takes a string, and it should return true or
false based on whether the input consists of only a repeated character
sequence. The length of given string is always greater than 1 and the
character sequence must have at least one repetition.




Some examples:



'aa' //true
'aaa' //true
'abcabcabc' //true
'aba' //false
'ababa' //false
'weqweqweqweqweqw' // false


Specifically, the check for a string strictly composed of repeating substrings (Update) can output any true or false representation, but no error output please. Strictly alphhanumeric strings. Otherwise standard code golf rules. Shortest answer in bytes for each language wins.










share|improve this question











$endgroup$








  • 3




    $begingroup$
    Hm, I was going to close this challenge as a dupe of that one, but I noticed that the other one scores on character count. So maybe we should close the other one (it also has an accepted answer) as a dupe of this one instead.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:14










  • $begingroup$
    Let us continue this discussion in chat.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:36














24












24








24


5



$begingroup$


This is taken from this question (with permission ofcourse). I'll quote:




Create a function which takes a string, and it should return true or
false based on whether the input consists of only a repeated character
sequence. The length of given string is always greater than 1 and the
character sequence must have at least one repetition.




Some examples:



'aa' //true
'aaa' //true
'abcabcabc' //true
'aba' //false
'ababa' //false
'weqweqweqweqweqw' // false


Specifically, the check for a string strictly composed of repeating substrings (Update) can output any true or false representation, but no error output please. Strictly alphhanumeric strings. Otherwise standard code golf rules. Shortest answer in bytes for each language wins.










share|improve this question











$endgroup$




This is taken from this question (with permission ofcourse). I'll quote:




Create a function which takes a string, and it should return true or
false based on whether the input consists of only a repeated character
sequence. The length of given string is always greater than 1 and the
character sequence must have at least one repetition.




Some examples:



'aa' //true
'aaa' //true
'abcabcabc' //true
'aba' //false
'ababa' //false
'weqweqweqweqweqw' // false


Specifically, the check for a string strictly composed of repeating substrings (Update) can output any true or false representation, but no error output please. Strictly alphhanumeric strings. Otherwise standard code golf rules. Shortest answer in bytes for each language wins.







code-golf decision-problem






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 1 at 7:40







ouflak

















asked Apr 24 at 14:55









ouflakouflak

3201416




3201416








  • 3




    $begingroup$
    Hm, I was going to close this challenge as a dupe of that one, but I noticed that the other one scores on character count. So maybe we should close the other one (it also has an accepted answer) as a dupe of this one instead.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:14










  • $begingroup$
    Let us continue this discussion in chat.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:36














  • 3




    $begingroup$
    Hm, I was going to close this challenge as a dupe of that one, but I noticed that the other one scores on character count. So maybe we should close the other one (it also has an accepted answer) as a dupe of this one instead.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:14










  • $begingroup$
    Let us continue this discussion in chat.
    $endgroup$
    – Erik the Outgolfer
    Apr 24 at 15:36








3




3




$begingroup$
Hm, I was going to close this challenge as a dupe of that one, but I noticed that the other one scores on character count. So maybe we should close the other one (it also has an accepted answer) as a dupe of this one instead.
$endgroup$
– Erik the Outgolfer
Apr 24 at 15:14




$begingroup$
Hm, I was going to close this challenge as a dupe of that one, but I noticed that the other one scores on character count. So maybe we should close the other one (it also has an accepted answer) as a dupe of this one instead.
$endgroup$
– Erik the Outgolfer
Apr 24 at 15:14












$begingroup$
Let us continue this discussion in chat.
$endgroup$
– Erik the Outgolfer
Apr 24 at 15:36




$begingroup$
Let us continue this discussion in chat.
$endgroup$
– Erik the Outgolfer
Apr 24 at 15:36










40 Answers
40






active

oldest

votes













1 2
next












11












$begingroup$


Brachylog, 4 3 bytes



ġ=Ṁ


Try it online!



Explanation



ġ=Ṁ    Implicit input, say "abcabc"
ġ Split into chunks of equal lengths (except maybe the last one): ["abc","abc"]
= Apply the constraint that all of the chunks are equal,
Ṁ and that there are multiple of them.


The program prints true. if the constraints can be satisfied, and false. if not.






share|improve this answer











$endgroup$













  • $begingroup$
    I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago
    $endgroup$
    – Unrelated String
    Apr 24 at 21:27






  • 4




    $begingroup$
    Oh, yeah, this could be one byte shorter: ġ=Ṁ
    $endgroup$
    – Unrelated String
    Apr 24 at 21:36










  • $begingroup$
    ( is a variable constrained to be a list of two or more elements)
    $endgroup$
    – Unrelated String
    Apr 24 at 21:39






  • 1




    $begingroup$
    @UnrelatedString Great, thanks! I didn't think to check the variables wiki page.
    $endgroup$
    – Zgarb
    Apr 25 at 9:12






  • 1




    $begingroup$
    A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.
    $endgroup$
    – ouflak
    May 1 at 6:40



















19












$begingroup$

JavaScript (ES6), 22 bytes



Returns a Boolean value.





s=>/^(.*)1+$/.test(s)


Try it online!





Without a regular expression,  33  29 bytes



Returns either null (falsy) or an object (truthy).





s=>(s+s).slice(1,-1).match(s)


Try it online!



NB: Technically, $s$ is converted to a regular expression for match(), so the above title is a lie.






share|improve this answer











$endgroup$





















    9












    $begingroup$

    grep, 19



    grep -qxE '(.+)1+'


    Test



    while read; do 
    <<<"$REPLY" grep -qxE '(.+)1+' && t="true" || t="false"
    echo "$REPLY: $t"
    done < infile


    Output:



    aa: true
    aaa: true
    abcabcabc: true
    aba: false
    ababa: false
    weqweqweqweqweqw: false





    share|improve this answer











    $endgroup$





















      9












      $begingroup$


      Japt, 6 bytes



      ²é ¤øU


      Saved one byte thanks to @Shaggy



      Try it online!



              Implicit input, stored in variable 'U'
      ² U+U, "abcabc" -> "abcabcabcabc"
      é Rotate 1 char to the right "abcabcabcabc" -> "cabcabcabcab"
      ¤ Remove first two chars, "cabcabcabcab" -> "bcabcabcab"
      øU Check if U is in the above





      share|improve this answer











      $endgroup$













      • $begingroup$
        Nice one :) You can replace the p<space> with ² to save a byte.
        $endgroup$
        – Shaggy
        Apr 24 at 16:25



















      9












      $begingroup$

      Java, 25 24 bytes



      -1 byte thanks to Olivier Grégoire!

      Boring regex answer



      s->s.matches("(.+)\1+")


      Try it online!

      It's just 1 byte longer than the python answer aaaaa I'm tied now :)






      share|improve this answer











      $endgroup$









      • 3




        $begingroup$
        You can remove the final $ as the matches method is an exact match, not a substring match by default.
        $endgroup$
        – Olivier Grégoire
        Apr 24 at 23:18










      • $begingroup$
        I forgot matches adds its own $ to the regex. Thanks!
        $endgroup$
        – Benjamin Urquhart
        Apr 24 at 23:34



















      7












      $begingroup$

      Excel, 26 bytes



      =FIND(A1,A1&A1,2)<=LEN(A1)


      Inputs from A1, outputs to whatever cell you put this formula.






      share|improve this answer









      $endgroup$













      • $begingroup$
        You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.
        $endgroup$
        – i_saw_drones
        Apr 24 at 18:54










      • $begingroup$
        @i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.
        $endgroup$
        – Sophia Lechner
        Apr 24 at 20:17












      • $begingroup$
        Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)
        $endgroup$
        – i_saw_drones
        Apr 24 at 23:05






      • 1




        $begingroup$
        I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.
        $endgroup$
        – Sophia Lechner
        Apr 25 at 17:03





















      6












      $begingroup$


      Retina 0.8.2, 9 bytes



      ^(.+)1+$


      Try it online! Link includes test cases.






      share|improve this answer









      $endgroup$





















        6












        $begingroup$


        Jelly,  5  4 bytes



        I see now that the optimal way is to follow xnor's method!



        Ḋ;Ṗw


        A monadic Link that accepts a list of characters and outputs an integer - the shortest possible length of a repeating slice or zero if none exists. Note that zero is falsey while non-zero numbers are truthy in Jelly.



        Try it online!



        How?



        Ḋ;Ṗw - Link: list of characters, S   e.g. "abcabcabc"   or "abababa"
        Ḋ - dequeue S "bcabcabc" "bababa"
        Ṗ - pop from S "abcabcab" "ababab"
        ; - concatenate "bcabcabcabcabcab" "bababaababab"
        w - first index of sublist 3 ^---here! 0 (not found)





        share|improve this answer











        $endgroup$





















          6












          $begingroup$


          R, 28 bytes





          grepl("(.+)\1+$",scan(,''))


          Try it online!



          Simple Regex version. R is (sometimes) very similar to Python, so this is similar to TFeld's Python 2 regex answer, albeit shorter!



          Question (if anyone knows the answer)



          I am still confused why this works, as the substring can be any length and will always work, and still works when I add a letter to the front of a valid string, like "cABABABABAB". If I personally read the regex, I see (.+), which captures any group of any length. And then \1+$ which repeats the captured group any number of times until the end.



          So why doesn't it capture just "AB" and find that it is repeated until the end of the string, especially since there is no restriction specified as to where the substring can start?






          share|improve this answer











          $endgroup$









          • 1




            $begingroup$
            Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.
            $endgroup$
            – Grimy
            Apr 25 at 15:43






          • 1




            $begingroup$
            My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.
            $endgroup$
            – Grimy
            Apr 25 at 15:50



















          4












          $begingroup$


          Perl 5 -p, 14 bytes





          $_=/^(.*)1+$/


          Try it online!






          share|improve this answer









          $endgroup$





















            4












            $begingroup$


            Python 2, 24 bytes





            lambda s:s in(s*2)[1:-1]


            Try it online!



            Shamelessly stolen from xnor's answer to the original question.





            More intuitive version:




            Python 2, 59 55 53 bytes





            lambda s:s in[len(s)/i*s[:i]for i in range(1,len(s))]


            Try it online!





            Boring regex version:




            Python 2, 44 bytes





            lambda s:re.match(r'(.+)1+$',s)>0
            import re


            Try it online!






            share|improve this answer











            $endgroup$





















              3












              $begingroup$


              Pyke, 4 bytes



              +tO{


              Try it here!



              +    -    input+input
              t - ^[1:]
              O - ^[:-1]
              { - input in ^





              share|improve this answer









              $endgroup$





















                3












                $begingroup$


                J, 26 25 15 14 bytes



                Using xnor method



                +./@E.}:@}.@,~


                Try it online!



                original (two different approaches)




                J, 25 bytes



                1<1#.(#%#)=<+/@E.&:>"{]


                Try it online!




                J, 26 bytes



                1<1#.-@#([:(-:##{.)<)"{]


                Try it online!






                share|improve this answer











                $endgroup$





















                  3












                  $begingroup$


                  Wolfram Language (Mathematica), 24 23 bytes



                  StringMatchQ[x__..~~x_]


                  Try it online!



                  StringMatchQ[           (*a function that checks if its input (string) matches:*)
                  x__.. (*a sequence of one or more characters, repeated one or more times*)
                  ~~x_] (*and one more time*)





                  share|improve this answer











                  $endgroup$





















                    3












                    $begingroup$

                    PowerShell, 23 24 bytes



                    +1 byte to fully match rules



                    "$args"-match"^(.+)1+$"


                    Try it online!



                    Pretty boring. Based on the other Regex answers. Luckily PowerShell doesn't use as an escape character!






                    share|improve this answer











                    $endgroup$













                    • $begingroup$
                      it returns true for aabcabc
                      $endgroup$
                      – mazzy
                      Apr 25 at 3:41






                    • 1




                      $begingroup$
                      @mazzy just fixed!
                      $endgroup$
                      – Gabriel Mills
                      Apr 25 at 11:38



















                    3












                    $begingroup$


                    C# (Visual C# Interactive Compiler), 70 bytes



                    xnor's shameless adaptation (46 bytes)



                    s=>(s+s).Substring(1,s.Length*2-2).Contains(s)


                    My non Regex Solution:



                    s=>s.Select((x,y)=>y).Count(z=>s.Replace(s.Substring(0,z+1),"")=="")>1


                    Explanation:



                    Replace every possible substring that starts at index 0 with an empty string. If the result is an empty string, the string is entirely made of that substring. Since this includes evaluating the entire string with itself, the amount of expected results must be greater than 1.



                    Example: abcabc



                    Possible substrings starting at index 0:



                    'a', 'ab', 'abc', 'abca', 'abcab', 'abcabc'


                    If we replace them with empty strings



                    Substring          Result

                    'a' => 'bcbc'
                    'ab' => 'cc'
                    'abc' => ''
                    'abca' => 'bc'
                    'abcab' => 'c'
                    'abcabc' => ''


                    Since there is a substring other than 'abcabc' that returns an empty string, the string is entirely made of another substring ('abc')



                    Try it online!






                    share|improve this answer











                    $endgroup$





















                      3












                      $begingroup$


                      Python 3, 62 60 56 54 bytes



                      -4 bytes thanx to ArBo





                      lambda s:s in(len(s)//l*s[:l]for l in range(1,len(s)))



                      1. Iterate over all possible prefixes in the string.

                      2. Try to build the string out of the prefix.

                      3. Return whether this succeeds with any prefix at all.


                      Try it online!






                      share|improve this answer











                      $endgroup$









                      • 1




                        $begingroup$
                        Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes
                        $endgroup$
                        – ArBo
                        Apr 26 at 8:09








                      • 1




                        $begingroup$
                        Nice catch with the list membership, thanx! I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;) Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?
                        $endgroup$
                        – movatica
                        Apr 26 at 14:13








                      • 1




                        $begingroup$
                        @movatica In the header, put `f = ` ( is the line continuation character in python)
                        $endgroup$
                        – Artemis Fowl
                        Apr 26 at 15:33












                      • $begingroup$
                        Annoyingly, is also an escape character. Here, without code formatting, is what you should put in the header: f =
                        $endgroup$
                        – Artemis Fowl
                        Apr 26 at 15:35



















                      2












                      $begingroup$


                      Japt, 10 bytes



                      Returns a positive number if truthy and 0 if falsey. If you want a bool output just add flag



                      å+ k@rXÃÊÉ




                      å+ k@rXÃÊÉ      Full program. Implicit input U.
                      e.g: U = "abcabcabc"
                      å+ Take all prefixes
                      U = ["a","ab","abc","abca","abcab","abcabc","abcabca","abcabcab","abcabcabc"]
                      k@ Filter U by:
                      rXÃ Values that return false (empty string)
                      when replacing each prefix in U
                      e.g: ["bcbcbc","ccc","","bcabc","cabc","abc","bc","c",""]
                      take ↑ and ↑
                      U = ["abc","abcabcabc"]
                      ÊÉ Get U length and subtract 1. Then return the result


                      Try it online!






                      share|improve this answer











                      $endgroup$





















                        2












                        $begingroup$


                        Husk, 6 bytes



                        Ṡ€ȯhtD


                        Try it online!



                        I feel like this is one byte more than optimal, but I couldn't find an arrangement that made the explicit composition ȯ unnecessary.



                        Explanation



                        Ṡ€      Find the argument in the result of applying the following function to the argument
                        ȯhtD Duplicate the argument, then remove the first and last elements.





                        share|improve this answer









                        $endgroup$









                        • 2




                          $begingroup$
                          €htD¹ avoids the ȯ.
                          $endgroup$
                          – Zgarb
                          Apr 24 at 19:30










                        • $begingroup$
                          That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly
                          $endgroup$
                          – Sophia Lechner
                          Apr 24 at 20:10



















                        2












                        $begingroup$

                        Mathematica 11.x, 74 bytes



                        {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&


                        where, throughout, # represents the input string, and



                        StringCases[#,<pattern>]


                        finds substrings of the input string matching the pattern



                        StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="") 


                        This pattern requires matches, x, must start at the start of the string and must satisfy the condition that (1) the match is not the whole input string and (2) if we replace occurrences of the match in the input string with the empty string we obtain the empty string. Finally, comparing the list of matches to the empty list,



                        {}!=


                        is True if the list of matches is nonempty and False if the list of matches is empty.



                        Test cases:



                        {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aa"]
                        (* True *)
                        {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aaa"]
                        (* True *)
                        {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["abcabc"]
                        (* True *)


                        and



                        {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aba"]
                        (* False *)
                        {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["ababa"]
                        (* False *)
                        {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["weqweqweqweqweqw"]
                        (* False *)





                        share|improve this answer









                        $endgroup$





















                          2












                          $begingroup$

                          Python 3, 84 bytes



                          import textwrap
                          lambda s:any(len(set(textwrap.wrap(s,l)))<2 for l in range(1,len(s)))


                          Uses textwrap.wrap (thanks to this answer) to split the string into pieces of length n to test each possible length of repeating substring. The split pieces are then compared to each other by adding them to a set. If all of the pieces are equal, and the set is of length 1, then the string must be a repeating string. I used <2 instead of ==1 because it saves a byte, and the length of the input string was guaranteed to be greater than zero.



                          If there is no n for which repeating substrings of length n make up the entire string, then return false for the whole function.






                          share|improve this answer









                          $endgroup$





















                            2












                            $begingroup$


                            05AB1E, 5 bytes



                            xnor's method from the previous question appears to be optimal in 05AB1E as well.



                            «¦¨så


                            Try it online!
                            or as a Test Suite



                            Explanation



                            «       # append input to input
                            ¦¨ # remove the first and last character of the resulting string
                            så # check if the input is in this string





                            share|improve this answer









                            $endgroup$









                            • 1




                              $begingroup$
                              Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD
                              $endgroup$
                              – Kevin Cruijssen
                              Apr 25 at 6:55










                            • $begingroup$
                              @KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)
                              $endgroup$
                              – Emigna
                              Apr 25 at 6:56



















                            2












                            $begingroup$


                            Clean, 73 bytes



                            Doesn't use regex.



                            import StdEnv,Data.List
                            $s=or[isPrefixOf s(cycle t)\t<-tl(tails s)|t>]


                            Try it online!



                            Defines $ :: [Char] -> Bool.

                            Checks if the given string is a prefix of the repetition of any sub-string taken from the end.






                            share|improve this answer









                            $endgroup$





















                              2












                              $begingroup$


                              C++ (gcc), 36 bytes





                              #define f(x)(x+x).find(x,1)<x.size()


                              Try it online!



                              Another port of xnor's solution. Uses a macro to expand the argument into the expression. The argument is assumed to be of type std::string.






                              share|improve this answer











                              $endgroup$





















                                1












                                $begingroup$

                                QlikView Variable, 27 bytes



                                This should be defined as a variable, which then allows you to pass parameters, e.g. $1 as your input value.



                                It returns 0 or -1 (equivalent to QlikView's TRUE() function).



                                =substringcount($1&$1,$1)>2





                                share|improve this answer









                                $endgroup$





















                                  1












                                  $begingroup$

                                  Swift, 196 bytes



                                  func r(s:String)->Bool{guard let k=s.dropFirst().firstIndex(where:{$0==s.first}) else{return false};let v=s[...k].dropLast();var w=v;while s.hasPrefix(w) && s.count>=(w+v).count{w+=v};return s==w}


                                  Try it online!






                                  share|improve this answer









                                  $endgroup$













                                  • $begingroup$
                                    I don't use Swift, but I'm sure that extra whitespace can be removed
                                    $endgroup$
                                    – Benjamin Urquhart
                                    Apr 24 at 19:56










                                  • $begingroup$
                                    193 bytes using @benjamin's suggestion.
                                    $endgroup$
                                    – Artemis Fowl
                                    Apr 26 at 15:39










                                  • $begingroup$
                                    @ArtemisFowl or even 123 bytes
                                    $endgroup$
                                    – Roman Podymov
                                    Apr 26 at 16:59





















                                  1












                                  $begingroup$


                                  Icon, 46 bytes



                                  procedure f(s);return find(s,(s||s)[2:-1]);end


                                  Try it online!



                                  Another port of xnor's solution.






                                  share|improve this answer











                                  $endgroup$





















                                    1












                                    $begingroup$


                                    K (oK), 29 bytes



                                    {0<+/(1=#?:)'(0N,'1_!#x)#:x}


                                    Try it online!






                                    share|improve this answer









                                    $endgroup$





















                                      1












                                      $begingroup$


                                      Red, 72 bytes



                                      func[s][repeat i length? s[parse s[copy t i skip some t end(return 1)]]]


                                      Try it online!



                                      Returns 1 for True






                                      share|improve this answer









                                      $endgroup$





















                                        1












                                        $begingroup$

                                        T-SQL, 47 bytes



                                        Using @Xnor's method:



                                        DECLARE @ varchar(max)='ababab'

                                        PRINT sign(charindex(@,left(@+@,len(@)*2-1),2))


                                        Keeping old answer as it contains some nice golfing(67 bytes):



                                        DECLARE @y varchar(max)='abababa'

                                        ,@ INT=0WHILE
                                        replace(@y,left(@y,@),'')>''SET
                                        @+=1PRINT @/len(@y)^1


                                        Explanation: This script is repeatingly trying to replace the input '@y' with the first '@' characters of the input '@y' with nothing, while increasing '@'.




                                        if you replace 'ab' in 'ababab' with nothing you have an empty string




                                        Eventually the result will be empty. If this happens when the loop variable is equal to the length of the varchar, the criteria is false/0 because '@'=len(@y) (there was no repeating varchar).



                                        iif(@=len(@y),0,1)


                                        can be golfed into this



                                        @/len(@y)^1


                                        because the length of '@y' can not be 0 and '@' will never exceed the length @y.



                                        Try it online






                                        share|improve this answer











                                        $endgroup$

















                                          1 2
                                          next




                                          Your Answer






                                          StackExchange.ifUsing("editor", function () {
                                          StackExchange.using("externalEditor", function () {
                                          StackExchange.using("snippets", function () {
                                          StackExchange.snippets.init();
                                          });
                                          });
                                          }, "code-snippets");

                                          StackExchange.ready(function() {
                                          var channelOptions = {
                                          tags: "".split(" "),
                                          id: "200"
                                          };
                                          initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                          StackExchange.using("externalEditor", function() {
                                          // Have to fire editor after snippets, if snippets enabled
                                          if (StackExchange.settings.snippets.snippetsEnabled) {
                                          StackExchange.using("snippets", function() {
                                          createEditor();
                                          });
                                          }
                                          else {
                                          createEditor();
                                          }
                                          });

                                          function createEditor() {
                                          StackExchange.prepareEditor({
                                          heartbeatType: 'answer',
                                          autoActivateHeartbeat: false,
                                          convertImagesToLinks: false,
                                          noModals: true,
                                          showLowRepImageUploadWarning: true,
                                          reputationToPostImages: null,
                                          bindNavPrevention: true,
                                          postfix: "",
                                          imageUploader: {
                                          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                          allowUrls: true
                                          },
                                          onDemand: true,
                                          discardSelector: ".discard-answer"
                                          ,immediatelyShowMarkdownHelp:true
                                          });


                                          }
                                          });














                                          draft saved

                                          draft discarded


















                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f184682%2fcheck-if-a-string-is-entirely-made-of-the-same-substring%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown

























                                          40 Answers
                                          40






                                          active

                                          oldest

                                          votes








                                          40 Answers
                                          40






                                          active

                                          oldest

                                          votes









                                          active

                                          oldest

                                          votes






                                          active

                                          oldest

                                          votes








                                          1 2
                                          next










                                          11












                                          $begingroup$


                                          Brachylog, 4 3 bytes



                                          ġ=Ṁ


                                          Try it online!



                                          Explanation



                                          ġ=Ṁ    Implicit input, say "abcabc"
                                          ġ Split into chunks of equal lengths (except maybe the last one): ["abc","abc"]
                                          = Apply the constraint that all of the chunks are equal,
                                          Ṁ and that there are multiple of them.


                                          The program prints true. if the constraints can be satisfied, and false. if not.






                                          share|improve this answer











                                          $endgroup$













                                          • $begingroup$
                                            I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:27






                                          • 4




                                            $begingroup$
                                            Oh, yeah, this could be one byte shorter: ġ=Ṁ
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:36










                                          • $begingroup$
                                            ( is a variable constrained to be a list of two or more elements)
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:39






                                          • 1




                                            $begingroup$
                                            @UnrelatedString Great, thanks! I didn't think to check the variables wiki page.
                                            $endgroup$
                                            – Zgarb
                                            Apr 25 at 9:12






                                          • 1




                                            $begingroup$
                                            A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.
                                            $endgroup$
                                            – ouflak
                                            May 1 at 6:40
















                                          11












                                          $begingroup$


                                          Brachylog, 4 3 bytes



                                          ġ=Ṁ


                                          Try it online!



                                          Explanation



                                          ġ=Ṁ    Implicit input, say "abcabc"
                                          ġ Split into chunks of equal lengths (except maybe the last one): ["abc","abc"]
                                          = Apply the constraint that all of the chunks are equal,
                                          Ṁ and that there are multiple of them.


                                          The program prints true. if the constraints can be satisfied, and false. if not.






                                          share|improve this answer











                                          $endgroup$













                                          • $begingroup$
                                            I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:27






                                          • 4




                                            $begingroup$
                                            Oh, yeah, this could be one byte shorter: ġ=Ṁ
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:36










                                          • $begingroup$
                                            ( is a variable constrained to be a list of two or more elements)
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:39






                                          • 1




                                            $begingroup$
                                            @UnrelatedString Great, thanks! I didn't think to check the variables wiki page.
                                            $endgroup$
                                            – Zgarb
                                            Apr 25 at 9:12






                                          • 1




                                            $begingroup$
                                            A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.
                                            $endgroup$
                                            – ouflak
                                            May 1 at 6:40














                                          11












                                          11








                                          11





                                          $begingroup$


                                          Brachylog, 4 3 bytes



                                          ġ=Ṁ


                                          Try it online!



                                          Explanation



                                          ġ=Ṁ    Implicit input, say "abcabc"
                                          ġ Split into chunks of equal lengths (except maybe the last one): ["abc","abc"]
                                          = Apply the constraint that all of the chunks are equal,
                                          Ṁ and that there are multiple of them.


                                          The program prints true. if the constraints can be satisfied, and false. if not.






                                          share|improve this answer











                                          $endgroup$




                                          Brachylog, 4 3 bytes



                                          ġ=Ṁ


                                          Try it online!



                                          Explanation



                                          ġ=Ṁ    Implicit input, say "abcabc"
                                          ġ Split into chunks of equal lengths (except maybe the last one): ["abc","abc"]
                                          = Apply the constraint that all of the chunks are equal,
                                          Ṁ and that there are multiple of them.


                                          The program prints true. if the constraints can be satisfied, and false. if not.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Apr 25 at 0:22









                                          Unrelated String

                                          2,190313




                                          2,190313










                                          answered Apr 24 at 19:28









                                          ZgarbZgarb

                                          27.2k462233




                                          27.2k462233












                                          • $begingroup$
                                            I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:27






                                          • 4




                                            $begingroup$
                                            Oh, yeah, this could be one byte shorter: ġ=Ṁ
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:36










                                          • $begingroup$
                                            ( is a variable constrained to be a list of two or more elements)
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:39






                                          • 1




                                            $begingroup$
                                            @UnrelatedString Great, thanks! I didn't think to check the variables wiki page.
                                            $endgroup$
                                            – Zgarb
                                            Apr 25 at 9:12






                                          • 1




                                            $begingroup$
                                            A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.
                                            $endgroup$
                                            – ouflak
                                            May 1 at 6:40


















                                          • $begingroup$
                                            I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:27






                                          • 4




                                            $begingroup$
                                            Oh, yeah, this could be one byte shorter: ġ=Ṁ
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:36










                                          • $begingroup$
                                            ( is a variable constrained to be a list of two or more elements)
                                            $endgroup$
                                            – Unrelated String
                                            Apr 24 at 21:39






                                          • 1




                                            $begingroup$
                                            @UnrelatedString Great, thanks! I didn't think to check the variables wiki page.
                                            $endgroup$
                                            – Zgarb
                                            Apr 25 at 9:12






                                          • 1




                                            $begingroup$
                                            A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.
                                            $endgroup$
                                            – ouflak
                                            May 1 at 6:40
















                                          $begingroup$
                                          I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago
                                          $endgroup$
                                          – Unrelated String
                                          Apr 24 at 21:27




                                          $begingroup$
                                          I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago
                                          $endgroup$
                                          – Unrelated String
                                          Apr 24 at 21:27




                                          4




                                          4




                                          $begingroup$
                                          Oh, yeah, this could be one byte shorter: ġ=Ṁ
                                          $endgroup$
                                          – Unrelated String
                                          Apr 24 at 21:36




                                          $begingroup$
                                          Oh, yeah, this could be one byte shorter: ġ=Ṁ
                                          $endgroup$
                                          – Unrelated String
                                          Apr 24 at 21:36












                                          $begingroup$
                                          ( is a variable constrained to be a list of two or more elements)
                                          $endgroup$
                                          – Unrelated String
                                          Apr 24 at 21:39




                                          $begingroup$
                                          ( is a variable constrained to be a list of two or more elements)
                                          $endgroup$
                                          – Unrelated String
                                          Apr 24 at 21:39




                                          1




                                          1




                                          $begingroup$
                                          @UnrelatedString Great, thanks! I didn't think to check the variables wiki page.
                                          $endgroup$
                                          – Zgarb
                                          Apr 25 at 9:12




                                          $begingroup$
                                          @UnrelatedString Great, thanks! I didn't think to check the variables wiki page.
                                          $endgroup$
                                          – Zgarb
                                          Apr 25 at 9:12




                                          1




                                          1




                                          $begingroup$
                                          A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.
                                          $endgroup$
                                          – ouflak
                                          May 1 at 6:40




                                          $begingroup$
                                          A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.
                                          $endgroup$
                                          – ouflak
                                          May 1 at 6:40











                                          19












                                          $begingroup$

                                          JavaScript (ES6), 22 bytes



                                          Returns a Boolean value.





                                          s=>/^(.*)1+$/.test(s)


                                          Try it online!





                                          Without a regular expression,  33  29 bytes



                                          Returns either null (falsy) or an object (truthy).





                                          s=>(s+s).slice(1,-1).match(s)


                                          Try it online!



                                          NB: Technically, $s$ is converted to a regular expression for match(), so the above title is a lie.






                                          share|improve this answer











                                          $endgroup$


















                                            19












                                            $begingroup$

                                            JavaScript (ES6), 22 bytes



                                            Returns a Boolean value.





                                            s=>/^(.*)1+$/.test(s)


                                            Try it online!





                                            Without a regular expression,  33  29 bytes



                                            Returns either null (falsy) or an object (truthy).





                                            s=>(s+s).slice(1,-1).match(s)


                                            Try it online!



                                            NB: Technically, $s$ is converted to a regular expression for match(), so the above title is a lie.






                                            share|improve this answer











                                            $endgroup$
















                                              19












                                              19








                                              19





                                              $begingroup$

                                              JavaScript (ES6), 22 bytes



                                              Returns a Boolean value.





                                              s=>/^(.*)1+$/.test(s)


                                              Try it online!





                                              Without a regular expression,  33  29 bytes



                                              Returns either null (falsy) or an object (truthy).





                                              s=>(s+s).slice(1,-1).match(s)


                                              Try it online!



                                              NB: Technically, $s$ is converted to a regular expression for match(), so the above title is a lie.






                                              share|improve this answer











                                              $endgroup$



                                              JavaScript (ES6), 22 bytes



                                              Returns a Boolean value.





                                              s=>/^(.*)1+$/.test(s)


                                              Try it online!





                                              Without a regular expression,  33  29 bytes



                                              Returns either null (falsy) or an object (truthy).





                                              s=>(s+s).slice(1,-1).match(s)


                                              Try it online!



                                              NB: Technically, $s$ is converted to a regular expression for match(), so the above title is a lie.







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Apr 24 at 16:34

























                                              answered Apr 24 at 15:01









                                              ArnauldArnauld

                                              85.1k7100349




                                              85.1k7100349























                                                  9












                                                  $begingroup$

                                                  grep, 19



                                                  grep -qxE '(.+)1+'


                                                  Test



                                                  while read; do 
                                                  <<<"$REPLY" grep -qxE '(.+)1+' && t="true" || t="false"
                                                  echo "$REPLY: $t"
                                                  done < infile


                                                  Output:



                                                  aa: true
                                                  aaa: true
                                                  abcabcabc: true
                                                  aba: false
                                                  ababa: false
                                                  weqweqweqweqweqw: false





                                                  share|improve this answer











                                                  $endgroup$


















                                                    9












                                                    $begingroup$

                                                    grep, 19



                                                    grep -qxE '(.+)1+'


                                                    Test



                                                    while read; do 
                                                    <<<"$REPLY" grep -qxE '(.+)1+' && t="true" || t="false"
                                                    echo "$REPLY: $t"
                                                    done < infile


                                                    Output:



                                                    aa: true
                                                    aaa: true
                                                    abcabcabc: true
                                                    aba: false
                                                    ababa: false
                                                    weqweqweqweqweqw: false





                                                    share|improve this answer











                                                    $endgroup$
















                                                      9












                                                      9








                                                      9





                                                      $begingroup$

                                                      grep, 19



                                                      grep -qxE '(.+)1+'


                                                      Test



                                                      while read; do 
                                                      <<<"$REPLY" grep -qxE '(.+)1+' && t="true" || t="false"
                                                      echo "$REPLY: $t"
                                                      done < infile


                                                      Output:



                                                      aa: true
                                                      aaa: true
                                                      abcabcabc: true
                                                      aba: false
                                                      ababa: false
                                                      weqweqweqweqweqw: false





                                                      share|improve this answer











                                                      $endgroup$



                                                      grep, 19



                                                      grep -qxE '(.+)1+'


                                                      Test



                                                      while read; do 
                                                      <<<"$REPLY" grep -qxE '(.+)1+' && t="true" || t="false"
                                                      echo "$REPLY: $t"
                                                      done < infile


                                                      Output:



                                                      aa: true
                                                      aaa: true
                                                      abcabcabc: true
                                                      aba: false
                                                      ababa: false
                                                      weqweqweqweqweqw: false






                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Apr 24 at 16:02

























                                                      answered Apr 24 at 15:56









                                                      ThorThor

                                                      2,38621219




                                                      2,38621219























                                                          9












                                                          $begingroup$


                                                          Japt, 6 bytes



                                                          ²é ¤øU


                                                          Saved one byte thanks to @Shaggy



                                                          Try it online!



                                                                  Implicit input, stored in variable 'U'
                                                          ² U+U, "abcabc" -> "abcabcabcabc"
                                                          é Rotate 1 char to the right "abcabcabcabc" -> "cabcabcabcab"
                                                          ¤ Remove first two chars, "cabcabcabcab" -> "bcabcabcab"
                                                          øU Check if U is in the above





                                                          share|improve this answer











                                                          $endgroup$













                                                          • $begingroup$
                                                            Nice one :) You can replace the p<space> with ² to save a byte.
                                                            $endgroup$
                                                            – Shaggy
                                                            Apr 24 at 16:25
















                                                          9












                                                          $begingroup$


                                                          Japt, 6 bytes



                                                          ²é ¤øU


                                                          Saved one byte thanks to @Shaggy



                                                          Try it online!



                                                                  Implicit input, stored in variable 'U'
                                                          ² U+U, "abcabc" -> "abcabcabcabc"
                                                          é Rotate 1 char to the right "abcabcabcabc" -> "cabcabcabcab"
                                                          ¤ Remove first two chars, "cabcabcabcab" -> "bcabcabcab"
                                                          øU Check if U is in the above





                                                          share|improve this answer











                                                          $endgroup$













                                                          • $begingroup$
                                                            Nice one :) You can replace the p<space> with ² to save a byte.
                                                            $endgroup$
                                                            – Shaggy
                                                            Apr 24 at 16:25














                                                          9












                                                          9








                                                          9





                                                          $begingroup$


                                                          Japt, 6 bytes



                                                          ²é ¤øU


                                                          Saved one byte thanks to @Shaggy



                                                          Try it online!



                                                                  Implicit input, stored in variable 'U'
                                                          ² U+U, "abcabc" -> "abcabcabcabc"
                                                          é Rotate 1 char to the right "abcabcabcabc" -> "cabcabcabcab"
                                                          ¤ Remove first two chars, "cabcabcabcab" -> "bcabcabcab"
                                                          øU Check if U is in the above





                                                          share|improve this answer











                                                          $endgroup$




                                                          Japt, 6 bytes



                                                          ²é ¤øU


                                                          Saved one byte thanks to @Shaggy



                                                          Try it online!



                                                                  Implicit input, stored in variable 'U'
                                                          ² U+U, "abcabc" -> "abcabcabcabc"
                                                          é Rotate 1 char to the right "abcabcabcabc" -> "cabcabcabcab"
                                                          ¤ Remove first two chars, "cabcabcabcab" -> "bcabcabcab"
                                                          øU Check if U is in the above






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Apr 24 at 16:28

























                                                          answered Apr 24 at 16:14









                                                          Embodiment of IgnoranceEmbodiment of Ignorance

                                                          3,874128




                                                          3,874128












                                                          • $begingroup$
                                                            Nice one :) You can replace the p<space> with ² to save a byte.
                                                            $endgroup$
                                                            – Shaggy
                                                            Apr 24 at 16:25


















                                                          • $begingroup$
                                                            Nice one :) You can replace the p<space> with ² to save a byte.
                                                            $endgroup$
                                                            – Shaggy
                                                            Apr 24 at 16:25
















                                                          $begingroup$
                                                          Nice one :) You can replace the p<space> with ² to save a byte.
                                                          $endgroup$
                                                          – Shaggy
                                                          Apr 24 at 16:25




                                                          $begingroup$
                                                          Nice one :) You can replace the p<space> with ² to save a byte.
                                                          $endgroup$
                                                          – Shaggy
                                                          Apr 24 at 16:25











                                                          9












                                                          $begingroup$

                                                          Java, 25 24 bytes



                                                          -1 byte thanks to Olivier Grégoire!

                                                          Boring regex answer



                                                          s->s.matches("(.+)\1+")


                                                          Try it online!

                                                          It's just 1 byte longer than the python answer aaaaa I'm tied now :)






                                                          share|improve this answer











                                                          $endgroup$









                                                          • 3




                                                            $begingroup$
                                                            You can remove the final $ as the matches method is an exact match, not a substring match by default.
                                                            $endgroup$
                                                            – Olivier Grégoire
                                                            Apr 24 at 23:18










                                                          • $begingroup$
                                                            I forgot matches adds its own $ to the regex. Thanks!
                                                            $endgroup$
                                                            – Benjamin Urquhart
                                                            Apr 24 at 23:34
















                                                          9












                                                          $begingroup$

                                                          Java, 25 24 bytes



                                                          -1 byte thanks to Olivier Grégoire!

                                                          Boring regex answer



                                                          s->s.matches("(.+)\1+")


                                                          Try it online!

                                                          It's just 1 byte longer than the python answer aaaaa I'm tied now :)






                                                          share|improve this answer











                                                          $endgroup$









                                                          • 3




                                                            $begingroup$
                                                            You can remove the final $ as the matches method is an exact match, not a substring match by default.
                                                            $endgroup$
                                                            – Olivier Grégoire
                                                            Apr 24 at 23:18










                                                          • $begingroup$
                                                            I forgot matches adds its own $ to the regex. Thanks!
                                                            $endgroup$
                                                            – Benjamin Urquhart
                                                            Apr 24 at 23:34














                                                          9












                                                          9








                                                          9





                                                          $begingroup$

                                                          Java, 25 24 bytes



                                                          -1 byte thanks to Olivier Grégoire!

                                                          Boring regex answer



                                                          s->s.matches("(.+)\1+")


                                                          Try it online!

                                                          It's just 1 byte longer than the python answer aaaaa I'm tied now :)






                                                          share|improve this answer











                                                          $endgroup$



                                                          Java, 25 24 bytes



                                                          -1 byte thanks to Olivier Grégoire!

                                                          Boring regex answer



                                                          s->s.matches("(.+)\1+")


                                                          Try it online!

                                                          It's just 1 byte longer than the python answer aaaaa I'm tied now :)







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Apr 24 at 23:35

























                                                          answered Apr 24 at 19:49









                                                          Benjamin UrquhartBenjamin Urquhart

                                                          1,036116




                                                          1,036116








                                                          • 3




                                                            $begingroup$
                                                            You can remove the final $ as the matches method is an exact match, not a substring match by default.
                                                            $endgroup$
                                                            – Olivier Grégoire
                                                            Apr 24 at 23:18










                                                          • $begingroup$
                                                            I forgot matches adds its own $ to the regex. Thanks!
                                                            $endgroup$
                                                            – Benjamin Urquhart
                                                            Apr 24 at 23:34














                                                          • 3




                                                            $begingroup$
                                                            You can remove the final $ as the matches method is an exact match, not a substring match by default.
                                                            $endgroup$
                                                            – Olivier Grégoire
                                                            Apr 24 at 23:18










                                                          • $begingroup$
                                                            I forgot matches adds its own $ to the regex. Thanks!
                                                            $endgroup$
                                                            – Benjamin Urquhart
                                                            Apr 24 at 23:34








                                                          3




                                                          3




                                                          $begingroup$
                                                          You can remove the final $ as the matches method is an exact match, not a substring match by default.
                                                          $endgroup$
                                                          – Olivier Grégoire
                                                          Apr 24 at 23:18




                                                          $begingroup$
                                                          You can remove the final $ as the matches method is an exact match, not a substring match by default.
                                                          $endgroup$
                                                          – Olivier Grégoire
                                                          Apr 24 at 23:18












                                                          $begingroup$
                                                          I forgot matches adds its own $ to the regex. Thanks!
                                                          $endgroup$
                                                          – Benjamin Urquhart
                                                          Apr 24 at 23:34




                                                          $begingroup$
                                                          I forgot matches adds its own $ to the regex. Thanks!
                                                          $endgroup$
                                                          – Benjamin Urquhart
                                                          Apr 24 at 23:34











                                                          7












                                                          $begingroup$

                                                          Excel, 26 bytes



                                                          =FIND(A1,A1&A1,2)<=LEN(A1)


                                                          Inputs from A1, outputs to whatever cell you put this formula.






                                                          share|improve this answer









                                                          $endgroup$













                                                          • $begingroup$
                                                            You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 18:54










                                                          • $begingroup$
                                                            @i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 24 at 20:17












                                                          • $begingroup$
                                                            Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 23:05






                                                          • 1




                                                            $begingroup$
                                                            I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 25 at 17:03


















                                                          7












                                                          $begingroup$

                                                          Excel, 26 bytes



                                                          =FIND(A1,A1&A1,2)<=LEN(A1)


                                                          Inputs from A1, outputs to whatever cell you put this formula.






                                                          share|improve this answer









                                                          $endgroup$













                                                          • $begingroup$
                                                            You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 18:54










                                                          • $begingroup$
                                                            @i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 24 at 20:17












                                                          • $begingroup$
                                                            Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 23:05






                                                          • 1




                                                            $begingroup$
                                                            I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 25 at 17:03
















                                                          7












                                                          7








                                                          7





                                                          $begingroup$

                                                          Excel, 26 bytes



                                                          =FIND(A1,A1&A1,2)<=LEN(A1)


                                                          Inputs from A1, outputs to whatever cell you put this formula.






                                                          share|improve this answer









                                                          $endgroup$



                                                          Excel, 26 bytes



                                                          =FIND(A1,A1&A1,2)<=LEN(A1)


                                                          Inputs from A1, outputs to whatever cell you put this formula.







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Apr 24 at 16:51









                                                          Sophia LechnerSophia Lechner

                                                          1,03018




                                                          1,03018












                                                          • $begingroup$
                                                            You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 18:54










                                                          • $begingroup$
                                                            @i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 24 at 20:17












                                                          • $begingroup$
                                                            Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 23:05






                                                          • 1




                                                            $begingroup$
                                                            I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 25 at 17:03




















                                                          • $begingroup$
                                                            You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 18:54










                                                          • $begingroup$
                                                            @i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 24 at 20:17












                                                          • $begingroup$
                                                            Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)
                                                            $endgroup$
                                                            – i_saw_drones
                                                            Apr 24 at 23:05






                                                          • 1




                                                            $begingroup$
                                                            I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.
                                                            $endgroup$
                                                            – Sophia Lechner
                                                            Apr 25 at 17:03


















                                                          $begingroup$
                                                          You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.
                                                          $endgroup$
                                                          – i_saw_drones
                                                          Apr 24 at 18:54




                                                          $begingroup$
                                                          You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.
                                                          $endgroup$
                                                          – i_saw_drones
                                                          Apr 24 at 18:54












                                                          $begingroup$
                                                          @i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.
                                                          $endgroup$
                                                          – Sophia Lechner
                                                          Apr 24 at 20:17






                                                          $begingroup$
                                                          @i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.
                                                          $endgroup$
                                                          – Sophia Lechner
                                                          Apr 24 at 20:17














                                                          $begingroup$
                                                          Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)
                                                          $endgroup$
                                                          – i_saw_drones
                                                          Apr 24 at 23:05




                                                          $begingroup$
                                                          Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)
                                                          $endgroup$
                                                          – i_saw_drones
                                                          Apr 24 at 23:05




                                                          1




                                                          1




                                                          $begingroup$
                                                          I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.
                                                          $endgroup$
                                                          – Sophia Lechner
                                                          Apr 25 at 17:03






                                                          $begingroup$
                                                          I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.
                                                          $endgroup$
                                                          – Sophia Lechner
                                                          Apr 25 at 17:03













                                                          6












                                                          $begingroup$


                                                          Retina 0.8.2, 9 bytes



                                                          ^(.+)1+$


                                                          Try it online! Link includes test cases.






                                                          share|improve this answer









                                                          $endgroup$


















                                                            6












                                                            $begingroup$


                                                            Retina 0.8.2, 9 bytes



                                                            ^(.+)1+$


                                                            Try it online! Link includes test cases.






                                                            share|improve this answer









                                                            $endgroup$
















                                                              6












                                                              6








                                                              6





                                                              $begingroup$


                                                              Retina 0.8.2, 9 bytes



                                                              ^(.+)1+$


                                                              Try it online! Link includes test cases.






                                                              share|improve this answer









                                                              $endgroup$




                                                              Retina 0.8.2, 9 bytes



                                                              ^(.+)1+$


                                                              Try it online! Link includes test cases.







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Apr 24 at 15:13









                                                              NeilNeil

                                                              84.6k845183




                                                              84.6k845183























                                                                  6












                                                                  $begingroup$


                                                                  Jelly,  5  4 bytes



                                                                  I see now that the optimal way is to follow xnor's method!



                                                                  Ḋ;Ṗw


                                                                  A monadic Link that accepts a list of characters and outputs an integer - the shortest possible length of a repeating slice or zero if none exists. Note that zero is falsey while non-zero numbers are truthy in Jelly.



                                                                  Try it online!



                                                                  How?



                                                                  Ḋ;Ṗw - Link: list of characters, S   e.g. "abcabcabc"   or "abababa"
                                                                  Ḋ - dequeue S "bcabcabc" "bababa"
                                                                  Ṗ - pop from S "abcabcab" "ababab"
                                                                  ; - concatenate "bcabcabcabcabcab" "bababaababab"
                                                                  w - first index of sublist 3 ^---here! 0 (not found)





                                                                  share|improve this answer











                                                                  $endgroup$


















                                                                    6












                                                                    $begingroup$


                                                                    Jelly,  5  4 bytes



                                                                    I see now that the optimal way is to follow xnor's method!



                                                                    Ḋ;Ṗw


                                                                    A monadic Link that accepts a list of characters and outputs an integer - the shortest possible length of a repeating slice or zero if none exists. Note that zero is falsey while non-zero numbers are truthy in Jelly.



                                                                    Try it online!



                                                                    How?



                                                                    Ḋ;Ṗw - Link: list of characters, S   e.g. "abcabcabc"   or "abababa"
                                                                    Ḋ - dequeue S "bcabcabc" "bababa"
                                                                    Ṗ - pop from S "abcabcab" "ababab"
                                                                    ; - concatenate "bcabcabcabcabcab" "bababaababab"
                                                                    w - first index of sublist 3 ^---here! 0 (not found)





                                                                    share|improve this answer











                                                                    $endgroup$
















                                                                      6












                                                                      6








                                                                      6





                                                                      $begingroup$


                                                                      Jelly,  5  4 bytes



                                                                      I see now that the optimal way is to follow xnor's method!



                                                                      Ḋ;Ṗw


                                                                      A monadic Link that accepts a list of characters and outputs an integer - the shortest possible length of a repeating slice or zero if none exists. Note that zero is falsey while non-zero numbers are truthy in Jelly.



                                                                      Try it online!



                                                                      How?



                                                                      Ḋ;Ṗw - Link: list of characters, S   e.g. "abcabcabc"   or "abababa"
                                                                      Ḋ - dequeue S "bcabcabc" "bababa"
                                                                      Ṗ - pop from S "abcabcab" "ababab"
                                                                      ; - concatenate "bcabcabcabcabcab" "bababaababab"
                                                                      w - first index of sublist 3 ^---here! 0 (not found)





                                                                      share|improve this answer











                                                                      $endgroup$




                                                                      Jelly,  5  4 bytes



                                                                      I see now that the optimal way is to follow xnor's method!



                                                                      Ḋ;Ṗw


                                                                      A monadic Link that accepts a list of characters and outputs an integer - the shortest possible length of a repeating slice or zero if none exists. Note that zero is falsey while non-zero numbers are truthy in Jelly.



                                                                      Try it online!



                                                                      How?



                                                                      Ḋ;Ṗw - Link: list of characters, S   e.g. "abcabcabc"   or "abababa"
                                                                      Ḋ - dequeue S "bcabcabc" "bababa"
                                                                      Ṗ - pop from S "abcabcab" "ababab"
                                                                      ; - concatenate "bcabcabcabcabcab" "bababaababab"
                                                                      w - first index of sublist 3 ^---here! 0 (not found)






                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Apr 24 at 19:07

























                                                                      answered Apr 24 at 16:18









                                                                      Jonathan AllanJonathan Allan

                                                                      55.9k538178




                                                                      55.9k538178























                                                                          6












                                                                          $begingroup$


                                                                          R, 28 bytes





                                                                          grepl("(.+)\1+$",scan(,''))


                                                                          Try it online!



                                                                          Simple Regex version. R is (sometimes) very similar to Python, so this is similar to TFeld's Python 2 regex answer, albeit shorter!



                                                                          Question (if anyone knows the answer)



                                                                          I am still confused why this works, as the substring can be any length and will always work, and still works when I add a letter to the front of a valid string, like "cABABABABAB". If I personally read the regex, I see (.+), which captures any group of any length. And then \1+$ which repeats the captured group any number of times until the end.



                                                                          So why doesn't it capture just "AB" and find that it is repeated until the end of the string, especially since there is no restriction specified as to where the substring can start?






                                                                          share|improve this answer











                                                                          $endgroup$









                                                                          • 1




                                                                            $begingroup$
                                                                            Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:43






                                                                          • 1




                                                                            $begingroup$
                                                                            My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:50
















                                                                          6












                                                                          $begingroup$


                                                                          R, 28 bytes





                                                                          grepl("(.+)\1+$",scan(,''))


                                                                          Try it online!



                                                                          Simple Regex version. R is (sometimes) very similar to Python, so this is similar to TFeld's Python 2 regex answer, albeit shorter!



                                                                          Question (if anyone knows the answer)



                                                                          I am still confused why this works, as the substring can be any length and will always work, and still works when I add a letter to the front of a valid string, like "cABABABABAB". If I personally read the regex, I see (.+), which captures any group of any length. And then \1+$ which repeats the captured group any number of times until the end.



                                                                          So why doesn't it capture just "AB" and find that it is repeated until the end of the string, especially since there is no restriction specified as to where the substring can start?






                                                                          share|improve this answer











                                                                          $endgroup$









                                                                          • 1




                                                                            $begingroup$
                                                                            Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:43






                                                                          • 1




                                                                            $begingroup$
                                                                            My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:50














                                                                          6












                                                                          6








                                                                          6





                                                                          $begingroup$


                                                                          R, 28 bytes





                                                                          grepl("(.+)\1+$",scan(,''))


                                                                          Try it online!



                                                                          Simple Regex version. R is (sometimes) very similar to Python, so this is similar to TFeld's Python 2 regex answer, albeit shorter!



                                                                          Question (if anyone knows the answer)



                                                                          I am still confused why this works, as the substring can be any length and will always work, and still works when I add a letter to the front of a valid string, like "cABABABABAB". If I personally read the regex, I see (.+), which captures any group of any length. And then \1+$ which repeats the captured group any number of times until the end.



                                                                          So why doesn't it capture just "AB" and find that it is repeated until the end of the string, especially since there is no restriction specified as to where the substring can start?






                                                                          share|improve this answer











                                                                          $endgroup$




                                                                          R, 28 bytes





                                                                          grepl("(.+)\1+$",scan(,''))


                                                                          Try it online!



                                                                          Simple Regex version. R is (sometimes) very similar to Python, so this is similar to TFeld's Python 2 regex answer, albeit shorter!



                                                                          Question (if anyone knows the answer)



                                                                          I am still confused why this works, as the substring can be any length and will always work, and still works when I add a letter to the front of a valid string, like "cABABABABAB". If I personally read the regex, I see (.+), which captures any group of any length. And then \1+$ which repeats the captured group any number of times until the end.



                                                                          So why doesn't it capture just "AB" and find that it is repeated until the end of the string, especially since there is no restriction specified as to where the substring can start?







                                                                          share|improve this answer














                                                                          share|improve this answer



                                                                          share|improve this answer








                                                                          edited Apr 24 at 19:55

























                                                                          answered Apr 24 at 19:46









                                                                          Sumner18Sumner18

                                                                          68018




                                                                          68018








                                                                          • 1




                                                                            $begingroup$
                                                                            Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:43






                                                                          • 1




                                                                            $begingroup$
                                                                            My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:50














                                                                          • 1




                                                                            $begingroup$
                                                                            Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:43






                                                                          • 1




                                                                            $begingroup$
                                                                            My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.
                                                                            $endgroup$
                                                                            – Grimy
                                                                            Apr 25 at 15:50








                                                                          1




                                                                          1




                                                                          $begingroup$
                                                                          Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.
                                                                          $endgroup$
                                                                          – Grimy
                                                                          Apr 25 at 15:43




                                                                          $begingroup$
                                                                          Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.
                                                                          $endgroup$
                                                                          – Grimy
                                                                          Apr 25 at 15:43




                                                                          1




                                                                          1




                                                                          $begingroup$
                                                                          My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.
                                                                          $endgroup$
                                                                          – Grimy
                                                                          Apr 25 at 15:50




                                                                          $begingroup$
                                                                          My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.
                                                                          $endgroup$
                                                                          – Grimy
                                                                          Apr 25 at 15:50











                                                                          4












                                                                          $begingroup$


                                                                          Perl 5 -p, 14 bytes





                                                                          $_=/^(.*)1+$/


                                                                          Try it online!






                                                                          share|improve this answer









                                                                          $endgroup$


















                                                                            4












                                                                            $begingroup$


                                                                            Perl 5 -p, 14 bytes





                                                                            $_=/^(.*)1+$/


                                                                            Try it online!






                                                                            share|improve this answer









                                                                            $endgroup$
















                                                                              4












                                                                              4








                                                                              4





                                                                              $begingroup$


                                                                              Perl 5 -p, 14 bytes





                                                                              $_=/^(.*)1+$/


                                                                              Try it online!






                                                                              share|improve this answer









                                                                              $endgroup$




                                                                              Perl 5 -p, 14 bytes





                                                                              $_=/^(.*)1+$/


                                                                              Try it online!







                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Apr 24 at 16:32









                                                                              XcaliXcali

                                                                              5,890523




                                                                              5,890523























                                                                                  4












                                                                                  $begingroup$


                                                                                  Python 2, 24 bytes





                                                                                  lambda s:s in(s*2)[1:-1]


                                                                                  Try it online!



                                                                                  Shamelessly stolen from xnor's answer to the original question.





                                                                                  More intuitive version:




                                                                                  Python 2, 59 55 53 bytes





                                                                                  lambda s:s in[len(s)/i*s[:i]for i in range(1,len(s))]


                                                                                  Try it online!





                                                                                  Boring regex version:




                                                                                  Python 2, 44 bytes





                                                                                  lambda s:re.match(r'(.+)1+$',s)>0
                                                                                  import re


                                                                                  Try it online!






                                                                                  share|improve this answer











                                                                                  $endgroup$


















                                                                                    4












                                                                                    $begingroup$


                                                                                    Python 2, 24 bytes





                                                                                    lambda s:s in(s*2)[1:-1]


                                                                                    Try it online!



                                                                                    Shamelessly stolen from xnor's answer to the original question.





                                                                                    More intuitive version:




                                                                                    Python 2, 59 55 53 bytes





                                                                                    lambda s:s in[len(s)/i*s[:i]for i in range(1,len(s))]


                                                                                    Try it online!





                                                                                    Boring regex version:




                                                                                    Python 2, 44 bytes





                                                                                    lambda s:re.match(r'(.+)1+$',s)>0
                                                                                    import re


                                                                                    Try it online!






                                                                                    share|improve this answer











                                                                                    $endgroup$
















                                                                                      4












                                                                                      4








                                                                                      4





                                                                                      $begingroup$


                                                                                      Python 2, 24 bytes





                                                                                      lambda s:s in(s*2)[1:-1]


                                                                                      Try it online!



                                                                                      Shamelessly stolen from xnor's answer to the original question.





                                                                                      More intuitive version:




                                                                                      Python 2, 59 55 53 bytes





                                                                                      lambda s:s in[len(s)/i*s[:i]for i in range(1,len(s))]


                                                                                      Try it online!





                                                                                      Boring regex version:




                                                                                      Python 2, 44 bytes





                                                                                      lambda s:re.match(r'(.+)1+$',s)>0
                                                                                      import re


                                                                                      Try it online!






                                                                                      share|improve this answer











                                                                                      $endgroup$




                                                                                      Python 2, 24 bytes





                                                                                      lambda s:s in(s*2)[1:-1]


                                                                                      Try it online!



                                                                                      Shamelessly stolen from xnor's answer to the original question.





                                                                                      More intuitive version:




                                                                                      Python 2, 59 55 53 bytes





                                                                                      lambda s:s in[len(s)/i*s[:i]for i in range(1,len(s))]


                                                                                      Try it online!





                                                                                      Boring regex version:




                                                                                      Python 2, 44 bytes





                                                                                      lambda s:re.match(r'(.+)1+$',s)>0
                                                                                      import re


                                                                                      Try it online!







                                                                                      share|improve this answer














                                                                                      share|improve this answer



                                                                                      share|improve this answer








                                                                                      edited Apr 24 at 18:37

























                                                                                      answered Apr 24 at 16:28









                                                                                      TFeldTFeld

                                                                                      16.9k31452




                                                                                      16.9k31452























                                                                                          3












                                                                                          $begingroup$


                                                                                          Pyke, 4 bytes



                                                                                          +tO{


                                                                                          Try it here!



                                                                                          +    -    input+input
                                                                                          t - ^[1:]
                                                                                          O - ^[:-1]
                                                                                          { - input in ^





                                                                                          share|improve this answer









                                                                                          $endgroup$


















                                                                                            3












                                                                                            $begingroup$


                                                                                            Pyke, 4 bytes



                                                                                            +tO{


                                                                                            Try it here!



                                                                                            +    -    input+input
                                                                                            t - ^[1:]
                                                                                            O - ^[:-1]
                                                                                            { - input in ^





                                                                                            share|improve this answer









                                                                                            $endgroup$
















                                                                                              3












                                                                                              3








                                                                                              3





                                                                                              $begingroup$


                                                                                              Pyke, 4 bytes



                                                                                              +tO{


                                                                                              Try it here!



                                                                                              +    -    input+input
                                                                                              t - ^[1:]
                                                                                              O - ^[:-1]
                                                                                              { - input in ^





                                                                                              share|improve this answer









                                                                                              $endgroup$




                                                                                              Pyke, 4 bytes



                                                                                              +tO{


                                                                                              Try it here!



                                                                                              +    -    input+input
                                                                                              t - ^[1:]
                                                                                              O - ^[:-1]
                                                                                              { - input in ^






                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered Apr 24 at 17:44









                                                                                              BlueBlue

                                                                                              24.1k73891




                                                                                              24.1k73891























                                                                                                  3












                                                                                                  $begingroup$


                                                                                                  J, 26 25 15 14 bytes



                                                                                                  Using xnor method



                                                                                                  +./@E.}:@}.@,~


                                                                                                  Try it online!



                                                                                                  original (two different approaches)




                                                                                                  J, 25 bytes



                                                                                                  1<1#.(#%#)=<+/@E.&:>"{]


                                                                                                  Try it online!




                                                                                                  J, 26 bytes



                                                                                                  1<1#.-@#([:(-:##{.)<)"{]


                                                                                                  Try it online!






                                                                                                  share|improve this answer











                                                                                                  $endgroup$


















                                                                                                    3












                                                                                                    $begingroup$


                                                                                                    J, 26 25 15 14 bytes



                                                                                                    Using xnor method



                                                                                                    +./@E.}:@}.@,~


                                                                                                    Try it online!



                                                                                                    original (two different approaches)




                                                                                                    J, 25 bytes



                                                                                                    1<1#.(#%#)=<+/@E.&:>"{]


                                                                                                    Try it online!




                                                                                                    J, 26 bytes



                                                                                                    1<1#.-@#([:(-:##{.)<)"{]


                                                                                                    Try it online!






                                                                                                    share|improve this answer











                                                                                                    $endgroup$
















                                                                                                      3












                                                                                                      3








                                                                                                      3





                                                                                                      $begingroup$


                                                                                                      J, 26 25 15 14 bytes



                                                                                                      Using xnor method



                                                                                                      +./@E.}:@}.@,~


                                                                                                      Try it online!



                                                                                                      original (two different approaches)




                                                                                                      J, 25 bytes



                                                                                                      1<1#.(#%#)=<+/@E.&:>"{]


                                                                                                      Try it online!




                                                                                                      J, 26 bytes



                                                                                                      1<1#.-@#([:(-:##{.)<)"{]


                                                                                                      Try it online!






                                                                                                      share|improve this answer











                                                                                                      $endgroup$




                                                                                                      J, 26 25 15 14 bytes



                                                                                                      Using xnor method



                                                                                                      +./@E.}:@}.@,~


                                                                                                      Try it online!



                                                                                                      original (two different approaches)




                                                                                                      J, 25 bytes



                                                                                                      1<1#.(#%#)=<+/@E.&:>"{]


                                                                                                      Try it online!




                                                                                                      J, 26 bytes



                                                                                                      1<1#.-@#([:(-:##{.)<)"{]


                                                                                                      Try it online!







                                                                                                      share|improve this answer














                                                                                                      share|improve this answer



                                                                                                      share|improve this answer








                                                                                                      edited Apr 24 at 21:33

























                                                                                                      answered Apr 24 at 17:13









                                                                                                      JonahJonah

                                                                                                      3,3781019




                                                                                                      3,3781019























                                                                                                          3












                                                                                                          $begingroup$


                                                                                                          Wolfram Language (Mathematica), 24 23 bytes



                                                                                                          StringMatchQ[x__..~~x_]


                                                                                                          Try it online!



                                                                                                          StringMatchQ[           (*a function that checks if its input (string) matches:*)
                                                                                                          x__.. (*a sequence of one or more characters, repeated one or more times*)
                                                                                                          ~~x_] (*and one more time*)





                                                                                                          share|improve this answer











                                                                                                          $endgroup$


















                                                                                                            3












                                                                                                            $begingroup$


                                                                                                            Wolfram Language (Mathematica), 24 23 bytes



                                                                                                            StringMatchQ[x__..~~x_]


                                                                                                            Try it online!



                                                                                                            StringMatchQ[           (*a function that checks if its input (string) matches:*)
                                                                                                            x__.. (*a sequence of one or more characters, repeated one or more times*)
                                                                                                            ~~x_] (*and one more time*)





                                                                                                            share|improve this answer











                                                                                                            $endgroup$
















                                                                                                              3












                                                                                                              3








                                                                                                              3





                                                                                                              $begingroup$


                                                                                                              Wolfram Language (Mathematica), 24 23 bytes



                                                                                                              StringMatchQ[x__..~~x_]


                                                                                                              Try it online!



                                                                                                              StringMatchQ[           (*a function that checks if its input (string) matches:*)
                                                                                                              x__.. (*a sequence of one or more characters, repeated one or more times*)
                                                                                                              ~~x_] (*and one more time*)





                                                                                                              share|improve this answer











                                                                                                              $endgroup$




                                                                                                              Wolfram Language (Mathematica), 24 23 bytes



                                                                                                              StringMatchQ[x__..~~x_]


                                                                                                              Try it online!



                                                                                                              StringMatchQ[           (*a function that checks if its input (string) matches:*)
                                                                                                              x__.. (*a sequence of one or more characters, repeated one or more times*)
                                                                                                              ~~x_] (*and one more time*)






                                                                                                              share|improve this answer














                                                                                                              share|improve this answer



                                                                                                              share|improve this answer








                                                                                                              edited Apr 25 at 9:47

























                                                                                                              answered Apr 25 at 3:48









                                                                                                              attinatattinat

                                                                                                              1,05717




                                                                                                              1,05717























                                                                                                                  3












                                                                                                                  $begingroup$

                                                                                                                  PowerShell, 23 24 bytes



                                                                                                                  +1 byte to fully match rules



                                                                                                                  "$args"-match"^(.+)1+$"


                                                                                                                  Try it online!



                                                                                                                  Pretty boring. Based on the other Regex answers. Luckily PowerShell doesn't use as an escape character!






                                                                                                                  share|improve this answer











                                                                                                                  $endgroup$













                                                                                                                  • $begingroup$
                                                                                                                    it returns true for aabcabc
                                                                                                                    $endgroup$
                                                                                                                    – mazzy
                                                                                                                    Apr 25 at 3:41






                                                                                                                  • 1




                                                                                                                    $begingroup$
                                                                                                                    @mazzy just fixed!
                                                                                                                    $endgroup$
                                                                                                                    – Gabriel Mills
                                                                                                                    Apr 25 at 11:38
















                                                                                                                  3












                                                                                                                  $begingroup$

                                                                                                                  PowerShell, 23 24 bytes



                                                                                                                  +1 byte to fully match rules



                                                                                                                  "$args"-match"^(.+)1+$"


                                                                                                                  Try it online!



                                                                                                                  Pretty boring. Based on the other Regex answers. Luckily PowerShell doesn't use as an escape character!






                                                                                                                  share|improve this answer











                                                                                                                  $endgroup$













                                                                                                                  • $begingroup$
                                                                                                                    it returns true for aabcabc
                                                                                                                    $endgroup$
                                                                                                                    – mazzy
                                                                                                                    Apr 25 at 3:41






                                                                                                                  • 1




                                                                                                                    $begingroup$
                                                                                                                    @mazzy just fixed!
                                                                                                                    $endgroup$
                                                                                                                    – Gabriel Mills
                                                                                                                    Apr 25 at 11:38














                                                                                                                  3












                                                                                                                  3








                                                                                                                  3





                                                                                                                  $begingroup$

                                                                                                                  PowerShell, 23 24 bytes



                                                                                                                  +1 byte to fully match rules



                                                                                                                  "$args"-match"^(.+)1+$"


                                                                                                                  Try it online!



                                                                                                                  Pretty boring. Based on the other Regex answers. Luckily PowerShell doesn't use as an escape character!






                                                                                                                  share|improve this answer











                                                                                                                  $endgroup$



                                                                                                                  PowerShell, 23 24 bytes



                                                                                                                  +1 byte to fully match rules



                                                                                                                  "$args"-match"^(.+)1+$"


                                                                                                                  Try it online!



                                                                                                                  Pretty boring. Based on the other Regex answers. Luckily PowerShell doesn't use as an escape character!







                                                                                                                  share|improve this answer














                                                                                                                  share|improve this answer



                                                                                                                  share|improve this answer








                                                                                                                  edited Apr 25 at 11:36

























                                                                                                                  answered Apr 24 at 20:13









                                                                                                                  Gabriel MillsGabriel Mills

                                                                                                                  673213




                                                                                                                  673213












                                                                                                                  • $begingroup$
                                                                                                                    it returns true for aabcabc
                                                                                                                    $endgroup$
                                                                                                                    – mazzy
                                                                                                                    Apr 25 at 3:41






                                                                                                                  • 1




                                                                                                                    $begingroup$
                                                                                                                    @mazzy just fixed!
                                                                                                                    $endgroup$
                                                                                                                    – Gabriel Mills
                                                                                                                    Apr 25 at 11:38


















                                                                                                                  • $begingroup$
                                                                                                                    it returns true for aabcabc
                                                                                                                    $endgroup$
                                                                                                                    – mazzy
                                                                                                                    Apr 25 at 3:41






                                                                                                                  • 1




                                                                                                                    $begingroup$
                                                                                                                    @mazzy just fixed!
                                                                                                                    $endgroup$
                                                                                                                    – Gabriel Mills
                                                                                                                    Apr 25 at 11:38
















                                                                                                                  $begingroup$
                                                                                                                  it returns true for aabcabc
                                                                                                                  $endgroup$
                                                                                                                  – mazzy
                                                                                                                  Apr 25 at 3:41




                                                                                                                  $begingroup$
                                                                                                                  it returns true for aabcabc
                                                                                                                  $endgroup$
                                                                                                                  – mazzy
                                                                                                                  Apr 25 at 3:41




                                                                                                                  1




                                                                                                                  1




                                                                                                                  $begingroup$
                                                                                                                  @mazzy just fixed!
                                                                                                                  $endgroup$
                                                                                                                  – Gabriel Mills
                                                                                                                  Apr 25 at 11:38




                                                                                                                  $begingroup$
                                                                                                                  @mazzy just fixed!
                                                                                                                  $endgroup$
                                                                                                                  – Gabriel Mills
                                                                                                                  Apr 25 at 11:38











                                                                                                                  3












                                                                                                                  $begingroup$


                                                                                                                  C# (Visual C# Interactive Compiler), 70 bytes



                                                                                                                  xnor's shameless adaptation (46 bytes)



                                                                                                                  s=>(s+s).Substring(1,s.Length*2-2).Contains(s)


                                                                                                                  My non Regex Solution:



                                                                                                                  s=>s.Select((x,y)=>y).Count(z=>s.Replace(s.Substring(0,z+1),"")=="")>1


                                                                                                                  Explanation:



                                                                                                                  Replace every possible substring that starts at index 0 with an empty string. If the result is an empty string, the string is entirely made of that substring. Since this includes evaluating the entire string with itself, the amount of expected results must be greater than 1.



                                                                                                                  Example: abcabc



                                                                                                                  Possible substrings starting at index 0:



                                                                                                                  'a', 'ab', 'abc', 'abca', 'abcab', 'abcabc'


                                                                                                                  If we replace them with empty strings



                                                                                                                  Substring          Result

                                                                                                                  'a' => 'bcbc'
                                                                                                                  'ab' => 'cc'
                                                                                                                  'abc' => ''
                                                                                                                  'abca' => 'bc'
                                                                                                                  'abcab' => 'c'
                                                                                                                  'abcabc' => ''


                                                                                                                  Since there is a substring other than 'abcabc' that returns an empty string, the string is entirely made of another substring ('abc')



                                                                                                                  Try it online!






                                                                                                                  share|improve this answer











                                                                                                                  $endgroup$


















                                                                                                                    3












                                                                                                                    $begingroup$


                                                                                                                    C# (Visual C# Interactive Compiler), 70 bytes



                                                                                                                    xnor's shameless adaptation (46 bytes)



                                                                                                                    s=>(s+s).Substring(1,s.Length*2-2).Contains(s)


                                                                                                                    My non Regex Solution:



                                                                                                                    s=>s.Select((x,y)=>y).Count(z=>s.Replace(s.Substring(0,z+1),"")=="")>1


                                                                                                                    Explanation:



                                                                                                                    Replace every possible substring that starts at index 0 with an empty string. If the result is an empty string, the string is entirely made of that substring. Since this includes evaluating the entire string with itself, the amount of expected results must be greater than 1.



                                                                                                                    Example: abcabc



                                                                                                                    Possible substrings starting at index 0:



                                                                                                                    'a', 'ab', 'abc', 'abca', 'abcab', 'abcabc'


                                                                                                                    If we replace them with empty strings



                                                                                                                    Substring          Result

                                                                                                                    'a' => 'bcbc'
                                                                                                                    'ab' => 'cc'
                                                                                                                    'abc' => ''
                                                                                                                    'abca' => 'bc'
                                                                                                                    'abcab' => 'c'
                                                                                                                    'abcabc' => ''


                                                                                                                    Since there is a substring other than 'abcabc' that returns an empty string, the string is entirely made of another substring ('abc')



                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$
















                                                                                                                      3












                                                                                                                      3








                                                                                                                      3





                                                                                                                      $begingroup$


                                                                                                                      C# (Visual C# Interactive Compiler), 70 bytes



                                                                                                                      xnor's shameless adaptation (46 bytes)



                                                                                                                      s=>(s+s).Substring(1,s.Length*2-2).Contains(s)


                                                                                                                      My non Regex Solution:



                                                                                                                      s=>s.Select((x,y)=>y).Count(z=>s.Replace(s.Substring(0,z+1),"")=="")>1


                                                                                                                      Explanation:



                                                                                                                      Replace every possible substring that starts at index 0 with an empty string. If the result is an empty string, the string is entirely made of that substring. Since this includes evaluating the entire string with itself, the amount of expected results must be greater than 1.



                                                                                                                      Example: abcabc



                                                                                                                      Possible substrings starting at index 0:



                                                                                                                      'a', 'ab', 'abc', 'abca', 'abcab', 'abcabc'


                                                                                                                      If we replace them with empty strings



                                                                                                                      Substring          Result

                                                                                                                      'a' => 'bcbc'
                                                                                                                      'ab' => 'cc'
                                                                                                                      'abc' => ''
                                                                                                                      'abca' => 'bc'
                                                                                                                      'abcab' => 'c'
                                                                                                                      'abcabc' => ''


                                                                                                                      Since there is a substring other than 'abcabc' that returns an empty string, the string is entirely made of another substring ('abc')



                                                                                                                      Try it online!






                                                                                                                      share|improve this answer











                                                                                                                      $endgroup$




                                                                                                                      C# (Visual C# Interactive Compiler), 70 bytes



                                                                                                                      xnor's shameless adaptation (46 bytes)



                                                                                                                      s=>(s+s).Substring(1,s.Length*2-2).Contains(s)


                                                                                                                      My non Regex Solution:



                                                                                                                      s=>s.Select((x,y)=>y).Count(z=>s.Replace(s.Substring(0,z+1),"")=="")>1


                                                                                                                      Explanation:



                                                                                                                      Replace every possible substring that starts at index 0 with an empty string. If the result is an empty string, the string is entirely made of that substring. Since this includes evaluating the entire string with itself, the amount of expected results must be greater than 1.



                                                                                                                      Example: abcabc



                                                                                                                      Possible substrings starting at index 0:



                                                                                                                      'a', 'ab', 'abc', 'abca', 'abcab', 'abcabc'


                                                                                                                      If we replace them with empty strings



                                                                                                                      Substring          Result

                                                                                                                      'a' => 'bcbc'
                                                                                                                      'ab' => 'cc'
                                                                                                                      'abc' => ''
                                                                                                                      'abca' => 'bc'
                                                                                                                      'abcab' => 'c'
                                                                                                                      'abcabc' => ''


                                                                                                                      Since there is a substring other than 'abcabc' that returns an empty string, the string is entirely made of another substring ('abc')



                                                                                                                      Try it online!







                                                                                                                      share|improve this answer














                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer








                                                                                                                      edited Apr 26 at 12:37

























                                                                                                                      answered Apr 25 at 9:09









                                                                                                                      Innat3Innat3

                                                                                                                      3014




                                                                                                                      3014























                                                                                                                          3












                                                                                                                          $begingroup$


                                                                                                                          Python 3, 62 60 56 54 bytes



                                                                                                                          -4 bytes thanx to ArBo





                                                                                                                          lambda s:s in(len(s)//l*s[:l]for l in range(1,len(s)))



                                                                                                                          1. Iterate over all possible prefixes in the string.

                                                                                                                          2. Try to build the string out of the prefix.

                                                                                                                          3. Return whether this succeeds with any prefix at all.


                                                                                                                          Try it online!






                                                                                                                          share|improve this answer











                                                                                                                          $endgroup$









                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes
                                                                                                                            $endgroup$
                                                                                                                            – ArBo
                                                                                                                            Apr 26 at 8:09








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice catch with the list membership, thanx! I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;) Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?
                                                                                                                            $endgroup$
                                                                                                                            – movatica
                                                                                                                            Apr 26 at 14:13








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            @movatica In the header, put `f = ` ( is the line continuation character in python)
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:33












                                                                                                                          • $begingroup$
                                                                                                                            Annoyingly, is also an escape character. Here, without code formatting, is what you should put in the header: f =
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:35
















                                                                                                                          3












                                                                                                                          $begingroup$


                                                                                                                          Python 3, 62 60 56 54 bytes



                                                                                                                          -4 bytes thanx to ArBo





                                                                                                                          lambda s:s in(len(s)//l*s[:l]for l in range(1,len(s)))



                                                                                                                          1. Iterate over all possible prefixes in the string.

                                                                                                                          2. Try to build the string out of the prefix.

                                                                                                                          3. Return whether this succeeds with any prefix at all.


                                                                                                                          Try it online!






                                                                                                                          share|improve this answer











                                                                                                                          $endgroup$









                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes
                                                                                                                            $endgroup$
                                                                                                                            – ArBo
                                                                                                                            Apr 26 at 8:09








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice catch with the list membership, thanx! I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;) Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?
                                                                                                                            $endgroup$
                                                                                                                            – movatica
                                                                                                                            Apr 26 at 14:13








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            @movatica In the header, put `f = ` ( is the line continuation character in python)
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:33












                                                                                                                          • $begingroup$
                                                                                                                            Annoyingly, is also an escape character. Here, without code formatting, is what you should put in the header: f =
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:35














                                                                                                                          3












                                                                                                                          3








                                                                                                                          3





                                                                                                                          $begingroup$


                                                                                                                          Python 3, 62 60 56 54 bytes



                                                                                                                          -4 bytes thanx to ArBo





                                                                                                                          lambda s:s in(len(s)//l*s[:l]for l in range(1,len(s)))



                                                                                                                          1. Iterate over all possible prefixes in the string.

                                                                                                                          2. Try to build the string out of the prefix.

                                                                                                                          3. Return whether this succeeds with any prefix at all.


                                                                                                                          Try it online!






                                                                                                                          share|improve this answer











                                                                                                                          $endgroup$




                                                                                                                          Python 3, 62 60 56 54 bytes



                                                                                                                          -4 bytes thanx to ArBo





                                                                                                                          lambda s:s in(len(s)//l*s[:l]for l in range(1,len(s)))



                                                                                                                          1. Iterate over all possible prefixes in the string.

                                                                                                                          2. Try to build the string out of the prefix.

                                                                                                                          3. Return whether this succeeds with any prefix at all.


                                                                                                                          Try it online!







                                                                                                                          share|improve this answer














                                                                                                                          share|improve this answer



                                                                                                                          share|improve this answer








                                                                                                                          edited Apr 28 at 0:50

























                                                                                                                          answered Apr 25 at 19:11









                                                                                                                          movaticamovatica

                                                                                                                          1786




                                                                                                                          1786








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes
                                                                                                                            $endgroup$
                                                                                                                            – ArBo
                                                                                                                            Apr 26 at 8:09








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice catch with the list membership, thanx! I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;) Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?
                                                                                                                            $endgroup$
                                                                                                                            – movatica
                                                                                                                            Apr 26 at 14:13








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            @movatica In the header, put `f = ` ( is the line continuation character in python)
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:33












                                                                                                                          • $begingroup$
                                                                                                                            Annoyingly, is also an escape character. Here, without code formatting, is what you should put in the header: f =
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:35














                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes
                                                                                                                            $endgroup$
                                                                                                                            – ArBo
                                                                                                                            Apr 26 at 8:09








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            Nice catch with the list membership, thanx! I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;) Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?
                                                                                                                            $endgroup$
                                                                                                                            – movatica
                                                                                                                            Apr 26 at 14:13








                                                                                                                          • 1




                                                                                                                            $begingroup$
                                                                                                                            @movatica In the header, put `f = ` ( is the line continuation character in python)
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:33












                                                                                                                          • $begingroup$
                                                                                                                            Annoyingly, is also an escape character. Here, without code formatting, is what you should put in the header: f =
                                                                                                                            $endgroup$
                                                                                                                            – Artemis Fowl
                                                                                                                            Apr 26 at 15:35








                                                                                                                          1




                                                                                                                          1




                                                                                                                          $begingroup$
                                                                                                                          Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes
                                                                                                                          $endgroup$
                                                                                                                          – ArBo
                                                                                                                          Apr 26 at 8:09






                                                                                                                          $begingroup$
                                                                                                                          Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes
                                                                                                                          $endgroup$
                                                                                                                          – ArBo
                                                                                                                          Apr 26 at 8:09






                                                                                                                          1




                                                                                                                          1




                                                                                                                          $begingroup$
                                                                                                                          Nice catch with the list membership, thanx! I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;) Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?
                                                                                                                          $endgroup$
                                                                                                                          – movatica
                                                                                                                          Apr 26 at 14:13






                                                                                                                          $begingroup$
                                                                                                                          Nice catch with the list membership, thanx! I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;) Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?
                                                                                                                          $endgroup$
                                                                                                                          – movatica
                                                                                                                          Apr 26 at 14:13






                                                                                                                          1




                                                                                                                          1




                                                                                                                          $begingroup$
                                                                                                                          @movatica In the header, put `f = ` ( is the line continuation character in python)
                                                                                                                          $endgroup$
                                                                                                                          – Artemis Fowl
                                                                                                                          Apr 26 at 15:33






                                                                                                                          $begingroup$
                                                                                                                          @movatica In the header, put `f = ` ( is the line continuation character in python)
                                                                                                                          $endgroup$
                                                                                                                          – Artemis Fowl
                                                                                                                          Apr 26 at 15:33














                                                                                                                          $begingroup$
                                                                                                                          Annoyingly, is also an escape character. Here, without code formatting, is what you should put in the header: f =
                                                                                                                          $endgroup$
                                                                                                                          – Artemis Fowl
                                                                                                                          Apr 26 at 15:35




                                                                                                                          $begingroup$
                                                                                                                          Annoyingly, is also an escape character. Here, without code formatting, is what you should put in the header: f =
                                                                                                                          $endgroup$
                                                                                                                          – Artemis Fowl
                                                                                                                          Apr 26 at 15:35











                                                                                                                          2












                                                                                                                          $begingroup$


                                                                                                                          Japt, 10 bytes



                                                                                                                          Returns a positive number if truthy and 0 if falsey. If you want a bool output just add flag



                                                                                                                          å+ k@rXÃÊÉ




                                                                                                                          å+ k@rXÃÊÉ      Full program. Implicit input U.
                                                                                                                          e.g: U = "abcabcabc"
                                                                                                                          å+ Take all prefixes
                                                                                                                          U = ["a","ab","abc","abca","abcab","abcabc","abcabca","abcabcab","abcabcabc"]
                                                                                                                          k@ Filter U by:
                                                                                                                          rXÃ Values that return false (empty string)
                                                                                                                          when replacing each prefix in U
                                                                                                                          e.g: ["bcbcbc","ccc","","bcabc","cabc","abc","bc","c",""]
                                                                                                                          take ↑ and ↑
                                                                                                                          U = ["abc","abcabcabc"]
                                                                                                                          ÊÉ Get U length and subtract 1. Then return the result


                                                                                                                          Try it online!






                                                                                                                          share|improve this answer











                                                                                                                          $endgroup$


















                                                                                                                            2












                                                                                                                            $begingroup$


                                                                                                                            Japt, 10 bytes



                                                                                                                            Returns a positive number if truthy and 0 if falsey. If you want a bool output just add flag



                                                                                                                            å+ k@rXÃÊÉ




                                                                                                                            å+ k@rXÃÊÉ      Full program. Implicit input U.
                                                                                                                            e.g: U = "abcabcabc"
                                                                                                                            å+ Take all prefixes
                                                                                                                            U = ["a","ab","abc","abca","abcab","abcabc","abcabca","abcabcab","abcabcabc"]
                                                                                                                            k@ Filter U by:
                                                                                                                            rXÃ Values that return false (empty string)
                                                                                                                            when replacing each prefix in U
                                                                                                                            e.g: ["bcbcbc","ccc","","bcabc","cabc","abc","bc","c",""]
                                                                                                                            take ↑ and ↑
                                                                                                                            U = ["abc","abcabcabc"]
                                                                                                                            ÊÉ Get U length and subtract 1. Then return the result


                                                                                                                            Try it online!






                                                                                                                            share|improve this answer











                                                                                                                            $endgroup$
















                                                                                                                              2












                                                                                                                              2








                                                                                                                              2





                                                                                                                              $begingroup$


                                                                                                                              Japt, 10 bytes



                                                                                                                              Returns a positive number if truthy and 0 if falsey. If you want a bool output just add flag



                                                                                                                              å+ k@rXÃÊÉ




                                                                                                                              å+ k@rXÃÊÉ      Full program. Implicit input U.
                                                                                                                              e.g: U = "abcabcabc"
                                                                                                                              å+ Take all prefixes
                                                                                                                              U = ["a","ab","abc","abca","abcab","abcabc","abcabca","abcabcab","abcabcabc"]
                                                                                                                              k@ Filter U by:
                                                                                                                              rXÃ Values that return false (empty string)
                                                                                                                              when replacing each prefix in U
                                                                                                                              e.g: ["bcbcbc","ccc","","bcabc","cabc","abc","bc","c",""]
                                                                                                                              take ↑ and ↑
                                                                                                                              U = ["abc","abcabcabc"]
                                                                                                                              ÊÉ Get U length and subtract 1. Then return the result


                                                                                                                              Try it online!






                                                                                                                              share|improve this answer











                                                                                                                              $endgroup$




                                                                                                                              Japt, 10 bytes



                                                                                                                              Returns a positive number if truthy and 0 if falsey. If you want a bool output just add flag



                                                                                                                              å+ k@rXÃÊÉ




                                                                                                                              å+ k@rXÃÊÉ      Full program. Implicit input U.
                                                                                                                              e.g: U = "abcabcabc"
                                                                                                                              å+ Take all prefixes
                                                                                                                              U = ["a","ab","abc","abca","abcab","abcabc","abcabca","abcabcab","abcabcabc"]
                                                                                                                              k@ Filter U by:
                                                                                                                              rXÃ Values that return false (empty string)
                                                                                                                              when replacing each prefix in U
                                                                                                                              e.g: ["bcbcbc","ccc","","bcabc","cabc","abc","bc","c",""]
                                                                                                                              take ↑ and ↑
                                                                                                                              U = ["abc","abcabcabc"]
                                                                                                                              ÊÉ Get U length and subtract 1. Then return the result


                                                                                                                              Try it online!







                                                                                                                              share|improve this answer














                                                                                                                              share|improve this answer



                                                                                                                              share|improve this answer








                                                                                                                              edited Apr 24 at 15:33

























                                                                                                                              answered Apr 24 at 15:18









                                                                                                                              Luis felipe De jesus MunozLuis felipe De jesus Munoz

                                                                                                                              6,30121874




                                                                                                                              6,30121874























                                                                                                                                  2












                                                                                                                                  $begingroup$


                                                                                                                                  Husk, 6 bytes



                                                                                                                                  Ṡ€ȯhtD


                                                                                                                                  Try it online!



                                                                                                                                  I feel like this is one byte more than optimal, but I couldn't find an arrangement that made the explicit composition ȯ unnecessary.



                                                                                                                                  Explanation



                                                                                                                                  Ṡ€      Find the argument in the result of applying the following function to the argument
                                                                                                                                  ȯhtD Duplicate the argument, then remove the first and last elements.





                                                                                                                                  share|improve this answer









                                                                                                                                  $endgroup$









                                                                                                                                  • 2




                                                                                                                                    $begingroup$
                                                                                                                                    €htD¹ avoids the ȯ.
                                                                                                                                    $endgroup$
                                                                                                                                    – Zgarb
                                                                                                                                    Apr 24 at 19:30










                                                                                                                                  • $begingroup$
                                                                                                                                    That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly
                                                                                                                                    $endgroup$
                                                                                                                                    – Sophia Lechner
                                                                                                                                    Apr 24 at 20:10
















                                                                                                                                  2












                                                                                                                                  $begingroup$


                                                                                                                                  Husk, 6 bytes



                                                                                                                                  Ṡ€ȯhtD


                                                                                                                                  Try it online!



                                                                                                                                  I feel like this is one byte more than optimal, but I couldn't find an arrangement that made the explicit composition ȯ unnecessary.



                                                                                                                                  Explanation



                                                                                                                                  Ṡ€      Find the argument in the result of applying the following function to the argument
                                                                                                                                  ȯhtD Duplicate the argument, then remove the first and last elements.





                                                                                                                                  share|improve this answer









                                                                                                                                  $endgroup$









                                                                                                                                  • 2




                                                                                                                                    $begingroup$
                                                                                                                                    €htD¹ avoids the ȯ.
                                                                                                                                    $endgroup$
                                                                                                                                    – Zgarb
                                                                                                                                    Apr 24 at 19:30










                                                                                                                                  • $begingroup$
                                                                                                                                    That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly
                                                                                                                                    $endgroup$
                                                                                                                                    – Sophia Lechner
                                                                                                                                    Apr 24 at 20:10














                                                                                                                                  2












                                                                                                                                  2








                                                                                                                                  2





                                                                                                                                  $begingroup$


                                                                                                                                  Husk, 6 bytes



                                                                                                                                  Ṡ€ȯhtD


                                                                                                                                  Try it online!



                                                                                                                                  I feel like this is one byte more than optimal, but I couldn't find an arrangement that made the explicit composition ȯ unnecessary.



                                                                                                                                  Explanation



                                                                                                                                  Ṡ€      Find the argument in the result of applying the following function to the argument
                                                                                                                                  ȯhtD Duplicate the argument, then remove the first and last elements.





                                                                                                                                  share|improve this answer









                                                                                                                                  $endgroup$




                                                                                                                                  Husk, 6 bytes



                                                                                                                                  Ṡ€ȯhtD


                                                                                                                                  Try it online!



                                                                                                                                  I feel like this is one byte more than optimal, but I couldn't find an arrangement that made the explicit composition ȯ unnecessary.



                                                                                                                                  Explanation



                                                                                                                                  Ṡ€      Find the argument in the result of applying the following function to the argument
                                                                                                                                  ȯhtD Duplicate the argument, then remove the first and last elements.






                                                                                                                                  share|improve this answer












                                                                                                                                  share|improve this answer



                                                                                                                                  share|improve this answer










                                                                                                                                  answered Apr 24 at 17:16









                                                                                                                                  Sophia LechnerSophia Lechner

                                                                                                                                  1,03018




                                                                                                                                  1,03018








                                                                                                                                  • 2




                                                                                                                                    $begingroup$
                                                                                                                                    €htD¹ avoids the ȯ.
                                                                                                                                    $endgroup$
                                                                                                                                    – Zgarb
                                                                                                                                    Apr 24 at 19:30










                                                                                                                                  • $begingroup$
                                                                                                                                    That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly
                                                                                                                                    $endgroup$
                                                                                                                                    – Sophia Lechner
                                                                                                                                    Apr 24 at 20:10














                                                                                                                                  • 2




                                                                                                                                    $begingroup$
                                                                                                                                    €htD¹ avoids the ȯ.
                                                                                                                                    $endgroup$
                                                                                                                                    – Zgarb
                                                                                                                                    Apr 24 at 19:30










                                                                                                                                  • $begingroup$
                                                                                                                                    That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly
                                                                                                                                    $endgroup$
                                                                                                                                    – Sophia Lechner
                                                                                                                                    Apr 24 at 20:10








                                                                                                                                  2




                                                                                                                                  2




                                                                                                                                  $begingroup$
                                                                                                                                  €htD¹ avoids the ȯ.
                                                                                                                                  $endgroup$
                                                                                                                                  – Zgarb
                                                                                                                                  Apr 24 at 19:30




                                                                                                                                  $begingroup$
                                                                                                                                  €htD¹ avoids the ȯ.
                                                                                                                                  $endgroup$
                                                                                                                                  – Zgarb
                                                                                                                                  Apr 24 at 19:30












                                                                                                                                  $begingroup$
                                                                                                                                  That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly
                                                                                                                                  $endgroup$
                                                                                                                                  – Sophia Lechner
                                                                                                                                  Apr 24 at 20:10




                                                                                                                                  $begingroup$
                                                                                                                                  That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly
                                                                                                                                  $endgroup$
                                                                                                                                  – Sophia Lechner
                                                                                                                                  Apr 24 at 20:10











                                                                                                                                  2












                                                                                                                                  $begingroup$

                                                                                                                                  Mathematica 11.x, 74 bytes



                                                                                                                                  {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&


                                                                                                                                  where, throughout, # represents the input string, and



                                                                                                                                  StringCases[#,<pattern>]


                                                                                                                                  finds substrings of the input string matching the pattern



                                                                                                                                  StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="") 


                                                                                                                                  This pattern requires matches, x, must start at the start of the string and must satisfy the condition that (1) the match is not the whole input string and (2) if we replace occurrences of the match in the input string with the empty string we obtain the empty string. Finally, comparing the list of matches to the empty list,



                                                                                                                                  {}!=


                                                                                                                                  is True if the list of matches is nonempty and False if the list of matches is empty.



                                                                                                                                  Test cases:



                                                                                                                                  {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aa"]
                                                                                                                                  (* True *)
                                                                                                                                  {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aaa"]
                                                                                                                                  (* True *)
                                                                                                                                  {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["abcabc"]
                                                                                                                                  (* True *)


                                                                                                                                  and



                                                                                                                                  {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aba"]
                                                                                                                                  (* False *)
                                                                                                                                  {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["ababa"]
                                                                                                                                  (* False *)
                                                                                                                                  {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["weqweqweqweqweqw"]
                                                                                                                                  (* False *)





                                                                                                                                  share|improve this answer









                                                                                                                                  $endgroup$


















                                                                                                                                    2












                                                                                                                                    $begingroup$

                                                                                                                                    Mathematica 11.x, 74 bytes



                                                                                                                                    {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&


                                                                                                                                    where, throughout, # represents the input string, and



                                                                                                                                    StringCases[#,<pattern>]


                                                                                                                                    finds substrings of the input string matching the pattern



                                                                                                                                    StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="") 


                                                                                                                                    This pattern requires matches, x, must start at the start of the string and must satisfy the condition that (1) the match is not the whole input string and (2) if we replace occurrences of the match in the input string with the empty string we obtain the empty string. Finally, comparing the list of matches to the empty list,



                                                                                                                                    {}!=


                                                                                                                                    is True if the list of matches is nonempty and False if the list of matches is empty.



                                                                                                                                    Test cases:



                                                                                                                                    {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aa"]
                                                                                                                                    (* True *)
                                                                                                                                    {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aaa"]
                                                                                                                                    (* True *)
                                                                                                                                    {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["abcabc"]
                                                                                                                                    (* True *)


                                                                                                                                    and



                                                                                                                                    {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aba"]
                                                                                                                                    (* False *)
                                                                                                                                    {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["ababa"]
                                                                                                                                    (* False *)
                                                                                                                                    {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["weqweqweqweqweqw"]
                                                                                                                                    (* False *)





                                                                                                                                    share|improve this answer









                                                                                                                                    $endgroup$
















                                                                                                                                      2












                                                                                                                                      2








                                                                                                                                      2





                                                                                                                                      $begingroup$

                                                                                                                                      Mathematica 11.x, 74 bytes



                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&


                                                                                                                                      where, throughout, # represents the input string, and



                                                                                                                                      StringCases[#,<pattern>]


                                                                                                                                      finds substrings of the input string matching the pattern



                                                                                                                                      StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="") 


                                                                                                                                      This pattern requires matches, x, must start at the start of the string and must satisfy the condition that (1) the match is not the whole input string and (2) if we replace occurrences of the match in the input string with the empty string we obtain the empty string. Finally, comparing the list of matches to the empty list,



                                                                                                                                      {}!=


                                                                                                                                      is True if the list of matches is nonempty and False if the list of matches is empty.



                                                                                                                                      Test cases:



                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aa"]
                                                                                                                                      (* True *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aaa"]
                                                                                                                                      (* True *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["abcabc"]
                                                                                                                                      (* True *)


                                                                                                                                      and



                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aba"]
                                                                                                                                      (* False *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["ababa"]
                                                                                                                                      (* False *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["weqweqweqweqweqw"]
                                                                                                                                      (* False *)





                                                                                                                                      share|improve this answer









                                                                                                                                      $endgroup$



                                                                                                                                      Mathematica 11.x, 74 bytes



                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&


                                                                                                                                      where, throughout, # represents the input string, and



                                                                                                                                      StringCases[#,<pattern>]


                                                                                                                                      finds substrings of the input string matching the pattern



                                                                                                                                      StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="") 


                                                                                                                                      This pattern requires matches, x, must start at the start of the string and must satisfy the condition that (1) the match is not the whole input string and (2) if we replace occurrences of the match in the input string with the empty string we obtain the empty string. Finally, comparing the list of matches to the empty list,



                                                                                                                                      {}!=


                                                                                                                                      is True if the list of matches is nonempty and False if the list of matches is empty.



                                                                                                                                      Test cases:



                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aa"]
                                                                                                                                      (* True *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aaa"]
                                                                                                                                      (* True *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["abcabc"]
                                                                                                                                      (* True *)


                                                                                                                                      and



                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aba"]
                                                                                                                                      (* False *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["ababa"]
                                                                                                                                      (* False *)
                                                                                                                                      {}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["weqweqweqweqweqw"]
                                                                                                                                      (* False *)






                                                                                                                                      share|improve this answer












                                                                                                                                      share|improve this answer



                                                                                                                                      share|improve this answer










                                                                                                                                      answered Apr 24 at 17:40









                                                                                                                                      Eric TowersEric Towers

                                                                                                                                      66637




                                                                                                                                      66637























                                                                                                                                          2












                                                                                                                                          $begingroup$

                                                                                                                                          Python 3, 84 bytes



                                                                                                                                          import textwrap
                                                                                                                                          lambda s:any(len(set(textwrap.wrap(s,l)))<2 for l in range(1,len(s)))


                                                                                                                                          Uses textwrap.wrap (thanks to this answer) to split the string into pieces of length n to test each possible length of repeating substring. The split pieces are then compared to each other by adding them to a set. If all of the pieces are equal, and the set is of length 1, then the string must be a repeating string. I used <2 instead of ==1 because it saves a byte, and the length of the input string was guaranteed to be greater than zero.



                                                                                                                                          If there is no n for which repeating substrings of length n make up the entire string, then return false for the whole function.






                                                                                                                                          share|improve this answer









                                                                                                                                          $endgroup$


















                                                                                                                                            2












                                                                                                                                            $begingroup$

                                                                                                                                            Python 3, 84 bytes



                                                                                                                                            import textwrap
                                                                                                                                            lambda s:any(len(set(textwrap.wrap(s,l)))<2 for l in range(1,len(s)))


                                                                                                                                            Uses textwrap.wrap (thanks to this answer) to split the string into pieces of length n to test each possible length of repeating substring. The split pieces are then compared to each other by adding them to a set. If all of the pieces are equal, and the set is of length 1, then the string must be a repeating string. I used <2 instead of ==1 because it saves a byte, and the length of the input string was guaranteed to be greater than zero.



                                                                                                                                            If there is no n for which repeating substrings of length n make up the entire string, then return false for the whole function.






                                                                                                                                            share|improve this answer









                                                                                                                                            $endgroup$
















                                                                                                                                              2












                                                                                                                                              2








                                                                                                                                              2





                                                                                                                                              $begingroup$

                                                                                                                                              Python 3, 84 bytes



                                                                                                                                              import textwrap
                                                                                                                                              lambda s:any(len(set(textwrap.wrap(s,l)))<2 for l in range(1,len(s)))


                                                                                                                                              Uses textwrap.wrap (thanks to this answer) to split the string into pieces of length n to test each possible length of repeating substring. The split pieces are then compared to each other by adding them to a set. If all of the pieces are equal, and the set is of length 1, then the string must be a repeating string. I used <2 instead of ==1 because it saves a byte, and the length of the input string was guaranteed to be greater than zero.



                                                                                                                                              If there is no n for which repeating substrings of length n make up the entire string, then return false for the whole function.






                                                                                                                                              share|improve this answer









                                                                                                                                              $endgroup$



                                                                                                                                              Python 3, 84 bytes



                                                                                                                                              import textwrap
                                                                                                                                              lambda s:any(len(set(textwrap.wrap(s,l)))<2 for l in range(1,len(s)))


                                                                                                                                              Uses textwrap.wrap (thanks to this answer) to split the string into pieces of length n to test each possible length of repeating substring. The split pieces are then compared to each other by adding them to a set. If all of the pieces are equal, and the set is of length 1, then the string must be a repeating string. I used <2 instead of ==1 because it saves a byte, and the length of the input string was guaranteed to be greater than zero.



                                                                                                                                              If there is no n for which repeating substrings of length n make up the entire string, then return false for the whole function.







                                                                                                                                              share|improve this answer












                                                                                                                                              share|improve this answer



                                                                                                                                              share|improve this answer










                                                                                                                                              answered Apr 24 at 20:20









                                                                                                                                              Delya ErricsonDelya Erricson

                                                                                                                                              8113




                                                                                                                                              8113























                                                                                                                                                  2












                                                                                                                                                  $begingroup$


                                                                                                                                                  05AB1E, 5 bytes



                                                                                                                                                  xnor's method from the previous question appears to be optimal in 05AB1E as well.



                                                                                                                                                  «¦¨så


                                                                                                                                                  Try it online!
                                                                                                                                                  or as a Test Suite



                                                                                                                                                  Explanation



                                                                                                                                                  «       # append input to input
                                                                                                                                                  ¦¨ # remove the first and last character of the resulting string
                                                                                                                                                  så # check if the input is in this string





                                                                                                                                                  share|improve this answer









                                                                                                                                                  $endgroup$









                                                                                                                                                  • 1




                                                                                                                                                    $begingroup$
                                                                                                                                                    Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Kevin Cruijssen
                                                                                                                                                    Apr 25 at 6:55










                                                                                                                                                  • $begingroup$
                                                                                                                                                    @KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Emigna
                                                                                                                                                    Apr 25 at 6:56
















                                                                                                                                                  2












                                                                                                                                                  $begingroup$


                                                                                                                                                  05AB1E, 5 bytes



                                                                                                                                                  xnor's method from the previous question appears to be optimal in 05AB1E as well.



                                                                                                                                                  «¦¨så


                                                                                                                                                  Try it online!
                                                                                                                                                  or as a Test Suite



                                                                                                                                                  Explanation



                                                                                                                                                  «       # append input to input
                                                                                                                                                  ¦¨ # remove the first and last character of the resulting string
                                                                                                                                                  så # check if the input is in this string





                                                                                                                                                  share|improve this answer









                                                                                                                                                  $endgroup$









                                                                                                                                                  • 1




                                                                                                                                                    $begingroup$
                                                                                                                                                    Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Kevin Cruijssen
                                                                                                                                                    Apr 25 at 6:55










                                                                                                                                                  • $begingroup$
                                                                                                                                                    @KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Emigna
                                                                                                                                                    Apr 25 at 6:56














                                                                                                                                                  2












                                                                                                                                                  2








                                                                                                                                                  2





                                                                                                                                                  $begingroup$


                                                                                                                                                  05AB1E, 5 bytes



                                                                                                                                                  xnor's method from the previous question appears to be optimal in 05AB1E as well.



                                                                                                                                                  «¦¨så


                                                                                                                                                  Try it online!
                                                                                                                                                  or as a Test Suite



                                                                                                                                                  Explanation



                                                                                                                                                  «       # append input to input
                                                                                                                                                  ¦¨ # remove the first and last character of the resulting string
                                                                                                                                                  så # check if the input is in this string





                                                                                                                                                  share|improve this answer









                                                                                                                                                  $endgroup$




                                                                                                                                                  05AB1E, 5 bytes



                                                                                                                                                  xnor's method from the previous question appears to be optimal in 05AB1E as well.



                                                                                                                                                  «¦¨så


                                                                                                                                                  Try it online!
                                                                                                                                                  or as a Test Suite



                                                                                                                                                  Explanation



                                                                                                                                                  «       # append input to input
                                                                                                                                                  ¦¨ # remove the first and last character of the resulting string
                                                                                                                                                  så # check if the input is in this string






                                                                                                                                                  share|improve this answer












                                                                                                                                                  share|improve this answer



                                                                                                                                                  share|improve this answer










                                                                                                                                                  answered Apr 25 at 6:33









                                                                                                                                                  EmignaEmigna

                                                                                                                                                  49.5k534150




                                                                                                                                                  49.5k534150








                                                                                                                                                  • 1




                                                                                                                                                    $begingroup$
                                                                                                                                                    Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Kevin Cruijssen
                                                                                                                                                    Apr 25 at 6:55










                                                                                                                                                  • $begingroup$
                                                                                                                                                    @KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Emigna
                                                                                                                                                    Apr 25 at 6:56














                                                                                                                                                  • 1




                                                                                                                                                    $begingroup$
                                                                                                                                                    Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Kevin Cruijssen
                                                                                                                                                    Apr 25 at 6:55










                                                                                                                                                  • $begingroup$
                                                                                                                                                    @KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)
                                                                                                                                                    $endgroup$
                                                                                                                                                    – Emigna
                                                                                                                                                    Apr 25 at 6:56








                                                                                                                                                  1




                                                                                                                                                  1




                                                                                                                                                  $begingroup$
                                                                                                                                                  Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD
                                                                                                                                                  $endgroup$
                                                                                                                                                  – Kevin Cruijssen
                                                                                                                                                  Apr 25 at 6:55




                                                                                                                                                  $begingroup$
                                                                                                                                                  Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD
                                                                                                                                                  $endgroup$
                                                                                                                                                  – Kevin Cruijssen
                                                                                                                                                  Apr 25 at 6:55












                                                                                                                                                  $begingroup$
                                                                                                                                                  @KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)
                                                                                                                                                  $endgroup$
                                                                                                                                                  – Emigna
                                                                                                                                                  Apr 25 at 6:56




                                                                                                                                                  $begingroup$
                                                                                                                                                  @KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)
                                                                                                                                                  $endgroup$
                                                                                                                                                  – Emigna
                                                                                                                                                  Apr 25 at 6:56











                                                                                                                                                  2












                                                                                                                                                  $begingroup$


                                                                                                                                                  Clean, 73 bytes



                                                                                                                                                  Doesn't use regex.



                                                                                                                                                  import StdEnv,Data.List
                                                                                                                                                  $s=or[isPrefixOf s(cycle t)\t<-tl(tails s)|t>]


                                                                                                                                                  Try it online!



                                                                                                                                                  Defines $ :: [Char] -> Bool.

                                                                                                                                                  Checks if the given string is a prefix of the repetition of any sub-string taken from the end.






                                                                                                                                                  share|improve this answer









                                                                                                                                                  $endgroup$


















                                                                                                                                                    2












                                                                                                                                                    $begingroup$


                                                                                                                                                    Clean, 73 bytes



                                                                                                                                                    Doesn't use regex.



                                                                                                                                                    import StdEnv,Data.List
                                                                                                                                                    $s=or[isPrefixOf s(cycle t)\t<-tl(tails s)|t>]


                                                                                                                                                    Try it online!



                                                                                                                                                    Defines $ :: [Char] -> Bool.

                                                                                                                                                    Checks if the given string is a prefix of the repetition of any sub-string taken from the end.






                                                                                                                                                    share|improve this answer









                                                                                                                                                    $endgroup$
















                                                                                                                                                      2












                                                                                                                                                      2








                                                                                                                                                      2





                                                                                                                                                      $begingroup$


                                                                                                                                                      Clean, 73 bytes



                                                                                                                                                      Doesn't use regex.



                                                                                                                                                      import StdEnv,Data.List
                                                                                                                                                      $s=or[isPrefixOf s(cycle t)\t<-tl(tails s)|t>]


                                                                                                                                                      Try it online!



                                                                                                                                                      Defines $ :: [Char] -> Bool.

                                                                                                                                                      Checks if the given string is a prefix of the repetition of any sub-string taken from the end.






                                                                                                                                                      share|improve this answer









                                                                                                                                                      $endgroup$




                                                                                                                                                      Clean, 73 bytes



                                                                                                                                                      Doesn't use regex.



                                                                                                                                                      import StdEnv,Data.List
                                                                                                                                                      $s=or[isPrefixOf s(cycle t)\t<-tl(tails s)|t>]


                                                                                                                                                      Try it online!



                                                                                                                                                      Defines $ :: [Char] -> Bool.

                                                                                                                                                      Checks if the given string is a prefix of the repetition of any sub-string taken from the end.







                                                                                                                                                      share|improve this answer












                                                                                                                                                      share|improve this answer



                                                                                                                                                      share|improve this answer










                                                                                                                                                      answered Apr 26 at 0:43









                                                                                                                                                      ΟurousΟurous

                                                                                                                                                      7,47611136




                                                                                                                                                      7,47611136























                                                                                                                                                          2












                                                                                                                                                          $begingroup$


                                                                                                                                                          C++ (gcc), 36 bytes





                                                                                                                                                          #define f(x)(x+x).find(x,1)<x.size()


                                                                                                                                                          Try it online!



                                                                                                                                                          Another port of xnor's solution. Uses a macro to expand the argument into the expression. The argument is assumed to be of type std::string.






                                                                                                                                                          share|improve this answer











                                                                                                                                                          $endgroup$


















                                                                                                                                                            2












                                                                                                                                                            $begingroup$


                                                                                                                                                            C++ (gcc), 36 bytes





                                                                                                                                                            #define f(x)(x+x).find(x,1)<x.size()


                                                                                                                                                            Try it online!



                                                                                                                                                            Another port of xnor's solution. Uses a macro to expand the argument into the expression. The argument is assumed to be of type std::string.






                                                                                                                                                            share|improve this answer











                                                                                                                                                            $endgroup$
















                                                                                                                                                              2












                                                                                                                                                              2








                                                                                                                                                              2





                                                                                                                                                              $begingroup$


                                                                                                                                                              C++ (gcc), 36 bytes





                                                                                                                                                              #define f(x)(x+x).find(x,1)<x.size()


                                                                                                                                                              Try it online!



                                                                                                                                                              Another port of xnor's solution. Uses a macro to expand the argument into the expression. The argument is assumed to be of type std::string.






                                                                                                                                                              share|improve this answer











                                                                                                                                                              $endgroup$




                                                                                                                                                              C++ (gcc), 36 bytes





                                                                                                                                                              #define f(x)(x+x).find(x,1)<x.size()


                                                                                                                                                              Try it online!



                                                                                                                                                              Another port of xnor's solution. Uses a macro to expand the argument into the expression. The argument is assumed to be of type std::string.







                                                                                                                                                              share|improve this answer














                                                                                                                                                              share|improve this answer



                                                                                                                                                              share|improve this answer








                                                                                                                                                              edited Apr 26 at 15:35

























                                                                                                                                                              answered Apr 25 at 23:42









                                                                                                                                                              jxhjxh

                                                                                                                                                              32128




                                                                                                                                                              32128























                                                                                                                                                                  1












                                                                                                                                                                  $begingroup$

                                                                                                                                                                  QlikView Variable, 27 bytes



                                                                                                                                                                  This should be defined as a variable, which then allows you to pass parameters, e.g. $1 as your input value.



                                                                                                                                                                  It returns 0 or -1 (equivalent to QlikView's TRUE() function).



                                                                                                                                                                  =substringcount($1&$1,$1)>2





                                                                                                                                                                  share|improve this answer









                                                                                                                                                                  $endgroup$


















                                                                                                                                                                    1












                                                                                                                                                                    $begingroup$

                                                                                                                                                                    QlikView Variable, 27 bytes



                                                                                                                                                                    This should be defined as a variable, which then allows you to pass parameters, e.g. $1 as your input value.



                                                                                                                                                                    It returns 0 or -1 (equivalent to QlikView's TRUE() function).



                                                                                                                                                                    =substringcount($1&$1,$1)>2





                                                                                                                                                                    share|improve this answer









                                                                                                                                                                    $endgroup$
















                                                                                                                                                                      1












                                                                                                                                                                      1








                                                                                                                                                                      1





                                                                                                                                                                      $begingroup$

                                                                                                                                                                      QlikView Variable, 27 bytes



                                                                                                                                                                      This should be defined as a variable, which then allows you to pass parameters, e.g. $1 as your input value.



                                                                                                                                                                      It returns 0 or -1 (equivalent to QlikView's TRUE() function).



                                                                                                                                                                      =substringcount($1&$1,$1)>2





                                                                                                                                                                      share|improve this answer









                                                                                                                                                                      $endgroup$



                                                                                                                                                                      QlikView Variable, 27 bytes



                                                                                                                                                                      This should be defined as a variable, which then allows you to pass parameters, e.g. $1 as your input value.



                                                                                                                                                                      It returns 0 or -1 (equivalent to QlikView's TRUE() function).



                                                                                                                                                                      =substringcount($1&$1,$1)>2






                                                                                                                                                                      share|improve this answer












                                                                                                                                                                      share|improve this answer



                                                                                                                                                                      share|improve this answer










                                                                                                                                                                      answered Apr 24 at 19:19









                                                                                                                                                                      i_saw_dronesi_saw_drones

                                                                                                                                                                      2835




                                                                                                                                                                      2835























                                                                                                                                                                          1












                                                                                                                                                                          $begingroup$

                                                                                                                                                                          Swift, 196 bytes



                                                                                                                                                                          func r(s:String)->Bool{guard let k=s.dropFirst().firstIndex(where:{$0==s.first}) else{return false};let v=s[...k].dropLast();var w=v;while s.hasPrefix(w) && s.count>=(w+v).count{w+=v};return s==w}


                                                                                                                                                                          Try it online!






                                                                                                                                                                          share|improve this answer









                                                                                                                                                                          $endgroup$













                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            I don't use Swift, but I'm sure that extra whitespace can be removed
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Benjamin Urquhart
                                                                                                                                                                            Apr 24 at 19:56










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            193 bytes using @benjamin's suggestion.
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Artemis Fowl
                                                                                                                                                                            Apr 26 at 15:39










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            @ArtemisFowl or even 123 bytes
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Roman Podymov
                                                                                                                                                                            Apr 26 at 16:59


















                                                                                                                                                                          1












                                                                                                                                                                          $begingroup$

                                                                                                                                                                          Swift, 196 bytes



                                                                                                                                                                          func r(s:String)->Bool{guard let k=s.dropFirst().firstIndex(where:{$0==s.first}) else{return false};let v=s[...k].dropLast();var w=v;while s.hasPrefix(w) && s.count>=(w+v).count{w+=v};return s==w}


                                                                                                                                                                          Try it online!






                                                                                                                                                                          share|improve this answer









                                                                                                                                                                          $endgroup$













                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            I don't use Swift, but I'm sure that extra whitespace can be removed
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Benjamin Urquhart
                                                                                                                                                                            Apr 24 at 19:56










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            193 bytes using @benjamin's suggestion.
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Artemis Fowl
                                                                                                                                                                            Apr 26 at 15:39










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            @ArtemisFowl or even 123 bytes
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Roman Podymov
                                                                                                                                                                            Apr 26 at 16:59
















                                                                                                                                                                          1












                                                                                                                                                                          1








                                                                                                                                                                          1





                                                                                                                                                                          $begingroup$

                                                                                                                                                                          Swift, 196 bytes



                                                                                                                                                                          func r(s:String)->Bool{guard let k=s.dropFirst().firstIndex(where:{$0==s.first}) else{return false};let v=s[...k].dropLast();var w=v;while s.hasPrefix(w) && s.count>=(w+v).count{w+=v};return s==w}


                                                                                                                                                                          Try it online!






                                                                                                                                                                          share|improve this answer









                                                                                                                                                                          $endgroup$



                                                                                                                                                                          Swift, 196 bytes



                                                                                                                                                                          func r(s:String)->Bool{guard let k=s.dropFirst().firstIndex(where:{$0==s.first}) else{return false};let v=s[...k].dropLast();var w=v;while s.hasPrefix(w) && s.count>=(w+v).count{w+=v};return s==w}


                                                                                                                                                                          Try it online!







                                                                                                                                                                          share|improve this answer












                                                                                                                                                                          share|improve this answer



                                                                                                                                                                          share|improve this answer










                                                                                                                                                                          answered Apr 24 at 19:32









                                                                                                                                                                          onnowebonnoweb

                                                                                                                                                                          1713




                                                                                                                                                                          1713












                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            I don't use Swift, but I'm sure that extra whitespace can be removed
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Benjamin Urquhart
                                                                                                                                                                            Apr 24 at 19:56










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            193 bytes using @benjamin's suggestion.
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Artemis Fowl
                                                                                                                                                                            Apr 26 at 15:39










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            @ArtemisFowl or even 123 bytes
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Roman Podymov
                                                                                                                                                                            Apr 26 at 16:59




















                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            I don't use Swift, but I'm sure that extra whitespace can be removed
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Benjamin Urquhart
                                                                                                                                                                            Apr 24 at 19:56










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            193 bytes using @benjamin's suggestion.
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Artemis Fowl
                                                                                                                                                                            Apr 26 at 15:39










                                                                                                                                                                          • $begingroup$
                                                                                                                                                                            @ArtemisFowl or even 123 bytes
                                                                                                                                                                            $endgroup$
                                                                                                                                                                            – Roman Podymov
                                                                                                                                                                            Apr 26 at 16:59


















                                                                                                                                                                          $begingroup$
                                                                                                                                                                          I don't use Swift, but I'm sure that extra whitespace can be removed
                                                                                                                                                                          $endgroup$
                                                                                                                                                                          – Benjamin Urquhart
                                                                                                                                                                          Apr 24 at 19:56




                                                                                                                                                                          $begingroup$
                                                                                                                                                                          I don't use Swift, but I'm sure that extra whitespace can be removed
                                                                                                                                                                          $endgroup$
                                                                                                                                                                          – Benjamin Urquhart
                                                                                                                                                                          Apr 24 at 19:56












                                                                                                                                                                          $begingroup$
                                                                                                                                                                          193 bytes using @benjamin's suggestion.
                                                                                                                                                                          $endgroup$
                                                                                                                                                                          – Artemis Fowl
                                                                                                                                                                          Apr 26 at 15:39




                                                                                                                                                                          $begingroup$
                                                                                                                                                                          193 bytes using @benjamin's suggestion.
                                                                                                                                                                          $endgroup$
                                                                                                                                                                          – Artemis Fowl
                                                                                                                                                                          Apr 26 at 15:39












                                                                                                                                                                          $begingroup$
                                                                                                                                                                          @ArtemisFowl or even 123 bytes
                                                                                                                                                                          $endgroup$
                                                                                                                                                                          – Roman Podymov
                                                                                                                                                                          Apr 26 at 16:59






                                                                                                                                                                          $begingroup$
                                                                                                                                                                          @ArtemisFowl or even 123 bytes
                                                                                                                                                                          $endgroup$
                                                                                                                                                                          – Roman Podymov
                                                                                                                                                                          Apr 26 at 16:59













                                                                                                                                                                          1












                                                                                                                                                                          $begingroup$


                                                                                                                                                                          Icon, 46 bytes



                                                                                                                                                                          procedure f(s);return find(s,(s||s)[2:-1]);end


                                                                                                                                                                          Try it online!



                                                                                                                                                                          Another port of xnor's solution.






                                                                                                                                                                          share|improve this answer











                                                                                                                                                                          $endgroup$


















                                                                                                                                                                            1












                                                                                                                                                                            $begingroup$


                                                                                                                                                                            Icon, 46 bytes



                                                                                                                                                                            procedure f(s);return find(s,(s||s)[2:-1]);end


                                                                                                                                                                            Try it online!



                                                                                                                                                                            Another port of xnor's solution.






                                                                                                                                                                            share|improve this answer











                                                                                                                                                                            $endgroup$
















                                                                                                                                                                              1












                                                                                                                                                                              1








                                                                                                                                                                              1





                                                                                                                                                                              $begingroup$


                                                                                                                                                                              Icon, 46 bytes



                                                                                                                                                                              procedure f(s);return find(s,(s||s)[2:-1]);end


                                                                                                                                                                              Try it online!



                                                                                                                                                                              Another port of xnor's solution.






                                                                                                                                                                              share|improve this answer











                                                                                                                                                                              $endgroup$




                                                                                                                                                                              Icon, 46 bytes



                                                                                                                                                                              procedure f(s);return find(s,(s||s)[2:-1]);end


                                                                                                                                                                              Try it online!



                                                                                                                                                                              Another port of xnor's solution.







                                                                                                                                                                              share|improve this answer














                                                                                                                                                                              share|improve this answer



                                                                                                                                                                              share|improve this answer








                                                                                                                                                                              edited Apr 25 at 7:41

























                                                                                                                                                                              answered Apr 25 at 7:13









                                                                                                                                                                              Galen IvanovGalen Ivanov

                                                                                                                                                                              8,33211237




                                                                                                                                                                              8,33211237























                                                                                                                                                                                  1












                                                                                                                                                                                  $begingroup$


                                                                                                                                                                                  K (oK), 29 bytes



                                                                                                                                                                                  {0<+/(1=#?:)'(0N,'1_!#x)#:x}


                                                                                                                                                                                  Try it online!






                                                                                                                                                                                  share|improve this answer









                                                                                                                                                                                  $endgroup$


















                                                                                                                                                                                    1












                                                                                                                                                                                    $begingroup$


                                                                                                                                                                                    K (oK), 29 bytes



                                                                                                                                                                                    {0<+/(1=#?:)'(0N,'1_!#x)#:x}


                                                                                                                                                                                    Try it online!






                                                                                                                                                                                    share|improve this answer









                                                                                                                                                                                    $endgroup$
















                                                                                                                                                                                      1












                                                                                                                                                                                      1








                                                                                                                                                                                      1





                                                                                                                                                                                      $begingroup$


                                                                                                                                                                                      K (oK), 29 bytes



                                                                                                                                                                                      {0<+/(1=#?:)'(0N,'1_!#x)#:x}


                                                                                                                                                                                      Try it online!






                                                                                                                                                                                      share|improve this answer









                                                                                                                                                                                      $endgroup$




                                                                                                                                                                                      K (oK), 29 bytes



                                                                                                                                                                                      {0<+/(1=#?:)'(0N,'1_!#x)#:x}


                                                                                                                                                                                      Try it online!







                                                                                                                                                                                      share|improve this answer












                                                                                                                                                                                      share|improve this answer



                                                                                                                                                                                      share|improve this answer










                                                                                                                                                                                      answered Apr 25 at 8:52









                                                                                                                                                                                      Galen IvanovGalen Ivanov

                                                                                                                                                                                      8,33211237




                                                                                                                                                                                      8,33211237























                                                                                                                                                                                          1












                                                                                                                                                                                          $begingroup$


                                                                                                                                                                                          Red, 72 bytes



                                                                                                                                                                                          func[s][repeat i length? s[parse s[copy t i skip some t end(return 1)]]]


                                                                                                                                                                                          Try it online!



                                                                                                                                                                                          Returns 1 for True






                                                                                                                                                                                          share|improve this answer









                                                                                                                                                                                          $endgroup$


















                                                                                                                                                                                            1












                                                                                                                                                                                            $begingroup$


                                                                                                                                                                                            Red, 72 bytes



                                                                                                                                                                                            func[s][repeat i length? s[parse s[copy t i skip some t end(return 1)]]]


                                                                                                                                                                                            Try it online!



                                                                                                                                                                                            Returns 1 for True






                                                                                                                                                                                            share|improve this answer









                                                                                                                                                                                            $endgroup$
















                                                                                                                                                                                              1












                                                                                                                                                                                              1








                                                                                                                                                                                              1





                                                                                                                                                                                              $begingroup$


                                                                                                                                                                                              Red, 72 bytes



                                                                                                                                                                                              func[s][repeat i length? s[parse s[copy t i skip some t end(return 1)]]]


                                                                                                                                                                                              Try it online!



                                                                                                                                                                                              Returns 1 for True






                                                                                                                                                                                              share|improve this answer









                                                                                                                                                                                              $endgroup$




                                                                                                                                                                                              Red, 72 bytes



                                                                                                                                                                                              func[s][repeat i length? s[parse s[copy t i skip some t end(return 1)]]]


                                                                                                                                                                                              Try it online!



                                                                                                                                                                                              Returns 1 for True







                                                                                                                                                                                              share|improve this answer












                                                                                                                                                                                              share|improve this answer



                                                                                                                                                                                              share|improve this answer










                                                                                                                                                                                              answered Apr 25 at 10:36









                                                                                                                                                                                              Galen IvanovGalen Ivanov

                                                                                                                                                                                              8,33211237




                                                                                                                                                                                              8,33211237























                                                                                                                                                                                                  1












                                                                                                                                                                                                  $begingroup$

                                                                                                                                                                                                  T-SQL, 47 bytes



                                                                                                                                                                                                  Using @Xnor's method:



                                                                                                                                                                                                  DECLARE @ varchar(max)='ababab'

                                                                                                                                                                                                  PRINT sign(charindex(@,left(@+@,len(@)*2-1),2))


                                                                                                                                                                                                  Keeping old answer as it contains some nice golfing(67 bytes):



                                                                                                                                                                                                  DECLARE @y varchar(max)='abababa'

                                                                                                                                                                                                  ,@ INT=0WHILE
                                                                                                                                                                                                  replace(@y,left(@y,@),'')>''SET
                                                                                                                                                                                                  @+=1PRINT @/len(@y)^1


                                                                                                                                                                                                  Explanation: This script is repeatingly trying to replace the input '@y' with the first '@' characters of the input '@y' with nothing, while increasing '@'.




                                                                                                                                                                                                  if you replace 'ab' in 'ababab' with nothing you have an empty string




                                                                                                                                                                                                  Eventually the result will be empty. If this happens when the loop variable is equal to the length of the varchar, the criteria is false/0 because '@'=len(@y) (there was no repeating varchar).



                                                                                                                                                                                                  iif(@=len(@y),0,1)


                                                                                                                                                                                                  can be golfed into this



                                                                                                                                                                                                  @/len(@y)^1


                                                                                                                                                                                                  because the length of '@y' can not be 0 and '@' will never exceed the length @y.



                                                                                                                                                                                                  Try it online






                                                                                                                                                                                                  share|improve this answer











                                                                                                                                                                                                  $endgroup$


















                                                                                                                                                                                                    1












                                                                                                                                                                                                    $begingroup$

                                                                                                                                                                                                    T-SQL, 47 bytes



                                                                                                                                                                                                    Using @Xnor's method:



                                                                                                                                                                                                    DECLARE @ varchar(max)='ababab'

                                                                                                                                                                                                    PRINT sign(charindex(@,left(@+@,len(@)*2-1),2))


                                                                                                                                                                                                    Keeping old answer as it contains some nice golfing(67 bytes):



                                                                                                                                                                                                    DECLARE @y varchar(max)='abababa'

                                                                                                                                                                                                    ,@ INT=0WHILE
                                                                                                                                                                                                    replace(@y,left(@y,@),'')>''SET
                                                                                                                                                                                                    @+=1PRINT @/len(@y)^1


                                                                                                                                                                                                    Explanation: This script is repeatingly trying to replace the input '@y' with the first '@' characters of the input '@y' with nothing, while increasing '@'.




                                                                                                                                                                                                    if you replace 'ab' in 'ababab' with nothing you have an empty string




                                                                                                                                                                                                    Eventually the result will be empty. If this happens when the loop variable is equal to the length of the varchar, the criteria is false/0 because '@'=len(@y) (there was no repeating varchar).



                                                                                                                                                                                                    iif(@=len(@y),0,1)


                                                                                                                                                                                                    can be golfed into this



                                                                                                                                                                                                    @/len(@y)^1


                                                                                                                                                                                                    because the length of '@y' can not be 0 and '@' will never exceed the length @y.



                                                                                                                                                                                                    Try it online






                                                                                                                                                                                                    share|improve this answer











                                                                                                                                                                                                    $endgroup$
















                                                                                                                                                                                                      1












                                                                                                                                                                                                      1








                                                                                                                                                                                                      1





                                                                                                                                                                                                      $begingroup$

                                                                                                                                                                                                      T-SQL, 47 bytes



                                                                                                                                                                                                      Using @Xnor's method:



                                                                                                                                                                                                      DECLARE @ varchar(max)='ababab'

                                                                                                                                                                                                      PRINT sign(charindex(@,left(@+@,len(@)*2-1),2))


                                                                                                                                                                                                      Keeping old answer as it contains some nice golfing(67 bytes):



                                                                                                                                                                                                      DECLARE @y varchar(max)='abababa'

                                                                                                                                                                                                      ,@ INT=0WHILE
                                                                                                                                                                                                      replace(@y,left(@y,@),'')>''SET
                                                                                                                                                                                                      @+=1PRINT @/len(@y)^1


                                                                                                                                                                                                      Explanation: This script is repeatingly trying to replace the input '@y' with the first '@' characters of the input '@y' with nothing, while increasing '@'.




                                                                                                                                                                                                      if you replace 'ab' in 'ababab' with nothing you have an empty string




                                                                                                                                                                                                      Eventually the result will be empty. If this happens when the loop variable is equal to the length of the varchar, the criteria is false/0 because '@'=len(@y) (there was no repeating varchar).



                                                                                                                                                                                                      iif(@=len(@y),0,1)


                                                                                                                                                                                                      can be golfed into this



                                                                                                                                                                                                      @/len(@y)^1


                                                                                                                                                                                                      because the length of '@y' can not be 0 and '@' will never exceed the length @y.



                                                                                                                                                                                                      Try it online






                                                                                                                                                                                                      share|improve this answer











                                                                                                                                                                                                      $endgroup$



                                                                                                                                                                                                      T-SQL, 47 bytes



                                                                                                                                                                                                      Using @Xnor's method:



                                                                                                                                                                                                      DECLARE @ varchar(max)='ababab'

                                                                                                                                                                                                      PRINT sign(charindex(@,left(@+@,len(@)*2-1),2))


                                                                                                                                                                                                      Keeping old answer as it contains some nice golfing(67 bytes):



                                                                                                                                                                                                      DECLARE @y varchar(max)='abababa'

                                                                                                                                                                                                      ,@ INT=0WHILE
                                                                                                                                                                                                      replace(@y,left(@y,@),'')>''SET
                                                                                                                                                                                                      @+=1PRINT @/len(@y)^1


                                                                                                                                                                                                      Explanation: This script is repeatingly trying to replace the input '@y' with the first '@' characters of the input '@y' with nothing, while increasing '@'.




                                                                                                                                                                                                      if you replace 'ab' in 'ababab' with nothing you have an empty string




                                                                                                                                                                                                      Eventually the result will be empty. If this happens when the loop variable is equal to the length of the varchar, the criteria is false/0 because '@'=len(@y) (there was no repeating varchar).



                                                                                                                                                                                                      iif(@=len(@y),0,1)


                                                                                                                                                                                                      can be golfed into this



                                                                                                                                                                                                      @/len(@y)^1


                                                                                                                                                                                                      because the length of '@y' can not be 0 and '@' will never exceed the length @y.



                                                                                                                                                                                                      Try it online







                                                                                                                                                                                                      share|improve this answer














                                                                                                                                                                                                      share|improve this answer



                                                                                                                                                                                                      share|improve this answer








                                                                                                                                                                                                      edited Apr 25 at 10:47

























                                                                                                                                                                                                      answered Apr 24 at 17:04









                                                                                                                                                                                                      t-clausen.dkt-clausen.dk

                                                                                                                                                                                                      2,214514




                                                                                                                                                                                                      2,214514






















                                                                                                                                                                                                          1 2
                                                                                                                                                                                                          next

















                                                                                                                                                                                                          draft saved

                                                                                                                                                                                                          draft discarded




















































                                                                                                                                                                                                          If this is an answer to a challenge…




                                                                                                                                                                                                          • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                                                                                                          • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                                                                                                            Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                                                                                                          • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                                                                                                          More generally…




                                                                                                                                                                                                          • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                                                                                                          • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                                                                                                                                          draft saved


                                                                                                                                                                                                          draft discarded














                                                                                                                                                                                                          StackExchange.ready(
                                                                                                                                                                                                          function () {
                                                                                                                                                                                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f184682%2fcheck-if-a-string-is-entirely-made-of-the-same-substring%23new-answer', 'question_page');
                                                                                                                                                                                                          }
                                                                                                                                                                                                          );

                                                                                                                                                                                                          Post as a guest















                                                                                                                                                                                                          Required, but never shown





















































                                                                                                                                                                                                          Required, but never shown














                                                                                                                                                                                                          Required, but never shown












                                                                                                                                                                                                          Required, but never shown







                                                                                                                                                                                                          Required, but never shown

































                                                                                                                                                                                                          Required, but never shown














                                                                                                                                                                                                          Required, but never shown












                                                                                                                                                                                                          Required, but never shown







                                                                                                                                                                                                          Required, but never shown







                                                                                                                                                                                                          Popular posts from this blog

                                                                                                                                                                                                          He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

                                                                                                                                                                                                          Bunad

                                                                                                                                                                                                          Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum