Smallest numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Pascal}}: to much copy and paste...)
(add FreeBASIC)
Line 64: Line 64:
23
23
</pre>
</pre>

=={{header|FreeBASIC}}==
Reuses some code from [[Arbitrary-precision_integers_(included)#FreeBASIC]].
<lang freebasic>#Include once "gmp.bi"
Dim Shared As Zstring * 100000000 outtext
Function Power(number As String,n As Uinteger) As String'automate precision
#define dp 3321921
Dim As __mpf_struct _number,FloatAnswer
Dim As Ulongint ln=Len(number)*(n)*4
If ln>dp Then ln=dp
mpf_init2(@FloatAnswer,ln)
mpf_init2(@_number,ln)
mpf_set_str(@_number,number,10)
mpf_pow_ui(@Floatanswer,@_number,n)
gmp_sprintf( @outtext,"%." & Str(n) & "Ff",@FloatAnswer )
Var outtxt=Trim(outtext)
If Instr(outtxt,".") Then outtxt= Rtrim(outtxt,"0"):outtxt=Rtrim(outtxt,".")
Return Trim(outtxt)
End Function

function is_substring( s as string, j as string ) as boolean
dim as integer nj = len(j), ns = len(s)
for i as integer = 1 to ns - nj + 1
if mid(s,i,nj) = j then return true
next i
return false
end function

dim as integer k

for i as uinteger = 0 to 50
k = 0
do
k = k + 1
loop until is_substring( Power(str(k), k), str(i) )
print k;" ";
next i</lang>
{{out}}<pre> 9 1 3 5 2 4 4 3 7 9 10 11 5 19 22 26 8 17 16 19 9 8 13 7 17 4 17 3 11 18 13 5 23 17 18 7 17 15 9 18 16 17 9 7 12 28 6 23 9 24 23</pre>


=={{header|Julia}}==
=={{header|Julia}}==