18
3
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 toSTDOUT
, 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, so the shortest answer in bytes wins.
It's quite impossible to not pass the last testcase in one minute... – Leaky Nun – 2016-08-17T07:41:59.900
OEIS A084050 (contains extra cases like
10
) – Leaky Nun – 2016-08-17T07:44:22.307What is the largest input? – Adám – 2016-08-17T09:01:12.593
@Adám Your program should theoretically work for any number, no matter how big. – Fatalize – 2016-08-17T09:03:22.770
Wouldn't it be enough to support numbers that by default are represented in non-exponent form? – Adám – 2016-08-17T09:05:37.327
1@Adám This is a pretty arbitrary limit that is dependant on the language used. Let's say that it should theoretically work for the biggest integer your language can represent by default (so all integers if bignums is the default in your language). – Fatalize – 2016-08-17T09:11:10.153