8
Given a number n
, calculate the amount of bases in the range of [2, n)
in which b(n)
is a Palindrome.
Example
n = 8
has the base conversions:
2 = 1000
3 = 22
4 = 20
5 = 13
6 = 12
7 = 11
Of which 2 of them, 3 = 22
and 7 = 11
are palindromes. So return 2
.
Clarifications
- For the sake of convenience, Your answer only needs to be correct for inputs 3 - 36 inclusive, as few languages can handle base conversion of >36.
- A single digit number is considered a palindrome.
- This is sequence A135551 on OEIS
Test Cases
3 -> 1
4 -> 1
5 -> 2
6 -> 1
7 -> 2
8 -> 2
9 -> 2
10 -> 3
11 -> 1
12 -> 2
13 -> 2
14 -> 2
15 -> 3
16 -> 3
17 -> 3
18 -> 3
19 -> 1
20 -> 3
21 -> 4
22 -> 2
23 -> 2
24 -> 4
25 -> 2
26 -> 4
27 -> 3
28 -> 4
29 -> 2
30 -> 3
31 -> 3
32 -> 3
33 -> 3
34 -> 3
35 -> 2
36 -> 5
Finally
- Standard Loopholes Apply.
- This is code-golf, so fewest bytes wins.
- Have Fun!
Did you mean to write "[2, n)", if so, what does the difference in braces mean? – Stan Strum – 2017-08-31T05:03:40.507
@StanStrum Set notion as described in ISO_31-11, Means 2 (inclusive) through n (exclusive)
– ATaco – 2017-08-31T05:12:48.847I think this might be a dupe of All your base palindromic belong to us?
– Dom Hastings – 2017-08-31T05:38:47.207"A single digit number is considered a palindrome." But this won't happen anyway. – G B – 2017-08-31T05:50:34.777
@ATaco ah, thanks – Stan Strum – 2017-08-31T05:57:52.117
@DomHastings I do not think so, as the sequences A126071 and A135551 differ.
– Jonathan Frech – 2017-08-31T06:27:25.0531@JonathanFrech actually I think Dom is right - once the sequences are aligned (one starts at index 0 the other at index 1), A126071(n) = A135551(n) + 1. This is evident from the facts that (a) n in Unary is 00...0 [palindromic]; (b) for n>1, n in base n is 10 [not palindromic]; and (c) n in base n+1 is 11 (or 1 for n=1) [palindromic]. Also it even states in the formula section of A135551 "a(n) = A126071(n) - 1". – Jonathan Allan – 2017-08-31T07:11:06.187
@JonathanAllan Although the sequences are similar, the challenges themselves do also differ in that one requests the other sequence up to n, where as this only requests n. Answers are completely non-transferable between the two. – ATaco – 2017-08-31T07:17:15.603
While it is true the other asks for up to n, that does not make them non-transferable. The second line of the Jelly submission there, for example, is just calling "link 1" for each number in turn (the only reason it's so much longer than my submission here is that the language has evolved). – Jonathan Allan – 2017-08-31T07:23:08.637
@OlivierGrégoire it's a palindrome in n-1 :P – ATaco – 2017-08-31T07:31:24.030
1
FYI: My latest submission in Pyth shows the ease of porting.
– Jonathan Allan – 2017-08-31T07:39:28.1834I have voted to reopen this question, because in my honest opinion the challenges (and tasks) are different enough, and porting the answers there might not be the best option (in some languages, at least). – Mr. Xcoder – 2017-08-31T08:56:05.130
2@Mr.Xcoder, if wrapping something in a loop from 1 to n is not sufficiently trivial a change to be a dupe, what is sufficiently trivial? – Peter Taylor – 2017-08-31T11:38:08.943
@PeterTaylor Here are the reasons I think it is not a duplicate. Feel free to disagree, but that won't change my opinion.
– Mr. Xcoder – 2017-08-31T11:39:53.1305
@Mr.Xcoder, the number of answers an earlier challenge received is nothing to do with whether it's a dupe or not; "the challenge there is quite old (and many languages have evolved since then, other languages were designed in the mean time" is an argument for keeping it open in spite of being a dupe which was also made in this case to which see also this. If you think an obvious dupe should be reopened in spite of being an obvious dupe, take it to meta first.
– Peter Taylor – 2017-08-31T11:47:38.2431@PeterTaylor Feel free to hammer it again, I don't really have a strong opinion right now. You are probably right. – Mr. Xcoder – 2017-08-31T11:49:38.473