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

Source code in the 11l programming language

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, radix' 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))

  

You may also check:How to resolve the algorithm 24 game step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Executable library step by step in the Pascal programming language
You may also check:How to resolve the algorithm Hofstadter Q sequence step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Cartesian product of two or more lists step by step in the Delphi programming language
You may also check:How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the J programming language