[Question]
  [
Given an integer `N` as input, output the `N`th permutapalindromic number.
A permutapalindromic number is a strictly positive integer such that there is at least one permutation of its digits that results in a palindrome (i.e. a number that is its own reverse).
For example, `117` is a permutapalindromic number since its digits can be permuted into `171`, which is a palindrome.
We consider that numbers like `10` are not permutapalindromic numbers, even though `01 = 1` is a palindrome. We impose that the palindromic permutation must not have a leading zero (as such, `0` itself is not permutapalindromic).
Numbers that are already palindromes are also permutapalindromic, since permuting nothing is valid.
### Inputs and outputs
* `N` may be either 0-indexed or 1-indexed. Please indicate which of the two your answer uses.
* The input can be taken through `STDIN`, as a function argument, or anything similar in your language of choice. The output can be written to `STDOUT`, returned from a function, or anything similar in your language of choice.
* The input and output must be in the decimal base.
### Test cases
The following test cases are 1-indexed. Your program must be able to pass any of the test cases presented here in at most 1 minute.
```
N      Output
1      1
2      2
3      3
4      4
5      5
6      6
7      7
8      8
9      9
10     11
42     181
100    404
128    511
256    994
270    1166
```
### Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins.
  
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~15~~ ~~14~~ 13 bytes
Saved a byte thanks to **Emigna**! Code:
```
µNœvyJÂïÊP}_½
```
Explanation:
```
µ               # c = 0, when c is equal to the input, print N.
 N              # Push N, the iteration variable.
  œ             # Push all permutations of N.
   vyJ    }     # For each permutation...
      Â         #   Bifurcate, which is short for duplicate and reverse.
       ï        #   Convert the seconds one to int, removing leading zeros.
        Q       #   Check if they are not equal.
         P      #   Product of the stack.
           _    # Logical not.
            ½   # Pop a value, if 1 then increase c by 1.
```
Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=wrVOxZN2eUrDgsOvw4pQfV_CvQ&input=MTI4).
[Answer]
# Brachylog, 19 bytes
```
~l<:1at.
.=pPrPl~l?
```
[Try it online!](http://brachylog.tryitonline.net/#code=fmw8OjFhdC4KLj1wUHJQbH5sPw&input=NDI&args=Wg)
Takes about 17 seconds for `N = 270`.
### Explanation
* Main predicate:
```
~l            Create a list whose length is Input.
  <           The list is strictly increasing.
   :1a        Apply predicate 1 to each element of the list.
      t.      Output is the last element of the list.
```
* Predicate 1:
```
.=            Input = Output = an integer
  pPrP        A permutation P of the Output is its own reverse
      l~l?    The length of P is equal to the length of the Input
```
[Answer]
## Pyth, 14
```
e.ff&_ITshT.p`
```
[Try it here](http://pyth.herokuapp.com/?code=e.ff%26_ITshT.p%60&input=270&debug=0) or run a [Test Suite](http://pyth.herokuapp.com/?code=e.ff%26_ITshT.p%60&input=270&test_suite=1&test_suite_input=1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A42%0A100%0A128%0A256%0A270&debug=0)
### Expansion:
```
e.ff&_ITshT.p`ZQ   # Auto-fill variables
 .f            Q   # Find the first input number of numbers that give truthy on ...
           .p`Z    # Take all the permutations of the current number
   f&              # Keep those that give a truthy value for both:
     _IT           # Invariance on reversing (is a palindrome)
        shT        # The integer value of the first digit (doesn't start with zero)
                   # A list with any values in it it truthy, so if any permutation matches
                   # these conditions, the number was a permutapalindrome
e                  # Take only the last number
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~21~~ 20 bytes
**1 byte thanks to Fatalize.**
Did you design the challenge for Brachylog?
```
:1yt.
0<.={@epcPrP!}
```
[Try it online!](http://brachylog.tryitonline.net/#code=OjF5dC4KMDwuPXtAZXBjUHJQIX0&input=Mjcw&args=Wg&debug=on)
270 takes about half a minute here.
```
Z = 1166
real    0m27.066s
user    0m26.983s
sys     0m0.030s
Exit code:     0
```
### Predicate 0 (main predicate)
```
:1yt.
:1y    find the first Input solutions to predicate 1
   t.  unify the output with the last element
```
### Predicate 1 (auxiliary predicate)
```
0<.={@epcPrP!}
0<.              0 < Output
  .=             Assign a value to Output (choice point)
    {        }   Inline predicate:
     @e              Digits of the Output
       p             A permutation (choice point)
        c            Concatenate (fails if leading zero present)
         P           store as P
          rP         assert that P reversed is still P
            !        remove the choice point in this predicate, so
                     that it will not return twice for the same number.
```
[Answer]
## JavaScript (ES6), 99 bytes
```
f=(n,i=1)=>(n-=/^.0+$/.test(i)</^((.),\2,)*(.)(,\3)?(,(.),\6)*$/.test([...i+''].sort()))?f(n,i+1):i
```
Explanation:
```
f=(n,i=1)=>             look for n numbers starting at 1
 (n-=                   test whether current guess is
  /^.0+$/.test(i)<      not a round number and
  /^((.),\2,)*          pairs of comma-separated digits
   (.)(,\3)?            possible single digit
   (,(.),\6)*$/         pairs of comma-separated digits
   .test(               matches the comma-joined
    [...i+''].sort()))  digits in ascending order
 ?f(n,i+1)              if not n numbers found try next number
 :i                     found it!
```
[Answer]
# R, 145 bytes
```
g=function(n){d=b=0 
while(d<n){b=b+1
if(sum(a<-table(strsplit(n<-as.character(b),""))%%2)==nchar(n)%%2&(!names(a)[1]==0|a[1]|sum(!a)>1))d=d+1}
b}
```
ungolfed
```
f=function(b){
    a<-table(strsplit(n<-as.character(b),""))%%2
    sum(a)==nchar(n)%%2&(!names(a)[1]==0|a[1]|sum(!a)>1)
}
g=function(n){
    d=b=0
    while(d<n){
         b=b+a
         if(f(b)) d=d+1
    }
    b
}
```
Essentially -- a function checking membership in permutapalindromic set, and a while loop incrementing until it finds the nth member.
[Answer]
# Python 2.7, ~~163~~ 154 bytes:
```
from itertools import*;I,F,Q=input(),[],2
while len(F)<I:F=[g for g in range(1,Q)if any(i==i[::-1]*(i[0]>'0')for i in permutations(`g`))];Q+=1
print F[-1]
```
Simple enough. Basically uses a `while` loop to repeatedly create arrays containing permutapalindromic numbers the the range `[1,Q)` until `Q` is large enough such that the array contains `Input` number of items. It then outputs the last element in that array. 
[Try It Online! (Ideone)](http://ideone.com/wOkRhR)
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), 51 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
One-indexed.
```
{⍵⊃{⍵/⍨{(⍵≤9)∨(1<≢c~'0')∧1≥+/2|+⌿c∘.=∪c←⍕⍵}¨⍵}⍳5×⍵}
```
> 
> `{` a function where ⍵ represents the argument
> 
> 
> 
> > 
> > `⍵⊃{` use the argument to pick from the result of the function
> > 
> > 
> > 
> > > 
> > > `⍵/⍨{` filter the argument with the result of the function
> > > 
> > > 
> > > 
> > > > 
> > > > `(⍵≤9)∨` the argument is less or equal to 9, OR
> > > > 
> > > > 
> > > > `(1<≢c~'0')∧` there remains more than one digit when zeros are removed AND
> > > > 
> > > > 
> > > > `1≥+/` 0 or 1 is the sum of
> > > > 
> > > > 
> > > > `2|` the oddnesses of
> > > > 
> > > > 
> > > > `+⌿` of the column sums of
> > > > 
> > > > 
> > > > `c∘.=∪c` the comparison table of *c* and the unique elements of *c*, where *c*...
> > > > 
> > > > 
> > > > `←⍕⍵` is the string representation of the argument
> > > > 
> > > > 
> > > > 
> > > 
> > > 
> > > `}¨⍵` applied to each of the arguments
> > > 
> > > 
> > > 
> > 
> > 
> > `}⍳5×⍵` applied to {1, 2, 3, ..., 5 times the argument}
> > 
> > 
> > 
> 
> 
> `}` [end of function]
> 
> 
> 
Finishes all the test cases instantly on [TryAPL](http://tryapl.org/?a=%7B%u2375%u2283%7B%u2375/%u2368%7B%28%u2375%u22649%29%u2228%281%3C%u2262c%7E%270%27%29%u22271%u2265+/2%7C+%u233Fc%u2218.%3D%u222Ac%u2190%u2355%u2375%7D%A8%u2375%7D%u23735%D7%u2375%7D%A81%202%203%204%205%206%207%208%209%2010%2042%20100%20128%20256%20270&run)
[Answer]
# JavaScript (ES6), 92
```
n=>eval("for(a=0;n-=(a++<9||(b=[...a+``].sort().join``)>9&!b.replace(/(.)\\1/g,``)[1]););a")
```
*Less golfed*
```
n=>{
  for( a = 0;
       n -= // decrement n (and exit when 0) if the check below is true == a is permutapalindromic
            (a ++ < 9 // single digit (meanwhile, increment a)
             || // or...
             ( b=[...a+``].sort().join`` )// build a string with the digits sorted
               > 9 // required at least 2 non zero digits
             & ! b.replace(/(.)\1/g,``)[1] // removed all digits pair, there must be just 1 or no single digits remaining
            );
     );
   return a;
}
```
**Test**
```
f=n=>eval("for(a=0;n-=(a++<9||(b=[...a+``].sort().join``)>9&!b.replace(/(.)\\1/g,``)[1]););a")
function update() {
  O.textContent=f(+I.value)
}
update()
```
```
<input id=I oninput=update() type=number value=100>
<pre id=O></pre>
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 13 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
_ì á fÎdêQ}iU
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=X%2bwg4SBmzmTqUX1pVQ&input=WwowCjEKMgozCjQKNQo2CjcKOAo5CjQxCjk5CjEyNwoyNTUKMjY5Cl0tbVI)
0-indexed
```
_ì á fÎdêQ}iU
_         }iU # Find the N-th number that meets this condition:
 ì            #  Get the digits as an array
   á          #  Get all permutations of that array
     f        #  Keep only permutations where:
      Î       #   The first digit is not zero
       d      #  Return true if any remaining permutation:
        êQ    #   Is a palindrome
```
[Answer]
# [Perl 6](http://perl6.org), 66 bytes
```
{(1..*).grep(*.comb.permutations.grep({+.join.flip eq.join}))[$_]}
```
0 based
## Explanation:
```
# bare block lambda which takes an implicit parameter ｢$_｣
{
  # all numbers greater than 0
  (1..*)\
  # remove any which aren't permutapalindromic
  .grep(
    # ｢*｣ here starts a Whatever lambda
    *\
    # split into list of digits
    .comb\
    # get all of the permutations of the digits
    .permutations\
    # find out if there are any palindromes
    .grep(
      # another bare block lambda taking ｢$_｣ as implicit parameter
      {
        # compare the current permutation with its reverse stringwise
        # numify only one side to get rid of leading ｢0｣
        +$_.join.flip eq $_.join
      }
    )
  # get the value at the index
  )[$_]
}
```
## Test:
```
#! /usr/bin/env perl6
use v6.c;
use Test;
my &permutapalindromic = {(1..*).grep(*.comb.permutations.grep({+.join.flip eq.join}))[$_]}
my @tests = (
  1   => 1,
  2   => 2,
  3   => 3,
  4   => 4,
  5   => 5,
  6   => 6,
  7   => 7,
  8   => 8,
  9   => 9,
  10  => 11,
  42  => 181,
  100 => 404,
  128 => 511,
  256 => 994,
  270 => 1166,
);
plan +@tests + 1;
my $start-time = now;
for @tests -> $_ ( :key($input), :value($expected) ) {
  # zero based instead of one based, so subtract 1
  is-deeply permutapalindromic( $input - 1 ), $expected, .gist;
}
my $finish-time = now;
my $total-time = $finish-time - $start-time;
cmp-ok $total-time, &[<], 60, 'Less than 60 seconds for the tests';
diag "$total-time seconds";
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog) v2, 16 bytes
```
<~l<₁{≜.pX↔Xp}ᵐt
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3w36Yux@ZRU2P1o845egURj9qmRBSAxEv@/4821DHSMdYx0THVMdMx17HQsdQxNNAxMQKSBjqGRhY6RqZmOkbmBrEA "Brachylog – Try It Online")
Borrows Fatalize's `~l` trick because my attempt at a `ᵘ`-based solution is a bit too slow...
```
<                   The input is less than
 ~l                 the length of some list
   <₁               which is strictly increasing
     {       }ᵐ     where each element:
      ≜.            is an integer chosen such that
        pX          some permutation X
          ↔X        is X reversed,
            p       a permutation of which is the element.
               t    Output the final element of that list.
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), ~~10~~ 9 bytes
```
SṖ'Ṙ⌊=)ȯt
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJBQiIsIiIsIlPhuZYn4bmY4oyKPSnIr3QiLCIiLCIxICBcbjIgIFxuMyAgXG40ICBcbjUgIFxuNiAgXG43ICBcbjggIFxuOSAgXG4xMCBcbjQyIFxuMTAwXG4xMjhcbjI1NlxuMjcwIl0=)
You say any test case presented in the challenge should pass in under a minute? *All* test cases presented in the challenge pass in under 30 seconds. That's what I call gaming (no doubt the other answers do too though lol).
## Explained
```
SṖ'Ṙ⌊=)ȯt
      )ȯ  # Starting at 1, get the first (input)th numbers where:
SṖ        #   From the permutation of the digits of the number,
  '       #   There exists at least 1 such that:
   Ṙ⌊     #   The reverse (cast to int)
     =    #   Equals that permutation
        t # Print the tail of the list
```
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 15 bytes
```
:vdṙ=
ṙf↑¦Σ
↑#)
```
[Try it online!](https://tio.run/##S0/MTPz/36os5eHOmbZcQCLtUdvEQ8vOLeYC0sqa//@bGAEA "Gaia – Try It Online")
First ever code golf, so please tell me if I'm doing anything wrong.
## Explained
```
:vdṙ= # Helper function 2 (hf2)
:     # Push two copies of the function argument
 vdṙ  # str(int(argument[::-1]))
    = # does that equal the original function argument?
-----
ṙf↑¦Σ # Helper function 1 (hf1)
ṙf    # Get all permutations of the string representation of the function argument
  ↑¦  # Map hf2 to each item
    Σ # and summate the result
-----
↑#)   # Main function
↑#    # First (input) items where hf1 is true
  )   # get the last item of that
```
[Answer]
# Javascript (using external library - Enumerable) (142 bytes)
```
   n=>_.Sequence(n,i=>{l=i+"";p=_.Permutations(_.From(l),l.length).Any(y=>y.First()!="0"&&y.SequenceEqual(y.Reverse()));if(p){return i;}}).Last()
```
Link to lib:<https://github.com/mvegh1/Enumerable/>
Code explanation: \_.Sequence creates an enumerable for a count of "n" elements, based on the predicate of signature ("i"teration~~,"a"ccumulated array~~). Cast the current iteration to a string, and create an enumerable of all permutations from it. Test if any of the permutations satisfy the test of not starting with "0" and that the reversal of the permutation equals the permutation. Return the last element in the sequence because that is the desired output as per OP
[![enter image description here](https://i.stack.imgur.com/qs3nr.png)](https://i.stack.imgur.com/qs3nr.png)
[Answer]
## Python 2, 93 bytes
```
S=sorted
f=lambda n,i=1:n and-~f(n-(S(`i`)in[S(`k`)for k in range(9*i)if`k`==`k`[::-1]]),i+1)
```
1-indexed. Depending on your system, the last test case may exceed the allowed recursion depth.
Does not compute permutations. Instead, uses the fact that two strings are permutations if they are equal when sorted. To test if a number is permutapalindromic, checks if its sorted digits equal the sorted digits of any palindrome up to a bound.
---
**96 bytes:**
```
f=lambda n,i=1:n and-~f(n-(sum(`i`.count(`d`)%2for d in range(10))<2*(set(`i`[1:])!={'0'})),i+1)
```
1-indexed. Depending on your system, the last test case may exceed the allowed recursion depth.
This doesn't look at permutations and instead uses the following characterization:
> 
> A number is *permutapalindromic* exactly when
> 
> 
> * At most one of its digits appears an odd number of times, and
> * It does not have the form d00...00 with one or more zeroes.
> 
> 
> 
This is true because a palindrome must pair off digits from the start and end, except for a possible center digit. The exception comes from the requirement that the leading digit be nonzero, and so some nonzero digit must appear twice unless the number is single-digit.
[Answer]
# Haskell, ~~89~~ 87 bytes
```
import Data.List
(filter(any(show.floor.read.reverse>>=(==)).permutations.show)[0..]!!)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
1DŒ!ŒḂ×ḢƊ€ẸƲ#Ṫ
```
[Try it online!](https://tio.run/##ASoA1f9qZWxsef//MUTFkiHFkuG4gsOX4biixorigqzhurjGsiPhuar///8yNzA "Jelly – Try It Online")
## How it works
```
1DŒ!ŒḂ×ḢƊ€ẸƲ#Ṫ - Main link. Takes an argument n on the left
           Ʋ   - Group the previous 4 links into a monad f(k):
 D             -   Convert k to digits
  Œ!           -   Permutations of k's digits
        Ɗ€     -   Over each permutation p:
    ŒḂ         -     Is p a palindrome?
      ×Ḣ       -     And is the first digit non-zero?
          Ẹ    -   Is that true for any permutation?
1           #  - Count up k = 1, 2, 3, ... until n k return true under f(k)
                 Return those k
             Ṫ - Return the n'th k
```
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 69 bytes
```
1while$_-=(join'',sort++$\=~/./g)=~s/(.)\1//gr=~y///c<2*$\!~/^.0+$/}{
```
[Try it online!](https://tio.run/##BcHdCkAwGAbga1ErP2MvSk7sThYHEpNsbStJduk@z2MXd3REzbXpY2FTJbPd6DNNS29c4JwpGSGw5jJ6ZCJXDbA6GW8A89AWTCURo6g5w/sQtX39GRu0OT1V9gc "Perl 5 – Try It Online")
[Answer]
# [Python](https://python.org) + [`golfing-shortcuts`](https://github.com/nayakrujul/golfing-shortcuts), 128 bytes
A port of [R. Kap's answer](https://codegolf.stackexchange.com/a/90122/114446).
```
from s import*
I,F,Q=e(i()),[],2
while l(F)<I:F=[G for G in r(1,Q)if a(I==I[::-1]*(I[0]>'0')for I in Im(repr(G)))];Q+=1
p(F[-1])
```
[Answer]
**C, 254 bytes**
```
#define W while
#define R return
f(j){int c=0,a[16]={0};do++a[j%10],++c;W(j/=10);if(c>1&&a[0]>=c-1)R 0;c%=2;W(j<10)if(a[j++]%2&&(!c||++c>2))R 0;R 1;}g(n){int k=0,i=1;W(k<n)if(f(i++))++k;R i-1;}main(a){printf("N>");scanf("%d",&a);printf("%d\n",g(a));}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
```
Dœ^/LỊaṢ-ịø#Ṫ
```
[Try it online!](https://tio.run/##ASQA2/9qZWxsef//RMWTXi9M4buKYeG5oi3hu4vDuCPhuar///8yNzA "Jelly – Try It Online")
Out of curiosity, I decided to see how far I could get without actually computing permutations, and two hours of head bashing later it ties caird's existing answer (modulo a golf to use `ø`). The logic boils down to checking two conditions:
* At most one digit occurs an odd number of times.
* There must be multiple nonzero digits if at least one digit is zero.
and stuck in a blender for five minutes on high, that's:
```
           #     Count up collecting the first n integers
          ø      starting from 0 which satisfy:
D                Do the digits
 œ^/             reduced by symmetric multiset difference
    LỊ           have length ≤ 1?
       Ṣ         Sort the digits,
      a          replace them all with 0 if the previous condition is not met,
        -ị       and take the second to last element (wrapping around if length 1),
           #     succeeding if it's nonzero.
            Ṫ    Return the last result.
```
]