How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Sidef 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 Sidef 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 Sidef programming language

Source code in the sidef programming language

var format = "%11s %24s %38s\n"
format.printf("decimal", "ternary", "binary")
format.printf(0, 0, 0)

for n in (0 .. 2e5) {
    var pal = n.base(3)||''
    var b3 = (pal + '1' + pal.flip)
    var b2 = Num(b3, 3).base(2)
    if (b2 == b2.flip) {
        format.printf(Num(b2, 2), b3, b2)
    }
}


  

You may also check:How to resolve the algorithm Leap year step by step in the zkl programming language
You may also check:How to resolve the algorithm Terminal control/Unicode output step by step in the Phix programming language
You may also check:How to resolve the algorithm Read entire file step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Loops/Break step by step in the Transact-SQL programming language
You may also check:How to resolve the algorithm String case step by step in the MATLAB / Octave programming language