This challenge is a tribute to PPCG user Dennis for winning the robbers' part of The Programming Language Quiz.
Looking at Dennis' PPCG profile page we can see some pretty impressive stuff:
He currently has over sixty-eight thousand reputation, making him second in rep overall, surpassing third place by almost thirty thousand. He recently won our election for a new moderator and got a shiny new diamond next to his name. But I personally think the most interesting part about Dennis is his PPCG user ID number: 12012.
At first glance 12012
almost looks like a palindrome, a number that reads the same when reversed, but it's a little off. It can become the palindrome 21012
if we swap the positions of the first 1
and 2
, and it can become the palindrome 12021
if we swap the last 1
and 2
. Also, following the convention that leading zeroes in a number are not written, swapping the first 1
and the 0
results in 02112
or rather 2112
which is another palindrome.
Let's define a Dennis number as a positive integer that is not palindromic itself but can be made into a palindrome by swapping the positions of at least one pair of any two digits. The order of a Dennis number is the number of distinct pairs of digits that can be swapped to make a (not necessarily distinct) palindrome.
So the order of 12012
is 3 since 3 distinct pairs of its digits (12012
, 12012
, 12012
) can be swapped around to produce palindromes. 12012
happens to be the smallest order 3 Dennis number.
10
is the smallest Dennis number and has order 1 because switching around the 1
and 0
gives 01
a.k.a. 1
which is a palindrome.
The imaginary leading zeroes of a number don't count as switchable digits. For example, changing 8908
to 08908
and swapping the first two digits to get the palindrome 80908
is invalid. 8908
is not a Dennis number.
Non-Dennis numbers could be said to have order 0.
Challenge
Write a program or function that takes in a positive integer N and prints or returns the Nth smallest Dennis number along with its order in some reasonable format such as 12012 3
or (12012, 3)
.
For example, 12012
is the 774th Dennis number so if 774
is the input to your program, the output should be something like 12012 3
. (Curiously, 774 is another Dennis number.)
The shortest code in bytes wins.
Here is are the first 20 Dennis numbers and their orders for reference:
N Dennis Order
1 10 1
2 20 1
3 30 1
4 40 1
5 50 1
6 60 1
7 70 1
8 80 1
9 90 1
10 100 1
11 110 2
12 112 1
13 113 1
14 114 1
15 115 1
16 116 1
17 117 1
18 118 1
19 119 1
20 122 1