Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
|||
200000 n#
|
||||
5 4 3 2 bfloat ^ ^ ^
|
||||
"%.0f" s:strfmt
|
||||
dup s:len . " digits" . cr
|
||||
dup 20 s:lsub . "..." . 20 s:rsub . cr
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
;; to save space and time, we do'nt stringify Ω = 5^4^3^2 ,
|
||||
;; but directly extract tail and head and number of decimal digits
|
||||
|
||||
(lib 'bigint) ;; arbitrary size integers
|
||||
|
||||
(define e10000 (expt 10 10000)) ;; 10^10000
|
||||
|
||||
(define (last-n big (n 20))
|
||||
(string-append "..." (number->string (modulo big (expt 10 n)))))
|
||||
|
||||
(define (first-n big (n 20))
|
||||
(while (> big e10000)
|
||||
(set! big (/ big e10000))) ;; cut 10000 digits at a time
|
||||
(string-append (take (number->string big) n) "..."))
|
||||
|
||||
;; faster than directly using (number-length big)
|
||||
(define (digits big (digits 0))
|
||||
(while (> big e10000)
|
||||
(set! big (/ big e10000))
|
||||
(set! digits (1+ digits)))
|
||||
(+ (* digits 10000) (number-length big)))
|
||||
|
||||
(define Ω (expt 5 (expt 4 (expt 3 2))))
|
||||
|
||||
(last-n Ω )
|
||||
→ "...92256259918212890625"
|
||||
(first-n Ω )
|
||||
→ "62060698786608744707..."
|
||||
(digits Ω )
|
||||
→ 183231
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#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
|
||||
|
||||
Extern gmp_version Alias "__gmp_version" As Zstring Ptr
|
||||
Print "GMP version ";*gmp_version
|
||||
Print
|
||||
|
||||
var ans=power("5",(4^(3^2)))
|
||||
Print Left(ans,20) + " ... "+Right(ans,20)
|
||||
Print "Number of digits ";Len(ans)
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
=+ big=(pow 5 (pow 4 (pow 3 2)))
|
||||
=+ digits=(lent (skip <big> |=(a/* ?:(=(a '.') & |))))
|
||||
[digits (div big (pow 10 (sub digits 20))) (mod big (pow 10 20))]
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
define integer->pow(factor::integer) => {
|
||||
#factor <= 0
|
||||
? return 0
|
||||
|
||||
local(retVal) = 1
|
||||
|
||||
loop(#factor) => { #retVal *= self }
|
||||
|
||||
return #retVal
|
||||
}
|
||||
|
||||
local(bigint) = string(5->pow(4->pow(3->pow(2))))
|
||||
#bigint->sub(1,20) + ` ... ` + #bigint->sub(#bigint->size - 19)
|
||||
"\n"
|
||||
`Number of digits: ` + #bigint->size
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import bigints
|
||||
|
||||
var x = 5.pow 4.pow 3.pow 2
|
||||
var s = $x
|
||||
|
||||
echo s[0..19]
|
||||
echo s[s.high - 19 .. s.high]
|
||||
echo s.len
|
||||
|
|
@ -0,0 +1 @@
|
|||
5 4 3 2 pow pow pow asString dup left(20) . dup right(20) . size .
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
include bigatom.e
|
||||
|
||||
bigatom res
|
||||
res = ba_power(3,2)
|
||||
res = ba_power(4,res)
|
||||
res = ba_power(5,res)
|
||||
|
||||
string s = ba_sprint(res)
|
||||
?length(s)
|
||||
?s[1..20]
|
||||
?s[-20..-1]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var x = 5**(4**(3**2));
|
||||
var y = x.to_s;
|
||||
printf("5**4**3**2 = %s...%s and has %i digits\n", y.ft(0,19), y.ft(-20), y.len);
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import "unbounded_int"
|
||||
decl unbounded_int x
|
||||
x.set ((x.valueof 5).pow ((x.valueof 4).pow ((x.valueof 3).pow 2)))
|
||||
|
||||
decl string first last xstr
|
||||
set xstr (string x)
|
||||
|
||||
# get the first twenty digits
|
||||
decl int i
|
||||
for (set i 0) (< i 20) (inc i)
|
||||
set first (+ first xstr<i>)
|
||||
end for
|
||||
|
||||
# get the last twenty digits
|
||||
for (set i (- (size xstr) 20)) (< i (size xstr)) (inc i)
|
||||
set last (+ last xstr<i>)
|
||||
end for
|
||||
|
||||
out "the first and last digits of 5^(4^(3^2)) are " first "..." console
|
||||
out last " (the result was " (size xstr) " digits long)" endl endl console
|
||||
|
||||
if (and (and (= first "62060698786608744707") (= last "92256259918212890625")) (= (size xstr) 183231))
|
||||
out "(pass)" endl console
|
||||
else
|
||||
out "FAIL" endl console
|
||||
end if
|
||||
Loading…
Add table
Add a link
Reference in a new issue