Find palindromic numbers in both binary and ternary bases: Difference between revisions
Find palindromic numbers in both binary and ternary bases (view source)
Revision as of 02:40, 29 November 2019
, 4 years agoAdded 11l
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 18:
* [[oeis:A060792|Sequence A60792]], numbers that are palindromic in bases 2 and 3 on ''The On-Line Encyclopedia of Integer Sequences''.
<br><br>
=={{header|11l}}==
{{trans|Python}}
<lang 11l>V digits = ‘0123456789abcdefghijklmnopqrstuvwxyz’
F baseN(=num, b)
I num == 0
R ‘0’
V result = ‘’
L num != 0
(num, V d) = divmod(num, b)
result ‘’= :digits[Int(d)]
R reversed(result)
F pal2(num)
I num == 0 | num == 1
R 1B
V based = bin(num)
R based == reversed(based)
F pal_23(limit)
V r = [Int64(0), 1]
V n = 1
L
n++
V b = baseN(n, 3)
V revb = reversed(b)
L(trial) (b‘’revb, b‘0’revb, b‘1’revb, b‘2’revb)
V t = Int64(trial, 3)
I pal2(t)
r.append(t)
I r.len == limit
R r
L(pal23) pal_23(6)
print(pal23‘ ’baseN(pal23, 3)‘ ’baseN(pal23, 2))</lang>
{{out}}
<pre>
0 0 0
1 1 1
6643 100010001 1100111110011
1422773 2200021200022 101011011010110110101
5415589 101012010210101 10100101010001010100101
90396755477 22122022220102222022122 1010100001100000100010000011000010101
</pre>
=={{header|Ada}}==
|