[Question]
  [
The shortest code that finds all *unique* "sub-palindromes" of a string, that is: any substring with length > 1 that is a palindrome.
eg.1
```
input: "12131331"
output: "33", "121", "131", "313", "1331"
```
eg.2
```
input: "3333"
output: "33", "333", "3333"
```
  
[Answer]
## J, 24 ~~31~~ ~~40~~
```
~.(#~(1<#*]-:|.)&>),<\\.
```
Sample use:
```
   ~.(#~(1<#*]-:|.)&>),<\\. '12131331'
┌───┬───┬───┬────┬──┐
│121│131│313│1331│33│
└───┴───┴───┴────┴──┘
   ~.(#~(1<#*]-:|.)&>),<\\. '3333'
┌──┬───┬────┐
│33│333│3333│
└──┴───┴────┘
```
Take that, GolfScript!
[Answer]
## Python 124
```
r=raw_input()
l=range(len(r))
print', '.join(set('"'+r[i:j+1]+'"'for i in l for j in l if i<j and r[i:j+1]==r[i:j+1][::-1]))
```
[Answer]
## Haskell 98, 88 ~~91~~ ~~96~~
```
import List
main=interact$show.filter(\x->length x>1&&x==reverse x).nub.(tails=<<).inits
```
[Answer]
## Python - 138 136
This code does not duplicate sub-palindromes.
```
r=raw_input()
i,l=0,len(r)
j=l
a=[]
while i<l-1:
 t=r[i:j];j-=1
 if t==t[::-1]:a+=['"'+t+'"']
 if j<i+2:i+=1;j=l
print", ".join(set(a))
```
[Answer]
## Ruby - 126 102 97 characters
```
s=gets
*m=*0..s.size
puts m.product(m).map{|h,j|(c=s[h,j+1]).size>1&&c==c.reverse ? c:0}.uniq-[0]
```
[Answer]
## Golfscript, 48 characters
subpalindrome.gs
```
{,}{(;}/{{,}{);}/}%{+}*{.,1>\.-1%=*},.&{`}%", "*
```
Usage:
```
echo "12131331" | ruby golfscript.rb subpalindrome.gs
```
The first operation `{,}{(;}/` turns a string into a list of trailing-substrings. A similar leading-substrings transform is then mapped over the result. Then flatten with `{+}*`, filter for palindromes using the predicate `.,1>\.-1%=*`, grab unique values with `.&`, then pretty print.
It would be neater to extract the trailing-substrings transform as a block and reuse it as a replacement for leading-substrings after reversing each trailing substring, but I can't figure out a succinct way of doing that.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 7 bytes
```
ǎU~Ḣ'Ḃ=
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyIiLCIiLCLHjlV+4biiJ+G4gj0iLCIiLCJcIjEyMTMxMzMxXCIiXQ==)
-1 thanks to lyxal
```
 U      # Unique
ǎ       # Substrings
  ~     # Where
   Ḣ    # Length > 1
    '   # And
     Ḃ= # Is palindromic
```
[Answer]
## Haskell - 170, 153
```
import Data.List
import Data.Set
p a=fromList$[show x|x<-subsequences a,x==reverse x,length x>1]
main=getLine>>=(\x->putStrLn$intercalate", "$toList$p x)
```
[Answer]
## J, 48
```
f=:,@:".
h=:\\.
~.(#~10&<)((]h-:"0&f|.h)#[:f]h)
```
eg
```
~.(#~10&<)((]h-:"0&f|.h)#[:f]h) '12131331'
121 131 313 1331 33
```
[Answer]
## Prolog, 92
```
f(S,P):-append([_,X,_],S),X=[_,_|_],reverse(X,X),atom_codes(P,X).
p(S,R):-setof(P,f(S,P),R).
```
Sample use:
```
?- p("12131331",R).
R = ['121', '131', '1331', '313', '33'].
?- p("3333",R).
R = ['33', '333', '3333'].
```
[Answer]
### Windows PowerShell, 104 ~~109~~ ~~111~~
```
0..($l=($s="$input").length-1)|%{($a=$_)..$l|%{-join$s[$a..$_]}}|sort -u|?{$_[1]-and$_-eq-join$_[$l..0]}
```
This expects the input on stdin and will throw all found palindromes one per line on stdout:
```
PS Home:\SVN\Joey\Public\SO\CG183> '12131331'| .\subp.ps1
33
121
131
313
1331
```
(When run from `cmd` it becomes `echo 12131331|powershell -file subp.ps1` – it's just that `$input` takes a slightly different meaning depending on how the script was called, but it can be stdin, just not interactively.)
**2011-01-30 13:57** (111) – First attempt.
**2011-01-30 13:59** (109) – Inlined variable declaration.
**2011-06-02 13:18** (104) – Redone substring finding by joining a char array instead of calling `.Substring()` and inlined a bit more.
[Answer]
# Q, 78
```
{a::x;(?)(,/)b@'(&:')({x~(|:)x}'')b:-1_1_'({(sublist[;a]')x,'1+c}')c::(!)(#)a}
```
usage
```
q){a::x;(?)(,/)b@'(&:')({x~(|:)x}'')b:-1_1_'({(sublist[;a]')x,'1+c}')c::(!)(#)a}"12131331"
"121"
"131"
"313"
"1331"
"33"
q){a::x;(?)(,/)b@'(&:')({x~(|:)x}'')b:-1_1_'({(sublist[;a]')x,'1+c}')c::(!)(#)a}"3333"
"33"
"333"
"3333"
```
[Answer]
## [Retina](https://github.com/m-ender/retina), ~~34~~ 27 bytes
```
&@!`(.)+.?(?<-1>\1)+(?(1)^)
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7w31fNQTFBQ09TW89ew95G19AuxlBTW8New1AzTvN/cILKf0MjQ2NDY2NDLmMg4ALzjAxNTKEMAA "Retina – Try It Online")
The test suite needs an `M` because it is followed by another stage to insert empty lines between test cases.
### Explanation
```
&@!`(.)+.?(?<-1>\1)+(?(1)^)
```
Print (`!`) all unique (`@`), overlapping (`&`) matches of the regex `(.)+.?(?<-1>\1)+(?(1)^)`. This matches a palindrome of length 2 or more using balancing groups. There's a caveat to the "all overlapping matches" part: we can get at most one match per starting position. However, if two palindromes of different length begin at the same position, the shorter palindrome will appear again at the end of the longer palindrome. And since the greediness of `+` prioritises longer matches, we're getting all palindromes anyway.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~11~~ 10 bytes
```
ŒÙʒÂQ}žQSK
```
[Try it online!](https://tio.run/##MzBNTDJM/f//6KTDM09NOtwUWHt0X2Cw9///iUnJSYkA "05AB1E – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 9 bytes
```
ã â fÅfêU
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=4yDiIGbFZupV&input=IjEyMTMxMzMxIg)
```
ã â fÅfêU     :Implicit input of string
ã             :Substrings
  â           :Deduplicate
    f         :Filter elements that return truthy
     Å        :  Slice off first character
       f      :Filter elements that return true
        êU    :  Test for palindrome
```
[Answer]
# [Factor](https://factorcode.org/), 70 bytes
```
[ all-subseqs [ length 1 > ] filter [ dup reverse = ] filter members ]
```
[Try it online!](https://tio.run/##RcyxCsIwFIXhvU9xyG4hZlMUN3FxEafSIa23WkxivfdW9Oljtp7xO/APvtcX5@vldD5uIPSeKfUkNX2VvSyA6PWBJ3GiUFQFE5Pqb@IxKbZVZezaOuucNZVxZSY38CGsZO5KRNAgULqXhsUeLYYxKHHR2zyB6UMshN1yRIpdMbS5Gw@oBX0gz/kP "Factor – Try It Online")
Having the two filters is actually shorter than having a single filter with some kind of `and` logic, or applying a single `filter` to two quotations with `bi@`.
* `all-subseqs` Get all subsequences of the input.
* `[ length 1 > ] filter` Take those with a length greater than one.
* `[ dup reverse = ] filter` Take the palindromes.
* `members` Remove duplicates.
Using locals ties the byte count:
```
[ all-subseqs [| s | s length 1 > s s reverse = and ] filter members ]
```
[Answer]
## Perl, 112
```
$_=<>;chop;s/./$&$' /g;
map{/../&&$_ eq reverse&&$h{$_}++}split/ /
  for grep{s/./$`$& /g}split/ /;
print for keys %h
```
[Answer]
# JavaScript (ES6), 120 bytes
```
a=>{for(b=0,c=d=a.length,e=[];b<d;--c<b+2?(b++,c=d):1)(f=a.slice(b,c))==f.split``.reverse().join``&&e.push(f);return e}
```
This function takes a string as input and outputs an array.
[Answer]
## Clojure, 81 bytes
```
#(set(for[i(range 2(+(count %)1))p(partition i 1 %):when(=(reverse p)(seq p))]p))
```
`for` was a perfect match here :) Could use `:when(=(reverse p)p)` if input was a list of characters OR a full string didn't count as a palindrome, actually in that case the max range of `i` could be `(count %)` as well.
Most compact case for reference:
```
#(set(for[i(range 2(count %))p(partition i 1 %):when(=(reverse p)p)]p))
```
[Answer]
## Python, 83 102 chars
```
s=lambda t:(t[1:]or())and(t,)*(t==t[::-1])+s(t[1:])+s(t[:-1])
print set(s(input()))
```
The phrase `(t[1:]or())and...` is equivalent to `(...)if t[1:]else()` and saves one character! I'm overly proud of this, given the savings.
Example:
```
python x
"51112232211161"
set(['11', '22', '11122322111', '161', '111', '112232211', '1223221', '22322', '232'])
```
[Answer]
## Scala 127
```
object p extends App{val s=args(0);print(2.to(s.size).flatMap(s.sliding(_).toSeq.filter(c=>c==c.reverse)).toSet.mkString(" "))}
```
To keep this an apples to apples comparison with the other Scala answer, I also made mine an object that extends App. Rather than iterate the input string manually and use substring, I leveraged sliding() to create a sequence of all the substrings for me.
[Answer]
## Scala 156 170
```
object o extends App{val l=args(0).length-2;val r=for(i<-0 to l;j<-i to l;c=args(0).substring(i,j+2);if(c==c.reverse))yield c;print(r.toSet.mkString(" "))}
```
```
object o{def main(s:Array[String]){val l=s(0).length-2;val r=for(i<-0 to l;j<-i to l;c=s(0).substring(i,j+2);if(c==c.reverse)) yield c;println(r.distinct.mkString(" "))}}
```
[Answer]
# [Perl 6](https://perl6.org), ~~35~~ 32 bytes
```
{unique ~«m:ex/(.+).?<{$0.flip}>/}
```
[Test it](https://tio.run/##VVBBboMwELz7FSuEIqOAU2opByiUR/ReJbBUVghQbEdBiH6ov@jHqA00SX1Z7c7Mjnda7Kr9pCXCZc/ymJx72ORNgZBMg67Fp0b4@vk@R3jdUbb12OvL4D6xshLtmO7GydAzhVJBApQAOOFzyEPOQweSFKjDuePPw7nwuRh86Uzr@VbEzfsn4LfCLcWLCbE/fDNGMWmrQw3b2dXMpT6CbDoVHHugmahbrXzI8NpirrDwYDAGy5hZWgRBCu7czxDcuawUnTQEd10SnQw@kpGQsunWK634HWh0wp4uPM8QL4dKI72bLq42mg6V7moTjo30TxEbUMigQGyrG4dt1ise9jwc4sOqtjGtEo99CKnIOP0C "Perl 6 – Try It Online")
```
{set ~«m:ex/(.+).?<{$0.flip}>/}
```
[Test it](https://tio.run/##VVBdboMwDH7PKSyEqqBCOhapDzAYh9j71IKZUCkgEqoixC60W@xizAHWn7xY9vcXu8G23E@dQrjsRRqycw@btM4QomlQqOH79@cc4HXHxdYR72@D/SLysmjGeDdOxE00Kg0RcAZg@a@@9KX0LYhi4JaUljsP5yLnQvjSUeu4RiTpPQnkrUhDcULGzPc@KChkTXmoYDun0lx1R1B1q71jDzwpqqbTLiR4bTDVmDkwUMAyFoYWgBeDPfczBHeuyItWEcFeTYIT4SMbGcvrdt3SiD@BByfs@cJziHg5lB3ye@iSSqexW9RdW9FxzD3/FSGBhfIyxKa8cQRZKrFZV3kwe9jGhdXC3GrVOeKrUJqN0x8 "Perl 6 – Try It Online")
## Expanded:
```
{  # bare block lambda with implicit parameter ｢$_｣
  set             # turn into a Set object (ignores duplicates)
  ~«\             # stringify ｢~｣ all of these ｢«｣ (possibly in parrallel)
                  # otherwise it would be a sequence of Match objects
  m               # match
  :exhaustive     # in every way possible
  /
    ( .+ )        # at least one character ｢$0｣
    .?            # possibly another character (for odd sized sub-palindromes)
    <{ $0.flip }> # match the reverse of the first grouping
  /
}
```
[Answer]
# Perl, ~~43~~ 40 bytes
Includes `+1` for `n`
```
perl -nE 's/(?=((.)((?1)|.?)\2)(?!.*\1))/say$1/eg' <<< 12131331
```
[Answer]
# [Coconut](http://coconut-lang.org/), 69 bytes
```
def f(s)=s and{s*(s[::-1]==s>""<s[1:])}-{""}|f(s[1:])|f(s[:-1])or s{}
```
[Try it online!](https://tio.run/##HY2xDoQgEER/ZbO5Ai6nyUpHDn@EUBiVxEIwrlbItyM61czLS2aMYwznUco0e/CCpWEYwpT4K9hq3ZAzhnvEP1vSTuYmIeariu98yyPJuAOnXCxSR4qUIvwBqhp0cPWwDttHbPsSjrb18iH1ls91Ltbd "Coconut – Try It Online")
---
# [Python 2](https://docs.python.org/2/), 73 bytes
```
f=lambda s:s and{s*(s[::-1]==s>""<s[1:])}-{""}|f(s[1:])|f(s[:-1])or set()
```
[Try it online!](https://tio.run/##JYs7DoMwEAX7nGK1lR2FYnG3wrmI5cIIrCAFg1g3iHB2h89UM9J785o/U6pLifYbxrYLICwQUrfJU4ljrshbK2/ERhyx13u1Ie6/qO685BzpaQHps9IlngZDAodUkyFjCF@A5gA9PwDmZUgZjqMufw "Python 2 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
ẆQŒḂÐfḊÐf
```
[Try it online!](https://tio.run/##y0rNyan8///hrrbAo5Me7mg6PCHt4Y4uIPn/cDtQYOeM//@VDI0MjQ2NjQ2VAA "Jelly – Try It Online")
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 27 bytes
```
{∪⍵/⍨≡∘⌽¨⍨⍵}∘⊃(,/1↓⍳∘≢,/¨⊂)
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/7VHbhOpHHase9W7Vf9S74lHnwkcdMx717D20AsTr3VoL4nY1a@joGz5qm/yodzOI37lIRx@ooKtJE2iAgrqhkaGxobGxoToXkGMMBOoA "APL (Dyalog Classic) – Try It Online")
```
{∪⍵/⍨≡∘⌽¨⍨⍵}∘⊃(,/1↓⍳∘≢,/¨⊂)    Monadic train:
                           ⊂     Enclose the input, ⊂'12131331'
                     ⍳∘≢          Range from 1 to length of input
                     ⍳∘≢,/¨⊂      List of list of substrings of each length
                   1↓            Remove the first list (length-1 substrings)
               ⊃ ,/              Put the rest of the substrings into a single list.
{∪⍵/⍨≡∘⌽¨⍨⍵}                   To the result, apply this function which
                                   keeps all palindromes from a list:
      ≡∘⌽¨⍨⍵                    Boolean value of whether each (¨) string in argument
      ≡∘⌽ ⍨                     is equal to its own reverse
  ⍵/⍨                           Replicate (filter) argument by those values.
                                 This yields the length >1 palindromes.
∪                                Remove duplicates from the list of palindromes.
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
Êò2@ãX fêSÃc â
```
[Try it online!](https://ethproductions.github.io/japt/?v=1.4.6&code=yvIyQONYIGbqU8NjIOI=&input=WyIxMjEzMTMzMSIKIjMzMzMiXQotUW0=)
Explanation:
```
Êò2               #Get the range [2...length(input)]
   @      Ã       #For each number in that range:
    ãX            # Get the substrings of the input with that length
       fêS        # Keep only the palindromes
           c      #Flatten
             â    #Keep unique results
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 99 bytes
```
$args|% t*y|%{$s+=$_
0..$n|%{if($n-$_-and($t=-join$s[$_..$n])-eq-join$s[$n..$_]){$t}}
$n++}|sort -u
```
[Try it online!](https://tio.run/##TZDRasMwDEXf/RXCKMNu4rLMb4NA/6OUUFq3ywhOZ7tsJfG3p4pxyvTgK5179SDfhl/j/Jfp@xkv0MA449Fd/VRA2DymYkRfNtiy9@0WLY3dRaBV2KqjPQsMjfoeOot@j@0SOEhlfl7IEmoPcsQQI0NblnHygwug7nNkbCcYUFWC1x@1rrWueQVLnyRPmZKdRHO5LmmqzNK7yr/IQmiSMEEBY6Log@vstQI0fzdzCuZMJ9N5yXPG3/tA4I1@IieTw1Hw7HI6kL@Wufxc1ziL8xM "PowerShell – Try It Online")
Less golfed:
```
$args|% toCharArray|%{
    $substring+=$_
    0..$n|%{
        if( $n-$_ -and ($temp=-join$substring[$_..$n]) -eq -join$substring[$n..$_] ){
            $temp
        }
    }
    $n++
}|sort -Unique
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 11 bytes
```
{s.l>1∧.↔}ᵘ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFSu9qhtw6Ompoe7Omsfbp3wv7pYL8fO8FHHcr1HbVOAIjP@/49WMjQyNDY0NjZU0lEyNjZWigUA "Brachylog – Try It Online")
(The header in the link is broken at the time of posting, so [here's](https://tio.run/##SypKTM6ozMlPN/r/v7pYL8fO8FHHcr1HbVNqH26dUf7/v5KhkaGxobGxoRIA) the predicate (function-equivalent in Brachylog) on only the first test case, with a `w` at the end to actually print the output.)
```
               The output is
{        }ᵘ    a list containing every possible unique
 s.            substring of
               the input
   l           the length of which
    >          is greater than
     1         one
      ∧        and
       .       which
        ↔      reversed
               is itself. (implicit output within the inline sub-predicate)
```
I feel like there's a shorter way to check that the length is greater than 1. (If it didn't filter out trivial palindromes, it would just be `{s.↔}ᵘ`.)
]