How to resolve the algorithm First power of 2 that has leading decimal digits of 12 step by step in the Yabasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm First power of 2 that has leading decimal digits of 12 step by step in the Yabasic programming language

Table of Contents

Problem Statement

(This task is taken from a   Project Euler   problem.) (All numbers herein are expressed in base ten.)

27   =   128   and   7   is the first power of   2   whose leading decimal digits are   12. The next power of   2   whose leading decimal digits are   12   is   80, 280   =   1208925819614629174706176.

Define     p(L,n)     to be the nth-smallest value of   j   such that the base ten representation of   2j   begins with the digits of   L .

You are also given that:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm First power of 2 that has leading decimal digits of 12 step by step in the Yabasic programming language

Source code in the yabasic programming language

FAC = 0.30102999566398119521373889472449302677

print p(12, 1)
print p(12, 2)
print p(123, 45)
print p(123, 12345)
print p(123, 678910)
end

sub p(L, n)
    cont = 0 : j = 0
    LS$ = str$(L)
    while cont < n
        j = j + 1
        x = FAC * j
        //if x < len(LS$)  continue while       'sino da error
        y = 10^(x-int(x))
        y = y * 10^len(LS$)
        digits$ = str$(y)
        if left$(digits$, len(LS$)) = LS$  cont = cont + 1
    end while
    return j
end sub

  

You may also check:How to resolve the algorithm Sockets step by step in the AWK programming language
You may also check:How to resolve the algorithm URL encoding step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Set right-adjacent bits step by step in the F# programming language
You may also check:How to resolve the algorithm Left factorials step by step in the Wren programming language
You may also check:How to resolve the algorithm Canny edge detector step by step in the Raku programming language