How to resolve the algorithm Minimum positive multiple in base 10 using only 0 and 1 step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Minimum positive multiple in base 10 using only 0 and 1 step by step in the zkl programming language

Table of Contents

Problem Statement

Every positive integer has infinitely many base-10 multiples that only use the digits 0 and 1. The goal of this task is to find and display the minimum multiple that has this property. This is simple to do, but can be challenging to do efficiently. To avoid repeating long, unwieldy phrases, the operation "minimum positive multiple of a positive integer n in base 10 that only uses the digits 0 and 1" will hereafter be referred to as "B10". Write a routine to find the B10 of a given integer.
E.G. and so on. Use the routine to find and display here, on this page, the B10 value for: Optionally find B10 for: Stretch goal; find B10 for: There are many opportunities for optimizations, but avoid using magic numbers as much as possible. If you do use magic numbers, explain briefly why and what they do for your implementation.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Minimum positive multiple in base 10 using only 0 and 1 step by step in the zkl programming language

Source code in the zkl programming language

var [const]
  B10_4=10*10*10*10,
  HexB10=T(0000,0001,0010,0011,0100,0101,0110,0111,
           1000,1001,1010,1011,1100,1101,1110,1111);
 
  // Convert n from binary as if it is Base 10
  // limited for Uint64 to 2^20-1= 1048575 ala 19 digits
  //   for int64, limited to 2^19-1= 524287, conv2B10()-->1111111111111111111
const B10_MAX=(2).pow(19) - 1;

fcn conv2B10(n){
   facB10,result := 1,0;
   while(n>0){
      result=facB10*HexB10[n.bitAnd(15)] + result;
      n=n/16;
      facB10*=B10_4;
   }
   result
}
fcn findB10(n){	// --> -1 if overflow signed 64 bit int
   i:=0;
   while(i
   return(-1);  // overflow 64 bit signed int
}

foreach r in (T([1..10],[95..105],
           T(297, 576, 891, 909, 1998, 2079, 2251, 2277, 2439, 2997, 4878))){
   foreach n in (r){ 
      b10:=findB10(n);
      if(b10==-1) println("B10(%4d): Out of range".fmt(n));
      else        println("B10(%4d) = %d = %d * %d".fmt(n,b10,n,b10/n));
   }
}

  

You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Io programming language
You may also check:How to resolve the algorithm The sieve of Sundaram step by step in the Go programming language
You may also check:How to resolve the algorithm Documentation step by step in the Neko programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the jq programming language
You may also check:How to resolve the algorithm Metronome step by step in the Nim programming language