5
For the purpose of this challenge, a smaller-base palindrome (SBP) is a number which is palindromic in a base between 1 and itself (exclusive), and is not a repdigit in the same base. For example, 5 is a SBP because it is a palindrome in base 2 (101). The first few SBPs are 5,9,10,16,17,20,21,23,25,26,27,28,29,33...
Your Task:
Write a program or function that, when given an integer i
as input, returns/outputs the i
th SBP.
Input:
An integer i
where 0 <= i < 1,000,000
.
Output:
The i
th SBP.
Test Cases:
12 -> 29
18 -> 41
Scoring:
This is code-golf, lowest score in bytes wins!
Sandbox – Gryphon – 2017-10-09T14:00:34.410
2It's not in the OEIS? Weird... – NieDzejkob – 2017-10-09T14:14:28.463
@Rod 6 is a repdigit – NieDzejkob – 2017-10-09T14:14:46.673
@NieDzejkob thanks, I overlooked that part – Rod – 2017-10-09T14:15:32.760
Surprisingly, this is actually (relatively) difficult in some golfing langs. (relatively meaning ~15 bytes instead of ~3) – Gryphon – 2017-10-09T14:54:18.477
@Emigna, thank-you, fixed. I did these by hand, so I apparently missed that one. – Gryphon – 2017-10-09T14:55:32.870
@NieDzejkob, I agree it is weird that it isn't in the OEIS, but unless I was wrong about something between 5 and 26, it isn't. – Gryphon – 2017-10-09T14:56:38.630
@Gryphon you should submit it – NieDzejkob – 2017-10-09T15:36:55.083
2What is a "repdigit"? I assume it's a single digit repeated? This is never clarified or defined. – mbomb007 – 2017-10-09T16:05:17.580
1Also, what is the result for
i = 999,999
? – mbomb007 – 2017-10-09T16:12:04.787as your examples are 0-indexed, shoudn't your
i
be in range0<=i
? – Felipe Nardi Batista – 2017-10-09T19:53:02.813From one of gryphon's closed challenges, [https://codegolf.stackexchange.com/questions/125947/am-a-i-square-repdigit?rq=1 ], A repdigit is an integer that contains only one digit (e.g. 2, 44, 9999) which explains why 3 isn't an SBP since 11 is a palidronme but all the digits are the same – Foon – 2017-10-09T21:00:24.057
Every number is a repdigit in some base. Do you mean to exclude only base 10 repdigits? – aschepler – 2017-10-10T00:41:18.520
1How is 33 not a repdigit? It's given as an example of a SBP. For that matter how is 5 not? – Noodle9 – 2017-10-10T08:00:46.683
1Ah, sorry. Ignore that previous comment, I thought it was about another challenge. I'll delete it now. What I meant on this challenge was that only palindromes in smaller bases that are not repdigits count. – Gryphon – 2017-10-10T10:26:25.453
So 5 is a SBP because it is a palindrome, but not a repdigit, in base 2. – Gryphon – 2017-10-10T10:29:22.497