Numbers in base 10 that are palindromic in bases 2, 4, and 16: Difference between revisions
Content added Content deleted
m (added a comma.) |
Not a robot (talk | contribs) (Add Cowgol) |
||
Line 158: | Line 158: | ||
<pre> 0 1 3 5 15 17 51 85 255 257 273 771 |
<pre> 0 1 3 5 15 17 51 85 255 257 273 771 |
||
819 1285 1365 3855 4095 4097 4369 12291 13107 20485 21845</pre> |
819 1285 1365 3855 4095 4097 4369 12291 13107 20485 21845</pre> |
||
=={{header|Cowgol}}== |
|||
<lang cowgol>include "cowgol.coh"; |
|||
const MAXIMUM := 25000; |
|||
sub reverse(n: uint16, base: uint16): (r: uint16) is |
|||
r := 0; |
|||
while n != 0 loop |
|||
r := r * base + n % base; |
|||
n := n / base; |
|||
end loop; |
|||
end sub; |
|||
var i: uint16 := 0; |
|||
var c: uint8 := 0; |
|||
while i < MAXIMUM loop |
|||
if reverse(i,2) == i |
|||
and reverse(i,4) == i |
|||
and reverse(i,16) == i |
|||
then |
|||
c := c + 1; |
|||
print_i16(i); |
|||
if c == 15 then |
|||
print_nl(); |
|||
c := 0; |
|||
else |
|||
print_char(' '); |
|||
end if; |
|||
end if; |
|||
i := i + 1; |
|||
end loop; |
|||
print_nl();</lang> |
|||
{{out}} |
|||
<pre>0 1 3 5 15 17 51 85 255 257 273 771 819 1285 1365 |
|||
3855 4095 4097 4369 12291 13107 20485 21845</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |