Smallest power of 6 whose decimal expansion contains n: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
 
(20 intermediate revisions by 11 users not shown)
Line 6: 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}}==
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
{{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.
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.
<lang algol68>BEGIN # find the smallest k such that the decimal representation of 6^k contains n for 0 <= n <= 21 #
<syntaxhighlight lang="algol68">BEGIN # find the smallest k such that the decimal representation of 6^k contains n for 0 <= n <= 21 #
# returns s blank-padded on the right to at least len characters #
# returns s blank-padded on the right to at least len characters #
PROC right pad = ( STRING s, INT len )STRING:
PROC right pad = ( STRING s, INT len )STRING:
Line 60: Line 98:
OD
OD
OD
OD
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 89: Line 127:
=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
Algol W doesn't have integers larger than 32 bits, however we can handle the required numbers with arrays of digits.
Algol W doesn't have integers larger than 32 bits, however we can handle the required numbers with arrays of digits.
<lang algolw>begin % find the smallest power of 6 that contains n for 0 <= n <= 21 %
<syntaxhighlight lang="algolw">begin % find the smallest power of 6 that contains n for 0 <= n <= 21 %
% we assume that powers of 6 upto 6^32 will be sufficient %
% 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 %
% as Algol W does not have integers longer than 32 bits, the powers %
Line 146: Line 184:
for d := digits( p ) step -1 until 1 do writeon( i_w := 1, s_w := 0, powers( p, d ) )
for d := digits( p ) step -1 until 1 do writeon( i_w := 1, s_w := 0, powers( p, d ) )
end for_n
end for_n
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 172: Line 210:
21 in 6^ 3: 216
21 in 6^ 3: 216
</pre>
</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}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SMALLEST_POWER_OF_6_WHOSE_DECIMAL_EXPANSION_CONTAINS_N.AWK
# syntax: GAWK -f SMALLEST_POWER_OF_6_WHOSE_DECIMAL_EXPANSION_CONTAINS_N.AWK
BEGIN {
BEGIN {
Line 189: Line 260:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 218: Line 289:


=={{header|C}}==
=={{header|C}}==
<lang C>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
#include <string.h>
#include <gmp.h>
#include <gmp.h>
Line 251: Line 322:
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 279: Line 350:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <iomanip>
#include <iomanip>
#include <string>
#include <string>
Line 301: Line 372:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 326: Line 397:
20: 170581728179578208256
20: 170581728179578208256
21: 216</pre>
21: 216</pre>

=={{header|CLU}}==
<syntaxhighlight lang="clu">% This program uses the bigint type that comes with PCLU.
% It is in "misc.lib"
%
% pclu -merge $CLUHOME/lib/misc.lib -compile n6_contains_6.clu

smallest_power_6 = proc (n: int) returns (int, bigint)
n_str: string := int$unparse(n)
six_power: bigint := bigint$i2bi(1)
six: bigint := bigint$i2bi(6)
n_power: int := 0
while true do
pow_str: string := bigint$unparse(six_power)
if string$indexs(n_str, pow_str) ~= 0 then
return(n_power, six_power)
end
six_power := six_power * six
n_power := n_power + 1
end
end smallest_power_6

start_up = proc ()
po: stream := stream$primary_output()
for n: int in int$from_to(0, 21) do
p: int val: bigint
stream$putright(po, int$unparse(n), 2)
stream$puts(po, ": 6^")
p, val := smallest_power_6(n)
stream$putleft(po, int$unparse(p), 2)
stream$puts(po, " = ")
stream$putright(po, bigint$unparse(val), 30)
stream$putl(po, "")
end
end start_up</syntaxhighlight>
{{out}}
<pre> 0: 6^9 = 10077696
1: 6^0 = 1
2: 6^3 = 216
3: 6^2 = 36
4: 6^6 = 46656
5: 6^6 = 46656
6: 6^1 = 6
7: 6^5 = 7776
8: 6^12 = 2176782336
9: 6^4 = 1296
10: 6^9 = 10077696
11: 6^16 = 2821109907456
12: 6^4 = 1296
13: 6^13 = 13060694016
14: 6^28 = 6140942214464815497216
15: 6^18 = 101559956668416
16: 6^3 = 216
17: 6^10 = 60466176
18: 6^15 = 470184984576
19: 6^21 = 21936950640377856
20: 6^26 = 170581728179578208256
21: 6^3 = 216</pre>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Nigel Galloway. April 9th., 2021
// 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
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))
[0I..99I]|>Seq.iter(fun n->printfn "%2d %A" (int n)(fN(if n>9I then 100I else 10I) n 1I 1I))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 440: Line 571:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
{{works with|Factor|0.99 2021-02-05}}
<lang factor>USING: formatting kernel lists lists.lazy math math.functions
<syntaxhighlight lang="factor">USING: formatting kernel lists lists.lazy math math.functions
present sequences tools.memory.private ;
present sequences tools.memory.private ;


Line 449: Line 580:
present powers-of-6 [ present subseq? ] with lfilter car ;
present powers-of-6 [ present subseq? ] with lfilter car ;


22 [ dup smallest commas "%2d %s\n" printf ] each-integer</lang>
22 [ dup smallest commas "%2d %s\n" printf ] each-integer</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 479: Line 610:
=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
{{trans|Ring}}
{{trans|Ring}}
<lang freebasic>
<syntaxhighlight lang="freebasic">
Print !"\ntrabajando...\n"
Print !"\ntrabajando...\n"
Print !"M¡nima potencia de 6 cuya expansi¢n decimal contiene n:\n"
Print !"M¡nima potencia de 6 cuya expansi¢n decimal contiene n:\n"
Line 499: Line 630:
Print !"\n--- terminado, pulsa RETURN---"
Print !"\n--- terminado, pulsa RETURN---"
Sleep
Sleep
</syntaxhighlight>
</lang>




=={{header|Go}}==
=={{header|Go}}==
{{trans|Wren}}
{{trans|Wren}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 546: Line 677:
}
}
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 576: Line 707:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.List (isInfixOf)
<syntaxhighlight lang="haskell">import Data.List (find, isInfixOf)
import Text.Printf (printf)
import Text.Printf (printf)


smallest :: Integer -> Integer
smallest n = d
where
Just d = find ((show n `isInfixOf`) . show) sixes
sixes :: [Integer]
sixes :: [Integer]
sixes = iterate (* 6) 1
sixes = iterate (* 6) 1

smallest :: Integer -> Integer
smallest n =
head $
filter
((show n `isInfixOf`) . show)
sixes


main :: IO ()
main :: IO ()
main =
main =
putStr $
putStr $
[0 .. 21] >>= printf "%2d: %d\n" <*> smallest</syntaxhighlight>
concatMap
(printf "%2d: %d\n" <*> smallest)
[0 .. 21]</lang>

{{out}}
{{out}}

<pre> 0: 10077696
<pre> 0: 10077696
1: 1
1: 1
Line 625: Line 750:


gojq provides unbounded-precision integer arithmetic and is therefore appropriate for this task.
gojq provides unbounded-precision integer arithmetic and is therefore appropriate for this task.
<lang jq># To preserve precision:
<syntaxhighlight lang="jq"># To preserve precision:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);


Line 632: Line 757:
| tostring as $n
| tostring as $n
| first(range(0;infinite) as $i | 6 | power($i) | . as $p | tostring | (index($n) // empty)
| first(range(0;infinite) as $i | 6 | power($i) | . as $p | tostring | (index($n) // empty)
| [$in,$i,$p] )</lang>
| [$in,$i,$p] )</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 661: Line 786:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Formatting
<syntaxhighlight lang="julia">using Formatting


digcontains(n, dig) = contains(String(Char.(digits(n))), String(Char.(dig)))
digcontains(n, dig) = contains(String(Char.(digits(n))), String(Char.(dig)))
Line 677: Line 802:
println(rpad(n, 5), format(findpow6containing(n), commas=true))
println(rpad(n, 5), format(findpow6containing(n), commas=true))
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
0 10,077,696
0 10,077,696
Line 702: Line 827:
21 216
21 216
</pre>
</pre>

=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">ClearAll[SmallestPowerContainingN]
SmallestPowerContainingN[n_Integer] := Module[{i = 1, test},
While[True,
test = 6^i;
If[SequenceCount[IntegerDigits[test], IntegerDigits[n]] > 0,
Return[{n, i, test}]];
i++;
]
]
Grid[SmallestPowerContainingN /@ Range[0, 21]]</syntaxhighlight>
{{out}}
<pre>0 9 10077696
1 3 216
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|Nim}}==
=={{header|Nim}}==
{{libheader|bignum}}
{{libheader|bignum}}
<lang Nim>import strformat, strutils
<syntaxhighlight lang="nim">import strformat, strutils
import bignum
import bignum


Line 723: Line 883:
echo "Smallest values of k such that 6^k contains n:"
echo "Smallest values of k such that 6^k contains n:"
for n, (k, s) in results:
for n, (k, s) in results:
echo &"{n:2}: 6^{k:<2} = {s}"</lang>
echo &"{n:2}: 6^{k:<2} = {s}"</syntaxhighlight>


{{out}}
{{out}}
Line 751: Line 911:


=={{header|Pascal}}==
=={{header|Pascal}}==
{{Works with|Free Pascal}}
==={{header|Free 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, to get down < 10 secs on my 2200G for DIGITS = 7.TIO.RUN is slower.
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.
<lang pascal>program PotOf6;
<syntaxhighlight lang="pascal">program PotOf6;
//First occurence of a numberstring with max DIGTIS digits in 6^n
//First occurence of a numberstring with max decimal DIGTIS digits in 6^n
{$IFDEF FPC}
{$IFDEF FPC}
{$MODE DELPHI}
{$MODE DELPHI} {$Optimization ON,ALL} {$COPERATORS ON}{$CODEALIGN proc=16}
{$ENDIF}
{$Optimization ON,ALL}
{$IFDEF WINDOWS}
{$ELSE}
{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
{$ENDIF}
{$ENDIF}
Line 765: Line 925:
sysutils;
sysutils;
const
const
//decimal places used by multiplication and for string conversion
POT_LIMIT = 70000;
{ DIGITS = 8;
calcDigits = 8;
PowerBase = 6; // don't use 10^n ;-)
67584 99999998 46238296

Max power 68479
// for PowerBase = 2 maxvalues for POT_LIMIT and STRCOUNT
Found: 100000000 Time used 148.584 secs}
// DIGITS = 8;decLimit= 100*1000*1000;POT_LIMIT = 114715;STRCOUNT = 83789;
DIGITS = 7;
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
type
tMulElem = Uint32;
tMulElem = Uint32;
Line 778: Line 945:


tFound = record
tFound = record
foundIndex: Uint32;
foundIndex,
foundStr :Ansistring;
foundStrIdx : Uint32;
end;
end;

var
var
{$ALIGN 32}
PotArrN : tPotArrN;
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;
Pot_N_str : AnsiString;
FirstMissing,
Str_Found : array of tFound;
FirstMissing :NativeInt;
FoundIdx :NativeInt;
T0 : INt64;
T0 : INt64;


procedure Init_Mul(number:NativeInt);
procedure Init_StrDec4Dgts;
var
var
MaxMulIdx : NativeInt;
s : string[4];
i : integer;
Begin
a,b,c,d : char;
MaxMulIdx := trunc(POT_LIMIT*ln(number)/ln(10)/9+2);
setlength(PotArrN[0],MaxMulIdx);
setlength(PotArrN[1],MaxMulIdx);
PotArrN[0,0] := 1;
end;

function Mul_N(var Mul1,Mul2:tMul;limit,n:Uint32):NativeInt;
//Mul2 = n*Mul1. n must be < LongWordDec !
const
LongWordDec = 1000*1000*1000;
var
pM1,pM2 : tpMul;
carry,prod : Uint64;
begin
begin
pM1 := @Mul1[0];
i := 0;
pM2 := @Mul2[0];
s := '0000';
carry := 0;
For a := '0' to '9' do
Begin
result :=0;
s[1] := a;
repeat
prod := n*pM1[result]+Carry;
For b := '0' to '9' do
begin
Carry := prod Div LongWordDec;
pM2[result] := Prod - Carry*LongWordDec;
s[2]:=b;
For c := '0' to '9' do
inc(result);
until result > limit;
begin
IF Carry <> 0 then
s[3] := c;
pM2[result] := Carry
For d := '0' to '9' do
begin
else
dec(result);
s[4] := d;
StrDec4Dgts[i]:= s;
inc(i);
end;
end;
end;
end;
end;
end;


Line 835: Line 1,000:
exit;
exit;
end;
end;
toIdx := 4*(toIdx DIV 3)+toIdx MOD 3;
toIdx := 4*(toIdx DIV 3)+toIdx MOD 3 +1 ;
inc(toIdx);
setlength(result,toIdx);
setlength(result,toIdx);
repeat
repeat
result[toIdx] := s[FromIdx];
result[toIdx] := s[FromIdx];
result[toIdx-1] := s[FromIdx-1];
result[toIdx-1] := s[FromIdx-1];
result[toIdx-2] := s[FromIdx-2];
result[toIdx-2] := s[FromIdx-2];
Line 852: Line 1,016:
dec(fromIdx);
dec(fromIdx);
end;
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;
end;


procedure ConvToStr(var s:Ansistring;const Mul:tMul;i:NativeInt);
procedure ConvToStr(var s:Ansistring;const Mul:tMul;i:NativeInt);
var
var
s9: string[9];
s8: string[calcDigits];
pS : pChar;
pS : pChar;
j,k : NativeInt;
j,k,d,m : NativeInt;
begin
begin
// i := High(MUL);
j := (i+1)*calcDigits;
j := (i+1)*9;
setlength(s,j+1);
setlength(s,j+1);
pS := pChar(s);
pS := @s[1];
m := Mul[i];
// fill complete with '0'
fillchar(pS[0],j,'0');
str(Mul[i],s8);
j := length(s8);
str(Mul[i],S9);
move(s8[1],pS[0],j);
j := length(s9);
move(s9[1],pS[0],j);
k := j;
k := j;
dec(i);
dec(i);
If i >= 0 then
If i >= 0 then
repeat
repeat
str(Mul[i],S9);// no leading '0'
m := MUL[i];
j := length(s9);
d := m div 10000;
inc(k,9);
m := m-10000*d;
move(StrDec4Dgts[d][1],pS[k],4);
//move to the right place, leading '0' is already there
move(s9[1],pS[k-j],j);
move(StrDec4Dgts[m][1],pS[k+4],4);
inc(k,calcDigits);
dec(i);
dec(i);
until i<0;
until i<0;
Line 884: Line 1,084:


function CheckOneString(const s:Ansistring;pow:NativeInt):NativeInt;
function CheckOneString(const s:Ansistring;pow:NativeInt):NativeInt;
//check every possible number from one to DIGITS digits,
//check every possible number from one to DIGITS digits,
//if it is still missing in the list
//if it is still missing in the list
var
var
pChecked : pBoolean;
i,k,lmt,num : NativeInt;
i,k,lmt,num : NativeInt;
cs : Ansistring;
oneFound : boolean;
begin
begin
pChecked := @CheckedNum[0];
result := 0;
result := 0;
cs := '';
oneFound := false;
lmt := length(s);
lmt := length(s);
For i := 1 to lmt do
For i := 1 to lmt do
Line 899: Line 1,101:
repeat
repeat
num := num*10+ Ord(s[k])-Ord('0');
num := num*10+ Ord(s[k])-Ord('0');
IF (num >= FirstMissing) AND (str_Found[num].foundIndex = 0) then
IF (num >= FirstMissing) AND Not(pChecked[num]) then
begin
begin
//memorize that string commatized
str_Found[num].foundIndex:= pow+1;
if NOT(oneFound) then
// commatize only once. reference counted string
if cs ='' then
Begin
cs := Commatize(s);
oneFound := true;
str_Found[num].foundStr:= cs;
FoundString[FoundIDX] := Commatize(s);
FoundIDX += 1;
end;
pChecked[num]:= true;
with str_Found[num] do
Begin
foundIndex:= pow+1;
foundStrIdx:= FoundIDX-1;
end;
inc(result);
inc(result);
if num =irstMissing then
if num =FirstMissing then
repeat
while str_Found[FirstMissing].foundIndex <> 0 do
inc(FirstMissing);
inc(FirstMissing)
until str_Found[FirstMissing].foundIndex =0;
end;
end;
inc(k)
inc(k)
Line 917: Line 1,128:


var
var
i,j,number,toggle,MaxMulIdx,found,decLimit: Int32;
i,j,k,toggle,MaxMulIdx,found: Int32;
Begin
Begin
T0 := GetTickCount64;
T0 := GetTickCount64;
number := 6;//<1e9 no power of 10 ;-)
decLimit := 1;
For i := 1 to digits do
decLimit *= 10;
setlength(Str_Found,decLimit);
setlength(Str_Found,decLimit);
setlength(CheckedNum,decLimit);
Init_Mul(number);
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;
toggle := 0;
found := 0;
found := 0;
FirstMissing := 0;
MaxMulIdx := 0;
MaxMulIdx := 0;
k := 0;
For j := 0 to POT_LIMIT do
For j := 0 to POT_LIMIT do
Begin
Begin
// if j MOD 20 = 0 then writeln;
ConvToStr(Pot_N_str,PotArrN[toggle],MaxMulIdx);
ConvToStr(Pot_N_str,PotArrN[toggle],MaxMulIdx);
inc(found,CheckOneString(Pot_N_str,j));
i := CheckOneString(Pot_N_str,j);
found += i;
MaxMulIdx := Mul_N(PotArrN[toggle],PotArrN[1-toggle],MaxMulIdx,number);
if i <> 0 then
k += 1;
MaxMulIdx := Mul_PowerBase(PotArrN[toggle],PotArrN[1-toggle],MaxMulIdx);
toggle := 1-toggle;
toggle := 1-toggle;

if found>=decLimit then
if FirstMissing = decLimit then
Begin
Begin
writeln(#10,'Max power ',j);
writeln(#10,'Max power ',j,' with ',length(Pot_N_str),' digits');
break;
break;
end;
end;
if (j and 1023) = 0 then
// if (j and 1023) = 0 then write(#13,j:10,found:10,FirstMissing:10);
write(j:10,found:10,firstMissing:10,#13);
end;
end;
writeln(#13#10,'Found: ',found,' in ',k,' strings. Time used ',(GetTickCount64-T0)/1000:8:3,' secs');

writeln(#10,'Found: ',found,' Time used ',(GetTickCount64-T0)/1000:8:3,' secs');
For i := 0 to 22 do//decLimit-1 do
For i := 0 to 22 do//decLimit-1 do
with Str_Found[i] do
with Str_Found[i] do
writeln(i:10,' ',PowerBase,'^',foundIndex-1:5,' ',(FoundString[foundStrIdx]):30);
if foundIndex >0 then
end.
writeln(i:10,' ',number,'^',foundIndex-1:5,' ',foundStr);
</syntaxhighlight>
readln;
{{out|@TIO.RUN}}
end.</lang>
{{out}}
<pre>
<pre>
Init in 0.062 secs
TIO.RUN output
//Power found first missing
0 1 0
1024 751817 10020
2048 2168981 100017
3072 3733971 100017
4096 5305316 100672
5120 6747391 104835
6144 7922626 575115
7168 8776137 1000007
8192 9336696 1000015
9216 9667898 1000020
10240 9846933 1000088
11264 9935108 1000135
12288 9974783 1000204
13312 9990953 1000204
14336 9997035 1000204
15360 9999102 1000204
16384 9999744 1029358
17408 9999934 1029358
18432 9999978 1029358
19456 9999997 8091358
20480 9999999 8091358
21504 9999999 8091358
Max power 21798


Max power 21798 with 16963 digits
Found: 10000000 Time used 14.882 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


Found: 10000000 in 15889 strings. Time used 8.114 secs
Real time: 15.373 s

User time: 14.953 s
0 6^ 9 10,077,696
Sys. time: 0.254 s
1 6^ 0 1
CPU share: 98.92 %</pre>
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}}==
=={{header|Perl}}==
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use List::Util 'first';
use List::Util 'first';
Line 1,022: Line 1,214:
my $e = first { 6**$_ =~ /$n/ } 0..1000;
my $e = first { 6**$_ =~ /$n/ } 0..1000;
printf "%7d: 6^%-3s %s\n", $n, $e, comma 6**$e;
printf "%7d: 6^%-3s %s\n", $n, $e, comma 6**$e;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre> 0: 6^9 10,077,696
<pre> 0: 6^9 10,077,696
Line 1,052: Line 1,244:
(Related recent task: [[Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#Phix]])
(Related recent task: [[Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#Phix]])


<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<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: #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>
<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,098: Line 1,290:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<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>
<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>
<!--</lang>-->
<!--</syntaxhighlight>-->


{{out}}
{{out}}
Line 1,128: Line 1,320:


=={{header|Python}}==
=={{header|Python}}==
<lang python>def smallest_six(n):
<syntaxhighlight lang="python">def smallest_six(n):
p = 1
p = 1
while str(n) not in str(p): p *= 6
while str(n) not in str(p): p *= 6
Line 1,134: Line 1,326:
for n in range(22):
for n in range(22):
print("{:2}: {}".format(n, smallest_six(n))</lang>
print("{:2}: {}".format(n, smallest_six(n)))</syntaxhighlight>
{{out}}
{{out}}
<pre> 0: 10077696
<pre> 0: 10077696
Line 1,159: Line 1,351:
21: 216</pre>
21: 216</pre>


=={{header|Raku}}==
=={{header|Quackery}}==


<syntaxhighlight lang="Quackery"> [ 0 swap
<lang perl6>use Lingua::EN::Numbers;
[ 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;
sub super ($n) { $n.trans(<0 1 2 3 4 5 6 7 8 9> => <⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹>) }


my @po6 = ^Inf .map: *.exp: 6;
my @po6 = ^Inf .map: *.exp: 6;
Line 1,170: Line 1,424:
sprintf "%3d: 6%-4s %s", $n, .&super, comma @po6[$_]
sprintf "%3d: 6%-4s %s", $n, .&super, comma @po6[$_]
given @po6.first: *.contains($n), :k
given @po6.first: *.contains($n), :k
};</lang>
};</syntaxhighlight>
{{out}}
{{out}}
<pre> 0: 6⁹ 10,077,696
<pre> 0: 6⁹ 10,077,696
Line 1,197: Line 1,451:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds the smallest (decimal) power of 6 which contains N, where N < 22. */
<syntaxhighlight lang="rexx">/*REXX pgm finds the smallest (decimal) power of 6 which contains N, where N < 22. */
numeric digits 100 /*ensure enough decimal digs for 6**N */
numeric digits 100 /*ensure enough decimal digs for 6**N */
parse arg hi . /*obtain optional argument from the CL.*/
parse arg hi . /*obtain optional argument from the CL.*/
Line 1,218: Line 1,472:
exit 0 /*stick a fork in it, we're all done. */
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 ?</lang>
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
Line 1,249: Line 1,503:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
load "stdlib.ring"
load "stdlib.ring"


Line 1,272: Line 1,526:


see "done..." + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,302: Line 1,556:
</pre>
</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}}==
=={{header|Wren}}==
{{libheader|Wren-big}}
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/big" for BigInt
<syntaxhighlight lang="wren">import "./big" for BigInt
import "/fmt" for Fmt
import "./fmt" for Fmt


System.print(" n smallest power of 6 which contains n")
System.print(" n smallest power of 6 which contains n")
Line 1,320: Line 1,711:
i = i + 1
i = i + 1
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,348: Line 1,739:
21 6^3 = 216
21 6^3 = 216
</pre>
</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>

Latest revision as of 12:36, 6 February 2024

Smallest power of 6 whose decimal expansion contains n is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Show the smallest (non-negative integer) power of   6   whose decimal expansion contains   n,     where   n   <   22


11l

Translation of: Python
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)))
Output:
 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

ALGOL 68

Works with: ALGOL 68G version 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.

BEGIN # find the smallest k such that the decimal representation of 6^k contains n for 0 <= n <= 21 #
    # returns s blank-padded on the right to at least len characters #
    PROC right pad = ( STRING s, INT len )STRING:
         BEGIN
            INT s len = ( UPB s - LWB s ) + 1;
            IF s len >= len THEN s ELSE s + ( len - s len ) * " " FI
         END # right pad # ;
    # returns s blank-padded on the left to at least len characters #
    PROC left pad = ( STRING s, INT len )STRING:
         BEGIN
            INT s len = ( UPB s - LWB s ) + 1;
            IF s len >= len THEN s ELSE ( ( len - s len ) * " " ) + s FI
         END # left pad # ;
    # returns a string representation of unformatted with space separators                    #
    PROC space separate = ( STRING unformatted )STRING:
         BEGIN
            STRING result      := "";
            INT    ch count    := 0;
            FOR c FROM UPB unformatted BY -1 TO LWB unformatted DO
                IF   ch count <= 2 THEN ch count +:= 1
                ELSE                    ch count  := 1; " " +=: result
                FI;
                unformatted[ c ] +=: result
            OD;
            result
         END # space separate # ;
    # start with powers up to 6^12, if this proves insufficient, the kk array will be extended #
    FLEX[ 0 : 12 ]STRING kk;
    FOR k FROM LWB kk TO UPB kk DO kk[ k ] := whole( LONG LONG INT( 6 ) ^ k, 0 ) OD;
    # find the numbers #
    FOR i FROM 0 TO 21 DO
        STRING n      = whole( i, 0 );
        BOOL try again := TRUE;
        WHILE try again DO
            try again := FALSE;
            BOOL   found := FALSE;
            FOR k FROM LWB kk TO UPB kk WHILE NOT found DO
                IF string in string( n, NIL, kk[ k ] ) THEN
                    found := TRUE;
                    print( ( whole( i, -2 ), right pad( ": 6^" + whole( k, 0 ), 8 ), " ", left pad( space separate( kk[ k ] ), 30 ), newline ) )
                FI
            OD;
            IF NOT found THEN
                # haven't got enough k^k values - get some more #
                kk := HEAP[ 1 : UPB kk * 2 ]STRING;
                FOR k FROM LWB kk TO UPB kk DO kk[ k ] := whole( LONG LONG INT( 6 ) ^ k, 0 ) OD;
                try again := TRUE
            FI
        OD
    OD
END
Output:
 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

ALGOL W

Algol W doesn't have integers larger than 32 bits, however we can handle the required numbers with arrays of digits.

begin % find the smallest power of 6 that contains n for 0 <= n <= 21       %
    % 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     %
    % will be held in an array where each element is a single digit of the  %
    % power, the least significant digit of 6^n is in powers( n, 1 )        %
    integer array powers ( 0 :: 32, 1 :: 32 ); % the powers                 %
    integer array digits ( 0 :: 32 ); % the number of digits in each power  %
    integer array lowest ( 0 :: 21 ); % the lowest power containing the idx %
    for n := 0 until 21 do lowest( n ) := -1;
    % 6^0 = 1, which is the lowest power containing 1                       %
    lowest( 1 )    := 0;
    powers( 0, 1 ) := 1;
    for d := 2 until 32 do powers( 0, d ) := 0;
    digits( 0 ) := 1;
    % calculate the remaining powers and find the numbers 0..21             %
    for p := 1 until 32 do begin
        integer carry, dPos, dMax;
        dPos  := 1;
        dMax  := digits( p - 1 );
        carry := 0;
        % compute the power p and find the single digit numbers             %
        while dPos <= dMax do begin
            integer d;
            d                 := carry + ( powers( p - 1, dPos ) * 6 );
            carry             := d div 10;
            d                 := d rem 10;
            if lowest( d ) < 0 then lowest( d ) := p;
            powers( p, dPos ) := d;
            dPos              := dPos + 1
        end while_dPos_le_dMax ;
        if   carry = 0
        then digits( p ) := dMax
        else begin
            % the power p has one more digit than the previous              %
            digits( p )       := dPos;
            powers( p, dPos ) := carry;
            if lowest( carry ) < 0 then lowest( carry ) := p;
        end if_carry_eq_0__ ;
        % find the two digit numbers                                        %
        for n := 10 until 21 do begin
            if lowest( n ) < 0 then begin
                integer h, l;
                h := n div 10;
                l := n rem 10;
                for d := digits( p ) - 1 step -1 until 1 do begin
                    if powers( p, d ) = l and powers( p, d + 1 ) = h then lowest( n ) := p
                end for_d
            end if_lowest_n_lt_0
        end for_n
    end for_p ;
    % show the lowest powers that contain the numbers 0..21                  %
    for n := 0 until 21 do begin
        integer p;
        p := lowest( n );
        write( i_w := 2, s_w := 0, n, " in 6^", p, ": " );
        for d := digits( p ) step -1 until 1 do writeon( i_w := 1, s_w := 0, powers( p, d ) )
    end for_n
end.
Output:
 0 in 6^ 9: 10077696
 1 in 6^ 0: 1
 2 in 6^ 3: 216
 3 in 6^ 2: 36
 4 in 6^ 6: 46656
 5 in 6^ 6: 46656
 6 in 6^ 1: 6
 7 in 6^ 5: 7776
 8 in 6^12: 2176782336
 9 in 6^ 4: 1296
10 in 6^ 9: 10077696
11 in 6^16: 2821109907456
12 in 6^ 4: 1296
13 in 6^13: 13060694016
14 in 6^28: 6140942214464815497216
15 in 6^18: 101559956668416
16 in 6^ 3: 216
17 in 6^10: 60466176
18 in 6^15: 470184984576
19 in 6^21: 21936950640377856
20 in 6^26: 170581728179578208256
21 in 6^ 3: 216

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]
]
Output:
 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

AWK

# syntax: GAWK -f SMALLEST_POWER_OF_6_WHOSE_DECIMAL_EXPANSION_CONTAINS_N.AWK
BEGIN {
    printf(" n power %30s\n","smallest power of 6")
    for (n=0; n<22; n++) {
      p = 1
      power = 0
      while (p !~ n) {
        p *= 6
        power++
      }
      printf("%2d %5d %'30d\n",n,power,p)
    }
    exit(0)
}
Output:
 n power            smallest power of 6
 0     9                     10,077,696
 1     0                              1
 2     3                            216
 3     2                             36
 4     6                         46,656
 5     6                         46,656
 6     1                              6
 7     5                          7,776
 8    12                  2,176,782,336
 9     4                          1,296
10     9                     10,077,696
11    16              2,821,109,907,456
12     4                          1,296
13    13                 13,060,694,016
14    28  6,140,942,214,464,815,497,216
15    18            101,559,956,668,416
16     3                            216
17    10                     60,466,176
18    15                470,184,984,576
19    21         21,936,950,640,377,856
20    26    170,581,728,179,578,208,256
21     3                            216

C

#include <stdio.h>
#include <string.h>
#include <gmp.h>

char *power_of_six(unsigned int n, char *buf) {
    mpz_t p;
    mpz_init(p);
    mpz_ui_pow_ui(p, 6, n);
    mpz_get_str(buf, 10, p);
    mpz_clear(p);
    return buf;
}

char *smallest_six(unsigned int n) {
    static char nbuf[32], powbuf[1024];
    unsigned int p = 0;
    
    do {
        sprintf(nbuf, "%u", n);
        power_of_six(p++, powbuf);
    } while (!strstr(powbuf, nbuf));
    
    return powbuf;
}

int main() {
    unsigned int i;
    
    for (i=0; i<22; i++) {
        printf("%d: %s\n", i, smallest_six(i));
    }
    
    return 0;
}
Output:
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

C++

#include <iostream>
#include <iomanip>
#include <string>
#include <gmpxx.h>

std::string smallest_six(unsigned int n) {
    mpz_class pow = 1;
    std::string goal = std::to_string(n);
    
    while (pow.get_str().find(goal) == std::string::npos) {
        pow *= 6;
    }
    
    return pow.get_str();
}

int main() {
    for (unsigned int i=0; i<22; i++) {
        std::cout << std::setw(2) << i << ": " 
                  << smallest_six(i) << std::endl;
    }
    return 0;
}
Output:
 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

CLU

% This program uses the bigint type that comes with PCLU.
% It is in "misc.lib"
%
% pclu -merge $CLUHOME/lib/misc.lib -compile n6_contains_6.clu

smallest_power_6 = proc (n: int) returns (int, bigint)
    n_str: string := int$unparse(n)
    six_power: bigint := bigint$i2bi(1)
    six: bigint := bigint$i2bi(6)
    n_power: int := 0
    
    while true do
        pow_str: string := bigint$unparse(six_power)
        if string$indexs(n_str, pow_str) ~= 0 then 
            return(n_power, six_power)
        end
        six_power := six_power * six
        n_power := n_power + 1
    end
end smallest_power_6

start_up = proc ()
    po: stream := stream$primary_output()
    
    for n: int in int$from_to(0, 21) do
        p: int  val: bigint
        stream$putright(po, int$unparse(n), 2)
        stream$puts(po, ": 6^")
        p, val := smallest_power_6(n)
        stream$putleft(po, int$unparse(p), 2)
        stream$puts(po, " = ")
        stream$putright(po, bigint$unparse(val), 30)
        stream$putl(po, "")
    end
end start_up
Output:
 0: 6^9  =                       10077696
 1: 6^0  =                              1
 2: 6^3  =                            216
 3: 6^2  =                             36
 4: 6^6  =                          46656
 5: 6^6  =                          46656
 6: 6^1  =                              6
 7: 6^5  =                           7776
 8: 6^12 =                     2176782336
 9: 6^4  =                           1296
10: 6^9  =                       10077696
11: 6^16 =                  2821109907456
12: 6^4  =                           1296
13: 6^13 =                    13060694016
14: 6^28 =         6140942214464815497216
15: 6^18 =                101559956668416
16: 6^3  =                            216
17: 6^10 =                       60466176
18: 6^15 =                   470184984576
19: 6^21 =              21936950640377856
20: 6^26 =          170581728179578208256
21: 6^3  =                            216

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))
Output:
 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
23 2176782336
24 1023490369077469249536
25 170581728179578208256
26 16926659444736
27 279936
28 2821109907456
29 1296
30 13060694016
31 131621703842267136
32 4738381338321616896
33 2176782336
34 1023490369077469249536
35 609359740010496
36 36
37 21936950640377856
38 131621703842267136
39 221073919720733357899776
40 13060694016
41 78364164096
42 131621703842267136
43 28430288029929701376
44 16926659444736
45 470184984576
46 46656
47 470184984576
48 6140942214464815497216
49 470184984576
50 21936950640377856
51 1326443518324400147398656
52 623673825204293256669089197883129856
53 789730223053602816
54 6140942214464815497216
55 101559956668416
56 46656
57 470184984576
58 3656158440062976
59 16926659444736
60 60466176
61 1679616
62 362797056
63 47751966659678405306351616
64 78364164096
65 46656
66 46656
67 1679616
68 101559956668416
69 10077696
70 362797056
71 131621703842267136
72 170581728179578208256
73 16926659444736
74 2821109907456
75 47751966659678405306351616
76 7776
77 7776
78 2176782336
79 279936
80 28430288029929701376
81 789730223053602816
82 2176782336
83 78364164096
84 470184984576
85 21936950640377856
86 36845653286788892983296
87 61886548790943213277031694336
88 28430288029929701376
89 789730223053602816
90 2821109907456
91 221073919720733357899776
92 16926659444736
93 279936
94 13060694016
95 101559956668416
96 1296
97 362797056
98 470184984576
99 279936
Real: 00:00:00.066

Factor

Works with: Factor version 0.99 2021-02-05
USING: formatting kernel lists lists.lazy math math.functions
present sequences tools.memory.private ;

: powers-of-6 ( -- list )
    0 lfrom [ 6 swap ^ ] lmap-lazy ;

: smallest ( m -- n )
    present powers-of-6 [ present subseq? ] with lfilter car ;

22 [ dup smallest commas "%2d   %s\n" printf ] each-integer
Output:
 0   10,077,696
 1   1
 2   216
 3   36
 4   46,656
 5   46,656
 6   6
 7   7,776
 8   2,176,782,336
 9   1,296
10   10,077,696
11   2,821,109,907,456
12   1,296
13   13,060,694,016
14   6,140,942,214,464,815,497,216
15   101,559,956,668,416
16   216
17   60,466,176
18   470,184,984,576
19   21,936,950,640,377,856
20   170,581,728,179,578,208,256
21   216


FreeBASIC

Translation of: Ring
Print !"\ntrabajando...\n"
Print !"M¡nima potencia de 6 cuya expansi¢n decimal contiene n:\n"

Dim As Uinteger num = 0, limit = 200, m

For n As Ubyte = 0 To 21
    Dim As String strn = Str(n)
    For m = 0 To limit
        Dim As String strpow = Str(6 ^ m)
        Dim As Ulong ind = Instr(strpow,strn)
        If ind > 0 Then
            Print Using "##. 6^\\ = &"; n; Str(m); strpow
            Exit For
        End If
    Next m
Next n

Print !"\n--- terminado, pulsa RETURN---"
Sleep


Go

Translation of: Wren
package main

import (
    "fmt"
    "math/big"
    "strconv"
    "strings"
)

// Adds thousand separators to an integral string.
func commatize(s string) string {
    neg := false
    if strings.HasPrefix(s, "-") {
        s = s[1:]
        neg = true
    }
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    if !neg {
        return s
    }
    return "-" + s
}

func main() {
    fmt.Println(" n  smallest power of 6 which contains n")
    six := big.NewInt(6)
    for n := 0; n <= 21; n++ {
        ns := strconv.Itoa(n)
        i := int64(0)
        for {
            bi := big.NewInt(i)
            pow6 := bi.Exp(six, bi, nil).String()
            if strings.Contains(pow6, ns) {
                fmt.Printf("%2d  6^%-2d = %s\n", n, i, commatize(pow6))
                break
            }
            i++
        }
    }
}
Output:
 n  smallest power of 6 which contains n
 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

Haskell

import Data.List (find, isInfixOf)
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
Output:
 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

jq

Works with gojq, the Go implementation of jq

gojq provides unbounded-precision integer arithmetic and is therefore appropriate for this task.

# To preserve precision:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);

range(0;22)
| . as $in
| tostring as $n 
| first(range(0;infinite) as $i | 6 | power($i) | . as $p | tostring | (index($n) // empty) 
        | [$in,$i,$p] )
Output:
[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]


Julia

using Formatting

digcontains(n, dig) = contains(String(Char.(digits(n))), String(Char.(dig)))

function findpow6containing(needle)
    dig = digits(needle)
    for i in 0:1000
        p = big"6"^i
        digcontains(p, dig) && return p
    end
    error("could not find a  power of 6 containing $dig")
end

for n in 0:21
    println(rpad(n, 5), format(findpow6containing(n), commas=true))
end
Output:
0    10,077,696
1    1
2    216
3    36
4    46,656
5    46,656
6    6
7    7,776
8    2,176,782,336
9    1,296
10   10,077,696
11   2,821,109,907,456
12   1,296
13   13,060,694,016
14   6,140,942,214,464,815,497,216
15   101,559,956,668,416
16   216
17   60,466,176
18   470,184,984,576
19   21,936,950,640,377,856
20   170,581,728,179,578,208,256
21   216

Mathematica/Wolfram Language

ClearAll[SmallestPowerContainingN]
SmallestPowerContainingN[n_Integer] := Module[{i = 1, test},
  While[True,
   test = 6^i;
   If[SequenceCount[IntegerDigits[test], IntegerDigits[n]] > 0, 
    Return[{n, i, test}]];
   i++;
   ]
  ]
Grid[SmallestPowerContainingN /@ Range[0, 21]]
Output:
0	9	10077696
1	3	216
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

Nim

Library: bignum
import strformat, strutils
import bignum

var toFind = {0..21}
var results: array[0..21, (int, string)]
var p = newInt(1)
var k = 0
while toFind.card > 0:
  let str = $p
  for n in toFind:
    if str.find($n) >= 0:
      results[n] = (k, str)
      toFind.excl(n)
  p *= 6
  inc k

echo "Smallest values of k such that 6^k contains n:"
for n, (k, s) in results:
  echo &"{n:2}:  6^{k:<2} = {s}"
Output:
Smallest values of k such that 6^k contains n:
 0:  6^9  = 10077696
 1:  6^0  = 1
 2:  6^3  = 216
 3:  6^2  = 36
 4:  6^6  = 46656
 5:  6^6  = 46656
 6:  6^1  = 6
 7:  6^5  = 7776
 8:  6^12 = 2176782336
 9:  6^4  = 1296
10:  6^9  = 10077696
11:  6^16 = 2821109907456
12:  6^4  = 1296
13:  6^13 = 13060694016
14:  6^28 = 6140942214464815497216
15:  6^18 = 101559956668416
16:  6^3  = 216
17:  6^10 = 60466176
18:  6^15 = 470184984576
19:  6^21 = 21936950640377856
20:  6^26 = 170581728179578208256
21:  6^3  = 216

Pascal

Free Pascal

Doing long multiplikation like in primorial task.
I used to check every numberstring one after the other on one 6^ n string.Gets really slow on high n
After a closer look into Smallest_power_of_6_whose_decimal_expansion_contains_n#Phix I applied a slghtly modified version of Pete.

program PotOf6;
//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}

uses
  sysutils;
const
  //decimal places used by multiplication and for string  conversion
  calcDigits = 8;
  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;
  tMul = array of tMulElem;
  tpMul = pUint32;
  tPotArrN = array[0..1] of tMul;

  tFound = record
             foundIndex,
             foundStrIdx : Uint32;
           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 Init_StrDec4Dgts;
var
  s : string[4];
  i : integer;
  a,b,c,d : char;
begin
  i := 0;
  s := '0000';
  For a := '0' to '9' do
  Begin
    s[1] := a;
    For b := '0' to '9' do
    begin
      s[2]:=b;
      For c := '0' to '9' do
      begin
        s[3] := c;
        For d := '0' to '9' do
        begin
          s[4] := d;
          StrDec4Dgts[i]:= s;
          inc(i);
        end;
      end;
    end;
  end;
end;

function Commatize(const s: AnsiString):AnsiString;
var
   fromIdx,toIdx :Int32;
Begin
  result := '';
  fromIdx := length(s);
  toIdx := fromIdx-1;
  if toIdx < 3 then
  Begin
    result := s;
    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];
    result[toIdx-3] := ',';
    dec(toIdx,4);
    dec(FromIdx,3);
  until FromIdx<=3;
  while fromIdx>=1 do
  Begin
    result[toIdx] := s[FromIdx];
    dec(toIdx);
    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
  s8: string[calcDigits];
  pS : pChar;
  j,k,d,m : NativeInt;
begin
  j := (i+1)*calcDigits;
  setlength(s,j+1);
  pS := @s[1];
  m := Mul[i];
  str(Mul[i],s8);
  j := length(s8);
  move(s8[1],pS[0],j);
  k := j;
  dec(i);
  If i >= 0 then
    repeat
      m := MUL[i];
      d := m div 10000;
      m := m-10000*d;
      move(StrDec4Dgts[d][1],pS[k],4);
      move(StrDec4Dgts[m][1],pS[k+4],4);
      inc(k,calcDigits);
      dec(i);
    until i<0;
  setlength(s,k);
end;

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;
  oneFound : boolean;
begin
  pChecked := @CheckedNum[0];
  result := 0;
  oneFound := false;
  lmt := length(s);
  For i := 1 to lmt do
  Begin
    k := i;
    num := 0;
    repeat
      num := num*10+ Ord(s[k])-Ord('0');
      IF (num >= FirstMissing) AND Not(pChecked[num]) then
      begin
        //memorize that string commatized
        if NOT(oneFound) then
        Begin
          oneFound := true;
          FoundString[FoundIDX] := Commatize(s);
          FoundIDX  += 1;
        end;
        pChecked[num]:= true;
        with str_Found[num] do
        Begin
          foundIndex:= pow+1;
          foundStrIdx:= FoundIDX-1;
        end;
        inc(result);
        if num =FirstMissing then
          repeat
            inc(FirstMissing)
          until str_Found[FirstMissing].foundIndex =0;
      end;
      inc(k)
    until (k>lmt) or (k-i >DIGITS-1);
  end;
end;

var
  i,j,k,toggle,MaxMulIdx,found: Int32;
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);
    i := CheckOneString(Pot_N_str,j);
    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.
@TIO.RUN:
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 %

Perl

use strict;
use warnings;
use List::Util 'first';
use Math::AnyNum ':overload';

sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }

for my $n (0..21, 314159) {
    my $e = first { 6**$_ =~ /$n/ } 0..1000;
    printf "%7d:  6^%-3s  %s\n", $n, $e, comma 6**$e;
}
Output:
      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
 314159:  6^494  2,551,042,473,957,557,281,758,472,595,966,885,638,262,058,644,568,332,160,010,313,393,465,384,231,415,969,801,503,269,402,221,368,959,426,761,447,049,526,922,498,341,120,174,041,236,629,812,681,424,262,988,020,546,286,492,213,224,906,594,147,652,459,693,833,191,626,748,973,370,777,591,205,509,673,825,541,899,874,436,305,798,094,943,728,762,682,333,192,202,041,960,669,401,031,964,634,164,426,985,990,195,192,836,400,994,016,666,910,919,499,884,972,133,471,176,804,190,463,444,807,178,864,658,551,422,631,018,496

Phix

Another good opportunity to do some string math, this time with embedded commas. Scales effortlessly.
(Related recent task: Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#Phix)

constant lim = 22           -- (tested to 10,000,000)
atom t0 = time(), t1 = t0+1
sequence res = repeat(0,lim),
         pwr = repeat(0,lim)
string p6 = "1"
res[2] = p6
integer found = 1, p = 0
while found<lim do
    integer carry = 0
    for i=length(p6) to 1 by -1 do
        if p6[i]!=',' then
            integer digit = (p6[i]-'0')*6+carry
            p6[i] = remainder(digit,10)+'0'
            carry = floor(digit/10)
        end if
    end for
    if carry then
        if remainder(length(p6)+1,4)=0 then
            p6 = "," & p6
        end if
        p6 = carry+'0' & p6
    end if
    p += 1
    for i=1 to length(p6) do
        if p6[i]!=',' then
            integer digit = 0, j = i
            while j<=length(p6) and digit<=lim do
                j += p6[j]=','
                digit = digit*10+p6[j]-'0'
                if digit<lim and res[digit+1]=0 then
                    res[digit+1] = p6
                    pwr[digit+1] = p
                    found += 1
                end if
                j += 1
            end while
        end if
    end for
    if time()>t1 then
        progress("found %,d/%,d, at 6^%,d which has %,d digits (%s)",
                 {found,lim,p,length(p6)*3/4,elapsed(time()-t0)})
        t1 = time()+1
    end if
end while
papply(true,printf,{1,{"%2d  %29s = 6^%d\n"},shorten(columnize({tagset(lim-1,0),res,pwr}),"",10)})
Output:
 0                     10,077,696 = 6^9
 1                              1 = 6^0
 2                            216 = 6^3
 3                             36 = 6^2
 4                         46,656 = 6^6
 5                         46,656 = 6^6
 6                              6 = 6^1
 7                          7,776 = 6^5
 8                  2,176,782,336 = 6^12
 9                          1,296 = 6^4
10                     10,077,696 = 6^9
11              2,821,109,907,456 = 6^16
12                          1,296 = 6^4
13                 13,060,694,016 = 6^13
14  6,140,942,214,464,815,497,216 = 6^28
15            101,559,956,668,416 = 6^18
16                            216 = 6^3
17                     60,466,176 = 6^10
18                470,184,984,576 = 6^15
19         21,936,950,640,377,856 = 6^21
20    170,581,728,179,578,208,256 = 6^26
21                            216 = 6^3

A limit of 10,000,000 takes 1 min 41s, reaches 6^21,798 which has 16,963 digits (not including commas) and is the first to contain 8091358, at offset 13,569.

Python

def smallest_six(n):
    p = 1
    while str(n) not in str(p): p *= 6
    return p
    
for n in range(22):
    print("{:2}: {}".format(n, smallest_six(n)))
Output:
 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

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
Output:
 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.

Raku

use Lingua::EN::Numbers;

my @po6 = ^Inf .map: *.exp: 6;

put join "\n", (flat ^22, 120).map: -> $n {
    sprintf "%3d: 6%-4s %s", $n, .&super, comma @po6[$_]
    given @po6.first: *.contains($n), :k
};
Output:
  0: 6⁹    10,077,696
  1: 6⁰    1
  2: 6³    216
  3: 6²    36
  4: 6⁶    46,656
  5: 6⁶    46,656
  6: 6¹    6
  7: 6⁵    7,776
  8: 6¹²   2,176,782,336
  9: 6⁴    1,296
 10: 6⁹    10,077,696
 11: 6¹⁶   2,821,109,907,456
 12: 6⁴    1,296
 13: 6¹³   13,060,694,016
 14: 6²⁸   6,140,942,214,464,815,497,216
 15: 6¹⁸   101,559,956,668,416
 16: 6³    216
 17: 6¹⁰   60,466,176
 18: 6¹⁵   470,184,984,576
 19: 6²¹   21,936,950,640,377,856
 20: 6²⁶   170,581,728,179,578,208,256
 21: 6³    216
120: 6¹⁴⁷  2,444,746,349,972,956,194,083,608,044,935,243,159,422,957,210,683,702,349,648,543,934,214,737,968,217,920,868,940,091,707,112,078,529,114,392,164,827,136

REXX

/*REXX pgm finds the smallest (decimal) power of  6  which contains  N,  where  N < 22. */
numeric digits 100                               /*ensure enough decimal digs for  6**N */
parse arg hi .                                   /*obtain optional argument from the CL.*/
if hi=='' | hi==","  then hi= 22                 /*Not specified?  Then use the default.*/
w= 50                                            /*width of a number in any column.     */
               @smp6= ' smallest power of  six  (expressed in decimal)  which contains  N'
say '  N  │ power │'center(@smp6, 20 + w     )   /*display the   title   of the output. */
say '─────┼───────┼'center(""   , 20 + w, '─')   /*   "     "  separator  "  "     "    */

      do j=0  for hi                             /*look for a power of 6 that contains N*/
                     do p=0;   x= 6**p           /*compute a power of six (in decimal). */
                     if pos(j, x)>0  then leave  /*does the power contain an   N ?      */
                     end   /*p*/
      c= commas(x)                               /*maybe add commas to the powe of six. */
      z= right(c, max(w, length(c) ) )           /*show a power of six, allow biger #s. */
      say center(j, 5)'│'center(p, 7)"│"   z     /*display what we have so far  (cols). */
      end   /*j*/

say '─────┴───────┴'center(""   , 20 + w, '─')   /*   "     "  separator  "  "     "    */
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 ?
output   when using the default input:
  N  │ power │   smallest power of  six  (expressed in decimal)  which contains  N
─────┼───────┼──────────────────────────────────────────────────────────────────────
  0  │   9   │                                         10,077,696
  1  │   0   │                                                  1
  2  │   3   │                                                216
  3  │   2   │                                                 36
  4  │   6   │                                             46,656
  5  │   6   │                                             46,656
  6  │   1   │                                                  6
  7  │   5   │                                              7,776
  8  │  12   │                                      2,176,782,336
  9  │   4   │                                              1,296
 10  │   9   │                                         10,077,696
 11  │  16   │                                  2,821,109,907,456
 12  │   4   │                                              1,296
 13  │  13   │                                     13,060,694,016
 14  │  28   │                      6,140,942,214,464,815,497,216
 15  │  18   │                                101,559,956,668,416
 16  │   3   │                                                216
 17  │  10   │                                         60,466,176
 18  │  15   │                                    470,184,984,576
 19  │  21   │                             21,936,950,640,377,856
 20  │  26   │                        170,581,728,179,578,208,256
 21  │   3   │                                                216
─────┴───────┴──────────────────────────────────────────────────────────────────────

Ring

load "stdlib.ring"

decimals(0)
see "working..." + nl
see "Smallest power of 6 whose decimal expansion contains n:" + nl

num = 0
limit = 200

for n = 1 to 21
    strn = string(n)
    for m = 0 to limit
        strpow = string(pow(6,m))
        ind = substr(strpow,strn)
        if ind > 0
           see "" + n + ". " + "6^" + m + " = " + strpow + nl
           exit
        ok
    next
next

see "done..." + nl
Output:
working...
Smallest power of 6 whose decimal expansion contains n:
1. 6^0 = 1
2. 6^3 = 216
3. 6^2 = 36
4. 6^6 = 46656
5. 6^6 = 46656
6. 6^1 = 6
7. 6^5 = 7776
8. 6^12 = 2176782336
9. 6^4 = 1296
10. 6^9 = 10077696
11. 6^16 = 2821109907456
12. 6^4 = 1296
13. 6^13 = 13060694016
14. 6^28 = 6140942214464815497216
15. 6^18 = 101559956668416
16. 6^3 = 216
17. 6^10 = 60466176
18. 6^15 = 470184984576
19. 6^21 = 21936950640377856
20. 6^26 = 170581728179578208256
21. 6^3 = 216
done...

RPL

1980s RPL can only handle 64-bit unsigned integers, which means a multi-precision multiplication is here required.

Works with: Halcyon Calc version 4.2.7
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 
≫ ≫ 'MMULT' 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
≫ 'M→STR' STO

≪ 
   { # 1d } SWAP 
   WHILE DUP REPEAT 
     SWAP 6 MMULT SWAP 1 - END 
   DROP M→STR
≫ 'POW6' STO

≪ DEC { }
 0 21 FOR n 
    n →STR -1 
    DO 1 + DUP POW6  
    UNTIL 3 PICK POS END 
    POW6 ROT SWAP + SWAP DROP 
 NEXT 
≫ 'TASK' STO 
MMULT ( { #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


M→STR ( { #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



POW6 ( 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


Output:
1: { "10077696" "1" "216" "36" "46656" "46656" "6" "7776" "2176782336" "1296" "10077696" "2821109907456" "1296" "13060694016" "6140942214464815497216" "101559956668416" "216" "60466176" "470184984576" "21936950640377856" "170581728179578208256" "216" }

2000s RPL version

Big integers are native in this version.

Works with: HP version 49
≪ { } 
   0 21 FOR n
      0
      WHILE 6 OVER ^ →STR n →STR POS NOT
      REPEAT 1 + END
      "'6^" SWAP + STR→ +
   NEXT
≫ 'TASK' STO 
Output:
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 }

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) }
Output:
  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

Wren

Library: Wren-big
Library: Wren-fmt
import "./big" for BigInt
import "./fmt" for Fmt

System.print(" n  smallest power of 6 which contains n")
var six = BigInt.new(6)
for (n in 0..21) {
    var i = 0
    while (true) {
        var pow6 = six.pow(i).toString
        if (pow6.contains(n.toString)) {
            Fmt.print("$2d  6^$-2d = $,s", n, i, pow6)
            break
        }
        i = i + 1
    }
}
Output:
 n  smallest power of 6 which contains n
 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

Yabasic

Translation of: Python
// 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
Output:
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---