Numbers in base 10 that are palindromic in bases 2, 4, and 16: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(add FreeBASIC) |
||
Line 390: | Line 390: | ||
0 1 3 5 15 17 51 85 255 257 273 771 819 1285 1365 3855 4095 4097 4369 12291 13107 20485 21845 |
0 1 3 5 15 17 51 85 255 257 273 771 819 1285 1365 3855 4095 4097 4369 12291 13107 20485 21845 |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>function ispal( byval n as integer, b as integer ) as boolean |
|||
'determines if n is palindromic in base b |
|||
dim as string ns |
|||
while n |
|||
ns += chr(48+n mod b) 'temporarily represent as a string |
|||
n\=b |
|||
wend |
|||
for i as integer = 1 to len(ns)\2 |
|||
if mid(ns,i,1)<>mid(ns,len(ns)-i+1,1) then return false |
|||
next i |
|||
return true |
|||
end function |
|||
for i as integer = 0 to 25000 |
|||
if ispal(i,16) andalso ispal(i,4) andalso ispal(i,2) then print i;" "; |
|||
next i</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|Go}}== |
=={{header|Go}}== |