Skip to main content
Golfed 1 byte
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Brachylog, 1616 15 bytes

~c~c₃↺{~jʰ|↺~jʰ↻h&~j}c↰|ʰ↻c↰|

Try it online! (Times out if the output is longer than 7 characters.)Try it online!

Explanation

I wouldn't be surprised if there's a better way to do this.

~c~c₃↺{~jʰ|↺~jʰ↻h&~j}c↰|ʰ↻c↰|
~c  ~c₃               "Unconcatenate" the input string into some list ofthree substrings
  {          }     ApplyRotate thisthe predicatefirst element to the list:end
    {           Apply this predicate to the EITHERnew first element:
     ʰ h&             Assert Takethat theit firstis elementnonempty
   ~j     ~j           Assert that it consists of a substring repeated twice,
                     and return that substring
      |             OR:
                    Rotate the firstfinal element back to the endbeginning
        ~jʰ     c    Concatenate the Samelist asback abovetogether
                  RotateCall the finalmain elementpredicate backagain toon the beginningresult
                 |  If that predicate succeeded:
              cthere was no way to Concatenatepartition the listinput backstring togetherthat
               ↰    Call the main predicate again onsatisfied the result
                |  Otherwiseassertions, return the input unchanged

Brachylog, 16 bytes

~c{~jʰ|↺~jʰ↻}c↰|

Try it online! (Times out if the output is longer than 7 characters.)

Explanation

I wouldn't be surprised if there's a better way to do this.

~c{~jʰ|↺~jʰ↻}c↰|
~c                 "Unconcatenate" the input string into some list of substrings
  {          }     Apply this predicate to the list:
                    EITHER:
     ʰ               Take the first element
   ~j                Assert that it consists of a substring repeated twice,
                     and return that substring
      |             OR:
                    Rotate the first element to the end
        ~jʰ           Same as above
                  Rotate the final element back to the beginning
                   If that predicate succeeded:
              c     Concatenate the list back together
               ↰    Call the main predicate again on the result
                |  Otherwise, return the input unchanged

Brachylog, 16 15 bytes

~c₃↺{h&~j}ʰ↻c↰|

Try it online!

Explanation

I wouldn't be surprised if there's a better way to do this.

~c₃↺{h&~j}ʰ↻c↰|
~c₃               "Unconcatenate" the input string into three substrings
                 Rotate the first element to the end
    {           Apply this predicate to the new first element:
     h&             Assert that it is nonempty
       ~j           Assert that it consists of a substring repeated twice,
                    and return that substring
                 Rotate the final element back to the beginning
             c    Concatenate the list back together
                 Call the main predicate again on the result
               |  If there was no way to partition the input string that
                  satisfied the assertions, return the input unchanged
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Brachylog, 16 bytes

~c{~jʰ|↺~jʰ↻}c↰|

Try it online! (Times out if the output is longer than 7 characters.)

Explanation

I wouldn't be surprised if there's a better way to do this.

~c{~jʰ|↺~jʰ↻}c↰|
~c                 "Unconcatenate" the input string into some list of substrings
  {          }     Apply this predicate to the list:
                    EITHER:
     ʰ               Take the first element
   ~j                Assert that it consists of a substring repeated twice,
                     and return that substring
      |             OR:
       ↺             Rotate the first element to the end
        ~jʰ           Same as above
           ↻         Rotate the final element back to the beginning
                   If that predicate succeeded:
              c     Concatenate the list back together
               ↰    Call the main predicate again on the result
                |  Otherwise, return the input unchanged