| Bytes | Lang | Time | Link |
|---|---|---|---|
| 038 | Retina | 180213T135014Z | Neil |
| 020 | J | 180213T152924Z | Galen Iv |
| 006 | Jelly | 180213T134054Z | Mr. Xcod |
| 008 | Husk | 180213T143628Z | Mr. Xcod |
| 007 | Pyth | 180213T134412Z | Mr. Xcod |
| 163 | Java 8 | 180213T143038Z | Kevin Cr |
| 058 | Python 3 | 180213T135020Z | Bijan |
| 009 | Brachylog | 180213T134920Z | Fatalize |
| 008 | 05AB1E | 180213T134855Z | Magic Oc |
Retina, 42 38 bytes
Lv`(.)*.?(?<-1>\1)*(?(1)^)
.
.
O^`
\G.
Try it online! Link includes test cases. Edit: Saved 1 4 bytes thanks to @UnrelatedString. Explanation:
Lv`(.)*.?(?<-1>\1)*(?(1)^)
For each character in the string, find the longest palindrome that starts at that point.
.
.
Change all of the characters in the palindromes to the same character, so that sorting them lexically actually sorts by length.
O^`
Sort the found palindromes in reverse order of length.
\G.
Count the length of the first (i.e. longest) palindrome.
Jelly, 6 bytes
Saved 1 byte thanks to Dennis (pointing out that Þ is stable and thus works instead of Ðf).
ẆŒḂÞṪL
How?
ẆŒḂÞṪL – Full program.
Ẇ – All contiguous non-empty subsequences.
Þ – Stable sort by...
ŒḂ – 1 if the element is palindrome, 0 otherwise.
Ṫ – Get the last element.
L – And take its length.
Note that the substrings are ordered by length, in Jelly.
Husk, 8 bytes
L►LfS=↔Q
How?
L►LfS=↔Q – Full program.
Q – All contiguous non-empty subsequences.
f – Keep those...
S= – That are equal to themselves when...
↔ – Reversed.
►L – Get the maximum element, sorted by length.
L – Take its length.
Alternative: ▲mLfS=↔Q. Note that the substrings are not ordered by length, in Husk.
Pyth, 7 bytes
le_I#.:
How?
le_I#.: – Full program.
.: – All contiguous non-empty subsequences.
# – Keep those...
_I – That are invariant under reversal.
e – Get the last element.
l – And take its length.
Note that the substrings are ordered by length, in Pyth.
Java 8, 163 bytes
s->{int r=0,l=s.length(),i=0,j,T;for(String t;i<l;i++)for(j=i;++j<=l;r=t.contains(new StringBuffer(t).reverse())&(T=t.length())>r?T:r)t=s.substring(i,j);return r;}
Explanation:
s->{ // Method with String parameter and integer return-type
int r=0, // Result-String, starting empty
l=s.length(), // The length of the input-String
i=0,j, // Index-integers
T; // Temp integer
for(String t; // Temp String
i<l;i++) // Loop `i` over the String
for(j=i;++j<=l; // Inner loop `j` over the String
r= // After every iteration, set the result to:
t.contains(new StringBuffer(t).reverse())
// If the temp-String is a palindrome,
&(T=t.length())>r?
// and the length of the substring is larger than the result
T // Set this length as the new result
: // Else:
r) // Keep the result the same
t=s.substring(i,j);
// Set the temp String to the substring from index `i` to `j`
return r;} // Return the result
Brachylog, 9 bytes
{s.↔}ᶠlᵐ⌉
Explanation
{ }ᶠ Find all…
s. …substrings of the input…
.↔ …which are their own reverse
lᵐ Map length
⌉ Max