Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Number of numeric palindromes in different bases
%% Number of numeric palindromes in different bases
N = zeros(4096,36);
for i=2:size(N,1)
N(i,:) = N(i-1,:);
for b=2:size(N,2)
s = dec2base(i,b);
if all(s == fliplr(s))
N(i,b) = N(i,b) + 1;
end
end
end
loglog(N(:,2:36))
legend(arrayfun(@num2str, 2:36, 'UniformOutput', false), 'Location', 'best');
print('-dpng','palindromes.png')
disp('N = 2015')
[2:36;N(2015,2:end)]'
N = 2015
2 92
3 99
4 92
5 103
6 89
7 87
8 92
9 103
10 118
11 135
12 155
13 165
14 155
15 146
16 139
17 133
18 127
19 122
20 118
21 114
22 111
23 108
24 105
25 103
26 101
27 99
28 97
29 96
30 95
31 93
32 92
33 92
34 91
35 90
36 89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.