| Bytes | Lang | Time | Link |
|---|---|---|---|
| 042 | Python 3 with regex | 240124T141622Z | movatica |
| 023 | R | 240602T184518Z | int 21h |
| 032 | Scala 3 | 240126T125559Z | 138 Aspe |
| 057 | Zsh | 240126T093858Z | pxeger |
| 021 | JavaScript ES6 | 240121T154239Z | Arnauld |
| 009 | 05AB1E | 240124T091914Z | Kevin Cr |
| 067 | C gcc | 240122T034656Z | l4m2 |
| 090 | Python 3.8 | 240123T102646Z | SevC_10 |
| 005 | Brachylog | 240122T232230Z | DLosc |
| 019 | Curry PAKCS | 240121T211626Z | Kirill L |
| 013 | Perl 5 p | 240122T070326Z | Xcali |
| 039 | APL+WIN | 240122T144303Z | Graham |
| 042 | BQN CBQN | 240122T084555Z | Razetime |
| 004 | Nekomata + e | 240122T014133Z | alephalp |
| 006 | Vyxal 3 | 240122T010221Z | lyxal |
| 016 | Charcoal | 240121T195419Z | Neil |
| 008 | Retina | 240121T193309Z | Fmbalbue |
| 013 | Haskell + hgl | 240121T191330Z | Wheat Wi |
| 045 | Uiua | 240121T180339Z | Joao-3 |
| 007 | Jelly | 240121T160324Z | Jonathan |
Python 3 with regex, 43 42 bytes
import re
f=re.compile(r'.+(.+)\1$').match
Python3 port of the Javascript answer.
Takes a string for input, returns a re.Match object as truthy, None as falsy.
Python 3 recursive, 53 bytes
by Jitse
f=lambda s,i=0:s>''and(s==i*s[:len(s)//2])|f(s[1:],2)
Python 3 iterative, 65 59 57 bytes
lambda s:any(s.endswith(2*s[i:],1)for i in range(len(s)))
Takes a string for input, returns True and False accordingly.
R, 24 23 bytes
- -1 byte thanks to pajonk
\(x)grep('.+(.+)\\1',x)
Attempt This Online!
Not a very special solution (regex taken here), but almost surely it's going to be the shortest one in R (well, until pajonk suggested to replace grepl with grep :).
JavaScript (ES6), 21 bytes
Takes a string and returns a Boolean value.
s=>/.(.+)\1$/.test(s)
JavaScript (ES6), 59 bytes
A non-regex solution.
s=>(g=i=>s[2*i]&&s.slice(-2*i)==(q=s.slice(-i))+q|g(-~i))``
05AB1E, 9 bytes
Three different alternatives:
.œ3ùε¦Ë}à- Try it online or verify all test cases..s¨ε2äË}à- Try it online or verify all test cases.¦D.s2×Å¿à- Try it online or verify all test cases.
Explanation:
.œ # Get all partitions of the (implicit) input-string
3ù # Only keep the partitions containing three parts
ε # Map over each over each remaining partition:
¦ # Remove the first part
Ë # Check if the remaining two parts are equal
}à # After the map: check if any is truthy
# (which is output implicitly as result)
.s # Get all suffixes of the (implicit) input-string
¨ # Remove the last suffix (the input itself)
ε # Map over each suffix:
2ä # Split it into two equal-sized parts (first part is larger for odd lengths)
Ë # Check that both parts are equal
}à # After the map: check if any is truthy
# (which is output implicitly as result)
¦ # Remove the first character of the (implicit) input-string
D # Duplicate it
.s # Pop the copy, and push its prefixes
2× # Double each string
Å¿ # Check if the input minus first character ends with a string
à # Check if any is truthy
# (which is output implicitly as result)
C (gcc), 67 bytes
n;f(char*s){n=strlen(++s);return~-n&&!bcmp(s-~n/2,s+n%2,n/2)|f(s);}
-1 byte from ceilingcat
Python 3.8, 90 bytes
The function takes as input a string s. It returns 0 for True cases, None for False ones.
def f(s):
l=len(s)
for i in range(1,l):
x=(i+l)//2
if s[i:x]==s[x:]:return 0
return
Explanation
The function takes as input a string s.
The i loop takes substrings of s representing b+b, starting from the second character in order to leave a non-empty substring a.
x represents the middle of the substring.
The two halves of the substring are compared: if they are equal, return 0. If no equal halves are found, return None.
Brachylog, 7 5 bytes
-2 bytes thanks to Unrelated String
ba₁ḍ=
Explanation
b Remove the first character from the input
a₁ Get a nonempty suffix of the remaining string
ḍ Split it into two halves
= Assert that both are identical
The first b is necessary to prevent the prefix from being empty.
Curry (PAKCS), 20 19 bytes
f(_:_++b++b)|b>""=1
Try it online! with truthy, or
Try it online! with falsy test case.
Thanks for a byte saved by Wheat Wizard.
APL+WIN, 39 bytes
Prompts for string.
×+/n=+/¨(n↑¨⊂v)=n↑¨(n←⍳⌊.5×⍴v)↓¨⊂v←⌽1↓⎕
Nekomata + -e, 4 bytes
Jtđ=
Jtđ=
J Split the input into a list of parts
t Remove the first part
đ Check that there are exactly two remaining parts
= Check that the two remaining parts are equal
Vyxal 3, 6 bytes
Ḣᶜϩ½≈a
Essentially, a case is truthy if some suffix of the input minus the first character (ensuring a is non empty) can be split into two equal halves.
Explained
Ḣᶜϩ½≈a
Ḣ # Remove the first character of the string because it could be `a`
ᶜϩ # Over all suffixes:
½ # Split into halves
≈ # And test whether both halves are the same
a # Output whether any are true.
💎
Created with the help of Luminespire.
Charcoal, 16 bytes
⊙ΦEθ…⮌θκι⁼ιײ∕ι²
Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - for a+b+b, nothing if not. Explanation:
θ Input string
E Map over characters
θ Input string
⮌ Reversed
… Truncated to length
κ Current index
Φ Filtered where
ι Reversed suffix (is not empty)
⊙ Any reversed suffix satisfies
ι Current reversed suffix
∕ ² First half
ײ Repeated twice
⁼ Equals
ι Current reversed suffix
Implicitly print
Haskell + hgl, 13 bytes
cP$h_*>h_>~ʃ
Explanation
This uses the parser library.
h_ parses any non-empty string, so we ask if there is a h_ followed by h_ and then we feed the output of the second h_ into ʃ. Since ʃ parses any fixed string given as input, this means it parses whatever h_ gave again.
cP takes the parser we built and turns it into a function which returns true when there is at least one parse which completely consumes the string.
Reflection
This is such a simple challenge it's hard for this to get any better, but I have some thoughts:
(>~ʃ)is a pretty common function. It attempts to parse the result of the last parse again. However unless I assigned it a 2 byte name it wouldn't make any savings in this particular case.(h_*>)might also be useful to have a shortcut for.
Jelly, 7 bytes
ŒHÐƤḊEƇ
A monadic Link that accepts a list of characters and yields a non-empty list (truthy) if the input can be expressed as a+b+b or an empty list (falsey) otherwise.
How?
ŒHÐƤḊEƇ - Link: list of characters, S
ÐƤ - for suffixes of S:
ŒH - split into half (if odd length first half is longer)
Ḋ - dequeue (we don't want to test for a+a, only a+b+b)
Ƈ - keep those for which:
E - all equal?