How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Arturo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Arturo programming language
Table of Contents
Problem Statement
It's permissible to assume the first two numbers and simply list them.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Arturo programming language
Source code in the arturo programming language
pal2?: function [n][
digs2: digits.base:2 n
return digs2 = reverse digs2
]
revNumber: function [z][
u: z
result: 0
while [u > 0][
result: result + (2*result) + u%3
u: u/3
]
return result
]
pal23: function [][
p3: 1
cnt: 1
print [
pad (to :string 0)++" :" 14
pad.right join to [:string] digits.base:2 0 37 "->"
join to [:string] digits.base:3 0
]
loop 0..31 'p [
while [(p3*(1+3*p3)) < shl 1 2*p]-> p3: p3*3
bound: (shl 1 2*p)/3*p3
limDown: max @[p3/3, bound]
limUp: min @[2*bound, p3-1]
if limUp >= limDown [
loop limDown..limUp 'k [
n: (revNumber k) + (1+3*k)*p3
if pal2? n [
print [
pad (to :string n)++" :" 14
pad.right join to [:string] digits.base:2 n 37 "->"
join to [:string] digits.base:3 n
]
cnt: cnt + 1
if cnt=6 -> return null
]
]
]
]
]
pal23
You may also check:How to resolve the algorithm Comments step by step in the SenseTalk programming language
You may also check:How to resolve the algorithm Knight's tour step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the PL/I programming language
You may also check:How to resolve the algorithm Generator/Exponential step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the BQN programming language