Smallest power of 6 whose decimal expansion contains n: Difference between revisions
Smallest power of 6 whose decimal expansion contains n (view source)
Revision as of 12:36, 6 February 2024
, 4 months ago→{{header|Wren}}: Minor tidy
Alextretyak (talk | contribs) m (Small fix of Python solution) |
m (→{{header|Wren}}: Minor tidy) |
||
(17 intermediate revisions by 9 users not shown) | |||
Line 6:
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">F smallest_six(n)
V p = BigInt(1)
L String(n) !C String(p)
p *= 6
R p
L(n) 22
print(‘#2: #.’.format(n, smallest_six(n)))</syntaxhighlight>
{{out}}
<pre>
0: 10077696
1: 1
2: 216
3: 36
4: 46656
5: 46656
6: 6
7: 7776
8: 2176782336
9: 1296
10: 10077696
11: 2821109907456
12: 1296
13: 13060694016
14: 6140942214464815497216
15: 101559956668416
16: 216
17: 60466176
18: 470184984576
19: 21936950640377856
20: 170581728179578208256
21: 216
</pre>
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses ALGOL 68G's LONG LONG INT large integers, the default precision is sufficient for this task. Also uses the ALGOL 68G specific string in string procedure.
<
# returns s blank-padded on the right to at least len characters #
PROC right pad = ( STRING s, INT len )STRING:
Line 60 ⟶ 98:
OD
OD
END</
{{out}}
<pre>
Line 89 ⟶ 127:
=={{header|ALGOL W}}==
Algol W doesn't have integers larger than 32 bits, however we can handle the required numbers with arrays of digits.
<
% we assume that powers of 6 upto 6^32 will be sufficient %
% as Algol W does not have integers longer than 32 bits, the powers %
Line 146 ⟶ 184:
for d := digits( p ) step -1 until 1 do writeon( i_w := 1, s_w := 0, powers( p, d ) )
end for_n
end.</
{{out}}
<pre>
Line 172 ⟶ 210:
21 in 6^ 3: 216
</pre>
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">loop 0..22 'n [
ns: to :string n
print [pad to :string n 2 "->" 6 ^ first select.first 0..∞ 'x -> contains? to :string 6^x ns]
]</syntaxhighlight>
{{out}}
<pre> 0 -> 10077696
1 -> 1
2 -> 216
3 -> 36
4 -> 46656
5 -> 46656
6 -> 6
7 -> 7776
8 -> 2176782336
9 -> 1296
10 -> 10077696
11 -> 2821109907456
12 -> 1296
13 -> 13060694016
14 -> 6140942214464815497216
15 -> 101559956668416
16 -> 216
17 -> 60466176
18 -> 470184984576
19 -> 21936950640377856
20 -> 170581728179578208256
21 -> 216
22 -> 131621703842267136</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f SMALLEST_POWER_OF_6_WHOSE_DECIMAL_EXPANSION_CONTAINS_N.AWK
BEGIN {
Line 189 ⟶ 260:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 218 ⟶ 289:
=={{header|C}}==
<
#include <string.h>
#include <gmp.h>
Line 251 ⟶ 322:
return 0;
}</
{{out}}
Line 279 ⟶ 350:
=={{header|C++}}==
<
#include <iomanip>
#include <string>
Line 301 ⟶ 372:
}
return 0;
}</
{{out}}
Line 328 ⟶ 399:
=={{header|CLU}}==
<
% It is in "misc.lib"
%
Line 362 ⟶ 433:
stream$putl(po, "")
end
end start_up</
{{out}}
<pre> 0: 6^9 = 10077696
Line 388 ⟶ 459:
=={{header|F_Sharp|F#}}==
<
// Nigel Galloway. April 9th., 2021
let rec fN i g e l=match l%i=g,l/10I with (true,_)->e |(_,l) when l=0I->fN i g (e*6I) (e*6I) |(_,l)->fN i g e l
[0I..99I]|>Seq.iter(fun n->printfn "%2d %A" (int n)(fN(if n>9I then 100I else 10I) n 1I 1I))
</syntaxhighlight>
{{out}}
<pre>
Line 500 ⟶ 571:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
present sequences tools.memory.private ;
Line 509 ⟶ 580:
present powers-of-6 [ present subseq? ] with lfilter car ;
22 [ dup smallest commas "%2d %s\n" printf ] each-integer</
{{out}}
<pre>
Line 539 ⟶ 610:
=={{header|FreeBASIC}}==
{{trans|Ring}}
<
Print !"\ntrabajando...\n"
Print !"M¡nima potencia de 6 cuya expansi¢n decimal contiene n:\n"
Line 559 ⟶ 630:
Print !"\n--- terminado, pulsa RETURN---"
Sleep
</syntaxhighlight>
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 606 ⟶ 677:
}
}
}</
{{out}}
Line 636 ⟶ 707:
=={{header|Haskell}}==
<
import Text.Printf (printf)
smallest :: Integer -> Integer
smallest n = d
where
Just d = find ((show n `isInfixOf`) . show) sixes
sixes :: [Integer]
sixes = iterate (* 6) 1
main :: IO ()
main =
putStr $
[0 .. 21] >>= printf "%2d: %d\n" <*> smallest</syntaxhighlight>
{{out}}
<pre> 0: 10077696
1: 1
Line 685 ⟶ 750:
gojq provides unbounded-precision integer arithmetic and is therefore appropriate for this task.
<
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
Line 692 ⟶ 757:
| tostring as $n
| first(range(0;infinite) as $i | 6 | power($i) | . as $p | tostring | (index($n) // empty)
| [$in,$i,$p] )</
{{out}}
<pre>
Line 721 ⟶ 786:
=={{header|Julia}}==
<
digcontains(n, dig) = contains(String(Char.(digits(n))), String(Char.(dig)))
Line 737 ⟶ 802:
println(rpad(n, 5), format(findpow6containing(n), commas=true))
end
</
<pre>
0 10,077,696
Line 764 ⟶ 829:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
SmallestPowerContainingN[n_Integer] := Module[{i = 1, test},
While[True,
Line 773 ⟶ 838:
]
]
Grid[SmallestPowerContainingN /@ Range[0, 21]]</
{{out}}
<pre>0 9 10077696
Line 800 ⟶ 865:
=={{header|Nim}}==
{{libheader|bignum}}
<
import bignum
Line 818 ⟶ 883:
echo "Smallest values of k such that 6^k contains n:"
for n, (k, s) in results:
echo &"{n:2}: 6^{k:<2} = {s}"</
{{out}}
Line 846 ⟶ 911:
=={{header|Pascal}}==
==={{
Doing long multiplikation like in primorial task.<BR>I used to check every numberstring one after the other on one 6^ n string.Gets really slow on high n<BR>After a closer look into [[Phix|Smallest_power_of_6_whose_decimal_expansion_contains_n#Phix]] I applied a slghtly modified version of Pete
<
//First occurence of a numberstring with max decimal DIGTIS digits in 6^n
{$IFDEF FPC}
{$MODE DELPHI} {$Optimization ON,ALL} {$COPERATORS ON}{$CODEALIGN proc=16}
{$ENDIF}
{$IFDEF WINDOWS}
{$APPTYPE CONSOLE}
{$ENDIF}
Line 860 ⟶ 925:
sysutils;
const
//decimal places used by multiplication and for string conversion
PowerBase = 6; // don't use 10^n ;-)
// for PowerBase = 2 maxvalues for POT_LIMIT and STRCOUNT
// DIGITS = 8;decLimit= 100*1000*1000;POT_LIMIT = 114715;STRCOUNT = 83789;
DIGITS = 7;decLimit= 10*1000*1000;POT_LIMIT = 32804;STRCOUNT = 24960;
// DIGITS = 6;decLimit= 1000*1000;POT_LIMIT = 9112;STRCOUNT = 7348;
// DIGITS = 5;decLimit= 100*1000;POT_LIMIT = 2750;STRCOUNT = 2148;
// DIGITS = 4;decLimit= 10*1000;POT_LIMIT = 809;STRCOUNT = 616;
// DIGITS = 3;decLimit= 1000;POT_LIMIT = 215;STRCOUNT = 175;
// DIGITS = 2;decLimit= 100;POT_LIMIT = 66;STRCOUNT = 45;
type
tMulElem = Uint32;
Line 873 ⟶ 945:
tFound = record
foundIndex
end;
var
{$ALIGN 32}
PotArrN : tPotArrN;
StrDec4Dgts : array[0..9999] of String[4];
Str_Found : array of tFound;
FoundString : array of AnsiString;
CheckedNum : array of boolean;
Pot_N_str : AnsiString;
FirstMissing,
FoundIdx :NativeInt;
T0 : INt64;
procedure
var
i : integer;
a,b,c,d : char;
begin
Begin
s[1] := a;
begin
For c := '0' to '9' do
begin
StrDec4Dgts[i]:= s;
inc(i);
end;
end;
end;
end;
end;
Line 930 ⟶ 1,000:
exit;
end;
toIdx := 4*(toIdx DIV 3)+toIdx MOD 3 +1 ;
setlength(result,toIdx);
repeat
result[toIdx] := s[FromIdx];
result[toIdx-1] := s[FromIdx-1];
result[toIdx-2] := s[FromIdx-2];
Line 947 ⟶ 1,016:
dec(fromIdx);
end;
end;
procedure Init_Mul(number:NativeInt);
var
dgtCount,
MaxMulIdx : NativeInt;
Begin
dgtCount := trunc(POT_LIMIT*ln(number)/ln(10))+1;
MaxMulIdx := dgtCount DIV calcDigits +2;
setlength(PotArrN[0],MaxMulIdx);
setlength(PotArrN[1],MaxMulIdx);
PotArrN[0,0] := 1;
setlength(Pot_N_str,dgtCount);
end;
function Mul_PowerBase(var Mul1,Mul2:tMul;limit:Uint32):NativeInt;
//Mul2 = n*Mul1. n must be < LongWordDec !
const
LongWordDec = 100*1000*1000;
var
pM1,pM2 : tpMul;
carry,prod : Uint64;
begin
pM1 := @Mul1[0];
pM2 := @Mul2[0];
carry := 0;
result :=0;
repeat
prod := PowerBase*pM1[result]+Carry;
Carry := prod Div LongWordDec;
pM2[result] := Prod - Carry*LongWordDec;
inc(result);
until result > limit;
IF Carry <> 0 then
pM2[result] := Carry
else
dec(result);
end;
procedure ConvToStr(var s:Ansistring;const Mul:tMul;i:NativeInt);
var
pS : pChar;
j,k,d,m : NativeInt;
begin
setlength(s,j+1);
pS :=
m := Mul[i];
j := length(s8);
move(s8[1],pS[0],j);
k := j;
dec(i);
If i >= 0 then
repeat
move(StrDec4Dgts[d][1],pS[k],4);
move(
inc(k,calcDigits);
dec(i);
until i<0;
Line 979 ⟶ 1,084:
function CheckOneString(const s:Ansistring;pow:NativeInt):NativeInt;
//check every possible number from one to DIGITS digits,
//if it is still missing in the list
var
pChecked : pBoolean;
i,k,lmt,num : NativeInt;
begin
pChecked := @CheckedNum[0];
result := 0;
lmt := length(s);
For i := 1 to lmt do
Line 994 ⟶ 1,101:
repeat
num := num*10+ Ord(s[k])-Ord('0');
IF (num >= FirstMissing) AND Not(
begin
//memorize that string commatized
if NOT(oneFound) then
FoundIDX += 1;
end;
pChecked[num]:= true;
with str_Found[num] do
Begin
foundIndex:= pow+1;
foundStrIdx:= FoundIDX-1;
end;
inc(result);
if num =
repeat
inc(FirstMissing)
until str_Found[FirstMissing].foundIndex =0;
end;
inc(k)
Line 1,012 ⟶ 1,128:
var
i,j,
Begin
T0 := GetTickCount64;
setlength(Str_Found,decLimit);
setlength(CheckedNum,decLimit);
setlength(FoundString,STRCOUNT);
FirstMissing := 0;
FoundIdx := 0;
Init_StrDec4Dgts;
Init_Mul(PowerBase);
writeln('Init in ',(GetTickCount64-T0)/1000:8:3,' secs');
T0 := GetTickCount64;
toggle := 0;
found := 0;
MaxMulIdx := 0;
k := 0;
For j := 0 to POT_LIMIT do
Begin
// if j MOD 20 = 0 then writeln;
ConvToStr(Pot_N_str,PotArrN[toggle],MaxMulIdx);
found += i;
if i <> 0 then
k += 1;
MaxMulIdx := Mul_PowerBase(PotArrN[toggle],PotArrN[1-toggle],MaxMulIdx);
toggle := 1-toggle;
if FirstMissing = decLimit then
Begin
writeln(#10,'Max power ',j,' with ',length(Pot_N_str),' digits');
break;
end;
// if (j and 1023) = 0 then write(#13,j:10,found:10,FirstMissing:10);
end;
writeln(#13#10,'Found: ',found,' in ',k,' strings. Time used ',(GetTickCount64-T0)/1000:8:3,' secs');
For i := 0 to 22 do//decLimit-1 do
with Str_Found[i] do
writeln(i:10,' ',PowerBase,'^',foundIndex-1:5,' ',(FoundString[foundStrIdx]):30);
end.
</syntaxhighlight>
{{out|@TIO.RUN}}
<pre>
Init in 0.062 secs
Max power 21798 with 16963 digits
Found: 10000000 in 15889 strings. Time used 8.114 secs
0 6^ 9 10,077,696
1 6^ 0 1
2 6^ 3 216
3 6^ 2 36
4 6^ 6 46,656
5 6^ 6 46,656
6 6^ 1 6
7 6^ 5 7,776
8 6^ 12 2,176,782,336
9 6^ 4 1,296
10 6^ 9 10,077,696
11 6^ 16 2,821,109,907,456
12 6^ 4 1,296
13 6^ 13 13,060,694,016
14 6^ 28 6,140,942,214,464,815,497,216
15 6^ 18 101,559,956,668,416
16 6^ 3 216
17 6^ 10 60,466,176
18 6^ 15 470,184,984,576
19 6^ 21 21,936,950,640,377,856
20 6^ 26 170,581,728,179,578,208,256
21 6^ 3 216
22 6^ 22 131,621,703,842,267,136
Real time: 8.383 s User time: 8.133 s Sys. time: 0.185 s CPU share: 99.23 %
</pre>
=={{header|Perl}}==
<
use warnings;
use List::Util 'first';
Line 1,117 ⟶ 1,214:
my $e = first { 6**$_ =~ /$n/ } 0..1000;
printf "%7d: 6^%-3s %s\n", $n, $e, comma 6**$e;
}</
{{out}}
<pre> 0: 6^9 10,077,696
Line 1,147 ⟶ 1,244:
(Related recent task: [[Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#Phix]])
<!--<
<span style="color: #008080;">constant</span> <span style="color: #000000;">lim</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">22</span> <span style="color: #000080;font-style:italic;">-- (tested to 10,000,000)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">(),</span> <span style="color: #000000;">t1</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">t0</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span>
Line 1,193 ⟶ 1,290:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">printf</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"%2d %29s = 6^%d\n"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">),</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pwr</span><span style="color: #0000FF;">}),</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
Line 1,223 ⟶ 1,320:
=={{header|Python}}==
<
p = 1
while str(n) not in str(p): p *= 6
Line 1,229 ⟶ 1,326:
for n in range(22):
print("{:2}: {}".format(n, smallest_six(n)))</
{{out}}
<pre> 0: 10077696
Line 1,254 ⟶ 1,351:
21: 216</pre>
=={{header|
<syntaxhighlight lang="Quackery"> [ 0 swap
[ dip 1+
10 /
dup 0 = until ]
drop ] is digits ( n --> n )
[ 10 over digits
** temp put
false unrot
[ over temp share mod
over = iff
[ rot not unrot ]
done
dip [ 10 / ]
over 0 = until ]
2drop
temp release ] is contains ( n n --> b )
[ -1 swap
[ dip 1+
over 6 swap **
over contains
until ]
drop ] is smallest ( n --> n )
22 times
[ i^ 10 < if sp
i^ echo
say " --> "
6 i^ smallest **
echo cr ]
cr
say "The smallest power of 6 whose decimal expansion contains 31415926 is 6^"
31415926 smallest echo say "." cr</syntaxhighlight>
{{out}}
<pre> 0 --> 10077696
1 --> 1
2 --> 216
3 --> 36
4 --> 46656
5 --> 46656
6 --> 6
7 --> 7776
8 --> 2176782336
9 --> 1296
10 --> 10077696
11 --> 2821109907456
12 --> 1296
13 --> 13060694016
14 --> 6140942214464815497216
15 --> 101559956668416
16 --> 216
17 --> 60466176
18 --> 470184984576
19 --> 21936950640377856
20 --> 170581728179578208256
21 --> 216
The smallest power of 6 whose decimal expansion contains 31415926 is 6^4261.</pre>
=={{header|Raku}}==
<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers;
my @po6 = ^Inf .map: *.exp: 6;
Line 1,265 ⟶ 1,424:
sprintf "%3d: 6%-4s %s", $n, .&super, comma @po6[$_]
given @po6.first: *.contains($n), :k
};</
{{out}}
<pre> 0: 6⁹ 10,077,696
Line 1,292 ⟶ 1,451:
=={{header|REXX}}==
<
numeric digits 100 /*ensure enough decimal digs for 6**N */
parse arg hi . /*obtain optional argument from the CL.*/
Line 1,313 ⟶ 1,472:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</
{{out|output|text= when using the default input:}}
<pre>
Line 1,344 ⟶ 1,503:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 1,367 ⟶ 1,526:
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 1,397 ⟶ 1,556:
</pre>
=={{header|RPL}}==
1980s RPL can only handle 64-bit unsigned integers, which means a multi-precision multiplication is here required.
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ 1000000000 → x n p
≪ { } # 0d
x SIZE 1 '''FOR''' j
x j GET n * +
DUP p / SWAP OVER p * - ROT + SWAP
-1 '''STEP'''
'''IF''' DUP # 0d ≠ '''THEN''' SWAP + '''ELSE''' DROP '''END'''
≫ ≫ '<span style="color:blue">MMULT</span>' STO
≪ "" SWAP
1 OVER SIZE '''FOR''' d
DUP d GET →STR 3 OVER SIZE 1 - SUB
'''IF''' d 1 ≠ '''THEN'''
'''WHILE''' DUP SIZE 9 < REPEAT "0" SWAP +
'''END END'''
ROT SWAP + SWAP
'''NEXT''' DROP
≫ '<span style="color:blue">M→STR</span>' STO
≪
{ # 1d } SWAP
WHILE DUP REPEAT
SWAP 6 <span style="color:blue">MMULT</span> SWAP 1 - END
DROP <span style="color:blue">M→STR</span>
≫ '<span style="color:blue">POW6</span>' STO
≪ DEC { }
0 21 '''FOR''' n
n →STR -1
DO 1 + DUP '''POW6'''
'''UNTIL''' 3 PICK POS '''END'''
<span style="color:blue">POW6</span> ROT SWAP + SWAP DROP
NEXT
≫ '<span style="color:blue">TASK</span>' STO
|
<span style="color:blue">MMULT</span> ''( { #multi #precision } n -- { #multi #precision } )''
initialize stack with empty result number and carry
loop from the lowest digit block
multiply block by n, add carry
prepare carry for next block
if carry ≠ 0 then add it as a new block
<span style="color:blue">M→STR</span> ''( { #multi #precision } -- "integer" )''
for each digit block
turn it into string, remove both ends
if not the highest block
fill with "0"
add to previous blocks' string
<span style="color:blue">POW6</span> ''( n -- { #multi #precision } )''
{ #1d } is 1 in multi-precision
multiply n times
by 6
make it a string
Forces decimal mode for integer display
for n < 22
turn n into string, initialize counter
get 6^n
until "n" in "6^n"
remake n a string and add it to result list
|}
{{out}}
<pre>
1: { "10077696" "1" "216" "36" "46656" "46656" "6" "7776" "2176782336" "1296" "10077696" "2821109907456" "1296" "13060694016" "6140942214464815497216" "101559956668416" "216" "60466176" "470184984576" "21936950640377856" "170581728179578208256" "216" }
</pre>
====2000s RPL version====
Big integers are native in this version.
{{works with|HP|49}}
≪ { }
0 21 '''FOR''' n
0
'''WHILE''' 6 OVER ^ →STR n →STR POS NOT
'''REPEAT''' 1 + '''END'''
"'6^" SWAP + STR→ +
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: { 6^9 6^0 6^3 6^2 6^6 6^6 6^1 6^5 6^12 6^4 6^9 6^16 6^4 6^13 6^28 6^18 6^3 6^10 6^15 6^21 6^26 6^3 }
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">def smallest_6(n)
i = 1
c = 0
s = n.to_s
until i.to_s.match?(s)
c += 1
i *= 6
end
[n, c, i]
end
(0..21).each{|n| puts "%3d**%-3d: %d" % smallest_6(n) }
</syntaxhighlight>
{{out}}
<pre> 0**9 : 10077696
1**0 : 1
2**3 : 216
3**2 : 36
4**6 : 46656
5**6 : 46656
6**1 : 6
7**5 : 7776
8**12 : 2176782336
9**4 : 1296
10**9 : 10077696
11**16 : 2821109907456
12**4 : 1296
13**13 : 13060694016
14**28 : 6140942214464815497216
15**18 : 101559956668416
16**3 : 216
17**10 : 60466176
18**15 : 470184984576
19**21 : 21936950640377856
20**26 : 170581728179578208256
21**3 : 216
</pre>
=={{header|Wren}}==
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<
import "./fmt" for Fmt
System.print(" n smallest power of 6 which contains n")
Line 1,415 ⟶ 1,711:
i = i + 1
}
}</
{{out}}
Line 1,443 ⟶ 1,739:
21 6^3 = 216
</pre>
=={{header|Yabasic}}==
{{trans|Python}}
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Smallest_power_of_6_whose_decimal_expansion_contains_n
// by Galileo, 05/2022
sub smallest_six(n)
local p, n$
n$ = str$(n)
p = 1
while not instr(str$(p, "%1.f"), n$) p = p * 6 : wend
return p
end sub
for n = 0 to 21 : print n, ": ", str$(smallest_six(n), "%1.f") : next</syntaxhighlight>
{{out}}
<pre>0: 10077696
1: 1
2: 216
3: 36
4: 46656
5: 46656
6: 6
7: 7776
8: 2176782336
9: 1296
10: 10077696
11: 2821109907456
12: 1296
13: 13060694016
14: 6140942214464815497216
15: 101559956668416
16: 216
17: 60466176
18: 470184984576
19: 21936950640377856
20: 170581728179578208256
21: 216
---Program done, press RETURN---</pre>
|