September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,59 +1,51 @@
|
|||
cls
|
||||
|
||||
n =1000
|
||||
len = 10*n \ 4
|
||||
needdecimal = true
|
||||
dim a(len)
|
||||
nines = 0
|
||||
predigit = 0 # {First predigit is a 0}
|
||||
|
||||
for j = 1 to len
|
||||
a[j-1] = 2 # {Start with 2s}
|
||||
next j
|
||||
|
||||
for j = 1 to n
|
||||
q = 0
|
||||
for i = len to 1 step -1
|
||||
# {Work backwards}
|
||||
x = 10*a[i-1] + q*i
|
||||
a[i-1] = x % (2*i - 1)
|
||||
q = x \ (2*i - 1)
|
||||
next i
|
||||
a[0] = q % 10
|
||||
q = q \ 10
|
||||
if q = 9 then
|
||||
nines = nines + 1
|
||||
else
|
||||
if q = 10 then
|
||||
d = predigit+1: gosub outputd
|
||||
if nines > 0 then
|
||||
for k = 1 to nines
|
||||
d = 0: gosub outputd
|
||||
next k
|
||||
end if
|
||||
predigit = 0
|
||||
nines = 0
|
||||
else
|
||||
d = predigit: gosub outputd
|
||||
predigit = q
|
||||
if nines <> 0 then
|
||||
for k = 1 to nines
|
||||
d = 9: gosub outputd
|
||||
next k
|
||||
nines = 0
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
next j
|
||||
print predigit
|
||||
end
|
||||
|
||||
outputd:
|
||||
if needdecimal then
|
||||
if d = 0 then return
|
||||
print d + ".";
|
||||
needdecimal = false
|
||||
else
|
||||
print d;
|
||||
end if
|
||||
return
|
||||
10 rem adopted from Commodore BASIC
|
||||
20 n = 100 : rem N may be increased, but will slow execution
|
||||
30 ln = int(10*n/4)
|
||||
40 nd = 1
|
||||
50 dim a(ln)
|
||||
60 n9 = 0
|
||||
70 pd = 0 :rem First pre-digit is a 0
|
||||
80 rem
|
||||
90 for j = 1 to ln
|
||||
100 a(j-1) = 2 :rem Start with 2s
|
||||
110 next j
|
||||
120 rem
|
||||
130 for j = 1 to n
|
||||
140 q = 0
|
||||
150 for i = ln to 1 step -1 :rem Work backwards
|
||||
160 x = 10*a(i-1) + q*i
|
||||
170 a(i-1) = x - (2*i-1)*int(x/(2*i-1)) :rem X - INT ( X / Y) * Y
|
||||
180 q = int(x/(2*i - 1))
|
||||
190 next i
|
||||
200 a(0) = q-10*int(q/10)
|
||||
210 q = int(q/10)
|
||||
220 if q=9 then n9 = n9 + 1 : goto 450
|
||||
240 if q<>10 then goto 350
|
||||
250 rem q == 10
|
||||
260 d = pd+1 : gosub 500
|
||||
270 if n9 < 0 then goto 320
|
||||
280 for k = 1 to n9
|
||||
290 d = 0: gosub 500
|
||||
300 next k
|
||||
310 rem end if
|
||||
320 pd = 0
|
||||
330 n9 = 0
|
||||
335 goto 450
|
||||
340 rem q <> 10
|
||||
350 d = pd: gosub 500
|
||||
360 pd = q
|
||||
370 if n9 = 0 then goto 450
|
||||
380 for k = 1 to n9
|
||||
390 d = 9 : gosub 500
|
||||
400 next k
|
||||
410 n9 = 0
|
||||
450 next j
|
||||
460 print str$(pd)
|
||||
470 end
|
||||
480 rem
|
||||
490 rem output digits
|
||||
500 if nd=0 then print str$(d); : return
|
||||
510 if d=0 then return
|
||||
520 print str$(d);".";
|
||||
530 nd = 0
|
||||
550 return
|
||||
|
|
|
|||
|
|
@ -1,51 +1,59 @@
|
|||
10 PRINT CHR$(147)
|
||||
20 n = 100
|
||||
30 ln = int(10*n/4)
|
||||
40 nd = 1
|
||||
50 dim a(ln)
|
||||
60 n9 = 0
|
||||
70 pd = 0 :rem First predigit is a 0
|
||||
80 :
|
||||
90 for j = 1 to ln
|
||||
100 a(j-1) = 2 :rem Start with 2s
|
||||
110 next j
|
||||
120 :
|
||||
130 for j = 1 to n
|
||||
140 q = 0
|
||||
150 for i = ln to 1 step -1 :rem Work backwards
|
||||
160 x = 10*a(i-1) + q*i
|
||||
170 a(i-1) = x - (2*i-1)*int(x/(2*i-1)) :rem X - INT ( X / Y) * Y
|
||||
180 q = int(x/(2*i - 1))
|
||||
190 next i
|
||||
200 a(0) = q-10*int(q/10)
|
||||
210 q = int(q/10)
|
||||
220 if q=9 then n9 = n9 + 1 : goto 450
|
||||
240 if q<>10 then 350
|
||||
250 rem q == 10
|
||||
260 d = pd+1 : gosub 500
|
||||
270 if n9 < 0 then 320
|
||||
280 for k = 1 to n9
|
||||
290 d = 0: gosub 500
|
||||
300 next k
|
||||
310 rem end if
|
||||
320 pd = 0
|
||||
330 n9 = 0
|
||||
335 goto 450
|
||||
340 rem q <> 10
|
||||
350 d = pd: gosub 500
|
||||
360 pd = q
|
||||
370 if n9 = 0 then 450
|
||||
380 for k = 1 to n9
|
||||
390 d = 9 : gosub 500
|
||||
400 next k
|
||||
410 n9 = 0
|
||||
450 next j
|
||||
460 print mid$(str$(pd),2,1)
|
||||
470 end
|
||||
480 :
|
||||
490 rem outputd
|
||||
500 if nd=0 then print mid$(str$(d),2,1); : return
|
||||
510 if d=0 then return
|
||||
520 print mid$(str$(d),2,1);".";
|
||||
530 nd = 0
|
||||
550 return
|
||||
cls
|
||||
|
||||
n =1000
|
||||
len = 10*n \ 4
|
||||
needdecimal = true
|
||||
dim a(len)
|
||||
nines = 0
|
||||
predigit = 0 # {First predigit is a 0}
|
||||
|
||||
for j = 1 to len
|
||||
a[j-1] = 2 # {Start with 2s}
|
||||
next j
|
||||
|
||||
for j = 1 to n
|
||||
q = 0
|
||||
for i = len to 1 step -1
|
||||
# {Work backwards}
|
||||
x = 10*a[i-1] + q*i
|
||||
a[i-1] = x % (2*i - 1)
|
||||
q = x \ (2*i - 1)
|
||||
next i
|
||||
a[0] = q % 10
|
||||
q = q \ 10
|
||||
if q = 9 then
|
||||
nines = nines + 1
|
||||
else
|
||||
if q = 10 then
|
||||
d = predigit+1: gosub outputd
|
||||
if nines > 0 then
|
||||
for k = 1 to nines
|
||||
d = 0: gosub outputd
|
||||
next k
|
||||
end if
|
||||
predigit = 0
|
||||
nines = 0
|
||||
else
|
||||
d = predigit: gosub outputd
|
||||
predigit = q
|
||||
if nines <> 0 then
|
||||
for k = 1 to nines
|
||||
d = 9: gosub outputd
|
||||
next k
|
||||
nines = 0
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
next j
|
||||
print predigit
|
||||
end
|
||||
|
||||
outputd:
|
||||
if needdecimal then
|
||||
if d = 0 then return
|
||||
print d + ".";
|
||||
needdecimal = false
|
||||
else
|
||||
print d;
|
||||
end if
|
||||
return
|
||||
|
|
|
|||
51
Task/Pi/BASIC/pi-3.basic
Normal file
51
Task/Pi/BASIC/pi-3.basic
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
10 PRINT CHR$(147)
|
||||
20 n = 100
|
||||
30 ln = int(10*n/4)
|
||||
40 nd = 1
|
||||
50 dim a(ln)
|
||||
60 n9 = 0
|
||||
70 pd = 0 :rem First predigit is a 0
|
||||
80 :
|
||||
90 for j = 1 to ln
|
||||
100 a(j-1) = 2 :rem Start with 2s
|
||||
110 next j
|
||||
120 :
|
||||
130 for j = 1 to n
|
||||
140 q = 0
|
||||
150 for i = ln to 1 step -1 :rem Work backwards
|
||||
160 x = 10*a(i-1) + q*i
|
||||
170 a(i-1) = x - (2*i-1)*int(x/(2*i-1)) :rem X - INT ( X / Y) * Y
|
||||
180 q = int(x/(2*i - 1))
|
||||
190 next i
|
||||
200 a(0) = q-10*int(q/10)
|
||||
210 q = int(q/10)
|
||||
220 if q=9 then n9 = n9 + 1 : goto 450
|
||||
240 if q<>10 then 350
|
||||
250 rem q == 10
|
||||
260 d = pd+1 : gosub 500
|
||||
270 if n9 < 0 then 320
|
||||
280 for k = 1 to n9
|
||||
290 d = 0: gosub 500
|
||||
300 next k
|
||||
310 rem end if
|
||||
320 pd = 0
|
||||
330 n9 = 0
|
||||
335 goto 450
|
||||
340 rem q <> 10
|
||||
350 d = pd: gosub 500
|
||||
360 pd = q
|
||||
370 if n9 = 0 then 450
|
||||
380 for k = 1 to n9
|
||||
390 d = 9 : gosub 500
|
||||
400 next k
|
||||
410 n9 = 0
|
||||
450 next j
|
||||
460 print mid$(str$(pd),2,1)
|
||||
470 end
|
||||
480 :
|
||||
490 rem outputd
|
||||
500 if nd=0 then print mid$(str$(d),2,1); : return
|
||||
510 if d=0 then return
|
||||
520 print mid$(str$(d),2,1);".";
|
||||
530 nd = 0
|
||||
550 return
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require "big_int"
|
||||
require "big"
|
||||
|
||||
def pi
|
||||
q, r, t, k, n, l = [1, 0, 1, 1, 3, 3].map { |n| BigInt.new(n) }
|
||||
|
|
|
|||
21
Task/Pi/Factor/pi.factor
Normal file
21
Task/Pi/Factor/pi.factor
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
USING: combinators.extras io kernel locals math prettyprint ;
|
||||
IN: rosetta-code.pi
|
||||
|
||||
:: calc-pi-digits ( -- )
|
||||
1 0 1 1 3 3 :> ( q! r! t! k! n! l! ) [
|
||||
4 q * r + t - n t * < [
|
||||
n pprint flush
|
||||
r n t * - 10 *
|
||||
3 q * r + 10 * t /i n 10 * - n! r!
|
||||
q 10 * q!
|
||||
] [
|
||||
2 q * r + l *
|
||||
7 k * q * 2 + r l * + t l * /i n! r!
|
||||
k q * q!
|
||||
t l * t!
|
||||
l 2 + l!
|
||||
k 1 + k!
|
||||
] if
|
||||
] forever ;
|
||||
|
||||
MAIN: calc-pi-digits
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
prec = precision(BigFloat)
|
||||
spi = ""
|
||||
digit = 1
|
||||
while true
|
||||
if digit > length(spi) - 6
|
||||
prec *= 2
|
||||
setprecision(prec)
|
||||
spi = string(big(π))
|
||||
end
|
||||
print(spi[digit])
|
||||
digit += 1
|
||||
let prec = precision(BigFloat), spi = "", digit = 1
|
||||
while true
|
||||
if digit > lastindex(spi)
|
||||
prec *= 2
|
||||
setprecision(prec)
|
||||
spi = string(big(π))
|
||||
end
|
||||
print(spi[digit])
|
||||
digit += 1
|
||||
end
|
||||
end
|
||||
|
|
|
|||
24
Task/Pi/Ol/pi.ol
Normal file
24
Task/Pi/Ol/pi.ol
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
; 'numbers' is count of numbers or #false for eternal pleasure.
|
||||
(define (pi numbers)
|
||||
(let loop ((q 1) (r 0) (t 1) (k 1) (n 3) (l 3) (numbers numbers))
|
||||
(unless (eq? numbers 0)
|
||||
(if (< (- (+ (* 4 q) r) t) (* n t))
|
||||
(begin
|
||||
(display n)
|
||||
(loop (* q 10)
|
||||
(* 10 (- r (* n t)))
|
||||
t
|
||||
k
|
||||
(- (div (* 10 (+ (* 3 q) r)) t) (* 10 n))
|
||||
l
|
||||
(if numbers (- numbers 1))))
|
||||
(begin
|
||||
(loop (* q k)
|
||||
(* (+ (* 2 q) r) l)
|
||||
(* t l)
|
||||
(+ k 1)
|
||||
(div (+ (* q (* 7 k)) 2 (* r l)) (* t l))
|
||||
(+ l 2)
|
||||
(if numbers (- numbers 1))))))))
|
||||
|
||||
(pi #false)
|
||||
|
|
@ -4,7 +4,7 @@ sub stream(&next, &safe, &prod, &cons, $z is copy, @x) {
|
|||
gather loop {
|
||||
$z = safe($z, my $y = next($z)) ??
|
||||
prod($z, take $y) !!
|
||||
cons($z, @x[(state $)++])
|
||||
cons($z, @x[$++])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
3
Task/Pi/Phix/pi-1.phix
Normal file
3
Task/Pi/Phix/pi-1.phix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
integer a=10000,b,c=8400,d,e=0,g sequence f=repeat(floor(a/5),c+1) while c>0 do g=2*c d=0
|
||||
b=c while b>0 do d+=f[b]*a g-=1 f[b]=remainder(d, g) d=floor(d/g) g-=1 b-=1 if b!=0 then
|
||||
d*=b end if end while printf(1,"%04d",e+floor(d/a)) c-=14 e = remainder(d,a) end while
|
||||
32
Task/Pi/Phix/pi-2.phix
Normal file
32
Task/Pi/Phix/pi-2.phix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
integer n = 2400,
|
||||
len = floor(10*n/3)
|
||||
sequence a = repeat(2,len)
|
||||
integer nines = 0,
|
||||
predigit = 0
|
||||
string res = ""
|
||||
for j=1 to n do
|
||||
integer q = 0
|
||||
for i=len to 1 by -1 do
|
||||
integer x = 10*a[i]+q*i,
|
||||
d = 2*i-1
|
||||
a[i] = remainder(x,d)
|
||||
q = floor(x/d)
|
||||
end for
|
||||
a[1] = remainder(q,10)
|
||||
q = floor(q/10)
|
||||
if q==9 then
|
||||
nines = nines+1
|
||||
else
|
||||
integer nine = '9'
|
||||
if q==10 then
|
||||
predigit += 1
|
||||
q = 0
|
||||
nine = '0'
|
||||
end if
|
||||
res &= predigit+'0'&repeat(nine,nines)
|
||||
predigit = q
|
||||
nines = 0
|
||||
end if
|
||||
end for
|
||||
res &= predigit+'0'
|
||||
puts(1,res)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
integer a,b,c,d,e,g sequence f a=10000 f=repeat(floor(a/5)
|
||||
,8401) c=8400 e=0 while c>0 do g=2*c d=0 b=c while b>0 do
|
||||
d+=f[b]*a g-=1 f[b]=remainder(d, g) d=floor(d/g) g-=1 b-=1
|
||||
if b!=0 then d*=b end if end while printf(1,"%04d",e+floor
|
||||
(d/a)) c-=14 e = remainder(d,a) end while
|
||||
50
Task/Pi/R/pi.r
Normal file
50
Task/Pi/R/pi.r
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
suppressMessages(library(gmp))
|
||||
ONE <- as.bigz("1")
|
||||
TWO <- as.bigz("2")
|
||||
THREE <- as.bigz("3")
|
||||
FOUR <- as.bigz("4")
|
||||
SEVEN <- as.bigz("7")
|
||||
TEN <- as.bigz("10")
|
||||
|
||||
q <- as.bigz("1")
|
||||
r <- as.bigz("0")
|
||||
t <- as.bigz("1")
|
||||
k <- as.bigz("1")
|
||||
n <- as.bigz("3")
|
||||
l <- as.bigz("3")
|
||||
|
||||
char_printed <- 0
|
||||
|
||||
how_many <- 1000
|
||||
|
||||
first <- TRUE
|
||||
while (how_many > 0) {
|
||||
if ((FOUR * q + r - t) < (n * t)) {
|
||||
if (char_printed == 80) {
|
||||
cat("\n")
|
||||
char_printed <- 0
|
||||
}
|
||||
how_many <- how_many - 1
|
||||
char_printed <- char_printed + 1
|
||||
cat(as.integer(n))
|
||||
if (first) {
|
||||
cat(".")
|
||||
first <- FALSE
|
||||
char_printed <- char_printed + 1
|
||||
}
|
||||
nr <- as.bigz(TEN * (r - n * t))
|
||||
n <- as.bigz(((TEN * (THREE * q + r)) %/% t) - (TEN * n))
|
||||
q <- as.bigz(q * TEN)
|
||||
r <- as.bigz(nr)
|
||||
} else {
|
||||
nr <- as.bigz((TWO * q + r) * l)
|
||||
nn <- as.bigz((q * (SEVEN * k + TWO) + r * l) %/% (t * l))
|
||||
q <- as.bigz(q * k)
|
||||
t <- as.bigz(t * l)
|
||||
l <- as.bigz(l + TWO)
|
||||
k <- as.bigz(k + ONE)
|
||||
n <- as.bigz(nn)
|
||||
r <- as.bigz(nr)
|
||||
}
|
||||
}
|
||||
cat("\n")
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
/*REXX program spits out decimal digits of pi (one digit at a time) until Ctrl-Break.*/
|
||||
signal on halt
|
||||
signal on halt /*───► HALT when Ctrl─Break is pressed.*/
|
||||
parse arg digs oFID . /*obtain optional argument from the CL.*/
|
||||
if digs=='' | digs=="," then digs= 300 /*Not specified? Then use the default.*/
|
||||
if oFID=='' | oFID=="," then oFID='PI_SPIT2.OUT' /*" " " " " " */
|
||||
if oFID=='' | oFID=="," then oFID='PI_SPIT2.OUT' /* " " " " " " */
|
||||
numeric digits digs /*with bigger digs, spitting is slower.*/
|
||||
q=1; r=0; t=1; k=1; n=3; L=3; z=0 /*define some REXX variables. */
|
||||
dot=1 /*DOT≡a flag when a dot in pi is shown.*/
|
||||
|
|
@ -11,8 +11,8 @@ dot=1 /*DOT≡a flag when a dot in pi
|
|||
if qq+qq+r-t < tn then do; z= z+1 /* qq+qq is faster than qq*2 */
|
||||
call charout , n
|
||||
call charout oFID, n
|
||||
if dot then do; dot=0; call charout , .
|
||||
call charout oFID, .
|
||||
if dot then do; dot=0; call charout , .
|
||||
call charout oFID, .
|
||||
end
|
||||
nr= (r - tn) * 10
|
||||
n = ((( (qq+q+r) * 10) / t) - n*10) %1
|
||||
|
|
@ -28,5 +28,5 @@ dot=1 /*DOT≡a flag when a dot in pi
|
|||
end /* %1≡fast way doing TRUNC of a number.*/
|
||||
r=nr
|
||||
end /*forever*/
|
||||
exit
|
||||
halt: say; say 'PI_SPIT2 halted via use of Ctrl-Break.'; exit
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
halt: say; say 'PI_SPIT2 halted via use of Ctrl-Break.'; exit
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
def pi
|
||||
pi_digits = Enumerator.new do |y|
|
||||
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
|
||||
dot = nil
|
||||
loop do
|
||||
if 4*q+r-t < n*t
|
||||
yield n
|
||||
if dot.nil?
|
||||
yield '.'
|
||||
dot = '.'
|
||||
end
|
||||
y << n
|
||||
nr = 10*(r-n*t)
|
||||
n = ((10*(3*q+r)) / t) - 10*n
|
||||
q *= 10
|
||||
|
|
@ -25,4 +20,5 @@ def pi
|
|||
end
|
||||
end
|
||||
|
||||
pi {|digit| print digit; $stdout.flush}
|
||||
print pi_digits.next, "."
|
||||
loop { print pi_digits.next }
|
||||
|
|
|
|||
37
Task/Pi/Rust/pi.rust
Normal file
37
Task/Pi/Rust/pi.rust
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use num_bigint::BigInt;
|
||||
|
||||
fn main() {
|
||||
calc_pi();
|
||||
}
|
||||
|
||||
fn calc_pi() {
|
||||
let mut q = BigInt::from(1);
|
||||
let mut r = BigInt::from(0);
|
||||
let mut t = BigInt::from(1);
|
||||
let mut k = BigInt::from(1);
|
||||
let mut n = BigInt::from(3);
|
||||
let mut l = BigInt::from(3);
|
||||
let mut first = true;
|
||||
loop {
|
||||
if &q * 4 + &r - &t < &n * &t {
|
||||
print!("{}", n);
|
||||
if first {
|
||||
print!(".");
|
||||
first = false;
|
||||
}
|
||||
let nr = (&r - &n * &t) * 10;
|
||||
n = (&q * 3 + &r) * 10 / &t - &n * 10;
|
||||
q *= 10;
|
||||
r = nr;
|
||||
} else {
|
||||
let nr = (&q * 2 + &r) * &l;
|
||||
let nn = (&q * &k * 7 + 2 + &r * &l) / (&t * &l);
|
||||
q *= &k;
|
||||
t *= &l;
|
||||
l += 2;
|
||||
k += 1;
|
||||
n = nn;
|
||||
r = nr;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Task/Pi/Scheme/pi.ss
Normal file
30
Task/Pi/Scheme/pi.ss
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
(import (rnrs))
|
||||
|
||||
(define (calc-pi yield)
|
||||
(let loop ((q 1) (r 0) (t 1) (k 1) (n 3) (l 3))
|
||||
(if (< (- (+ (* 4 q) r) t) (* n t))
|
||||
(begin
|
||||
(yield n)
|
||||
(loop (* q 10)
|
||||
(* 10 (- r (* n t)))
|
||||
t
|
||||
k
|
||||
(- (div (* 10 (+ (* 3 q) r)) t) (* 10 n))
|
||||
l))
|
||||
(begin
|
||||
(loop (* q k)
|
||||
(* (+ (* 2 q) r) l)
|
||||
(* t l)
|
||||
(+ k 1)
|
||||
(div (+ (* q (* 7 k)) 2 (* r l)) (* t l))
|
||||
(+ l 2))))))
|
||||
|
||||
(let ((i 0))
|
||||
(calc-pi
|
||||
(lambda (d)
|
||||
(display d)
|
||||
(set! i (+ i 1))
|
||||
(if (= 40 i)
|
||||
(begin
|
||||
(newline)
|
||||
(set! i 0))))))
|
||||
309
Task/Pi/Simula/pi-1.simula
Normal file
309
Task/Pi/Simula/pi-1.simula
Normal file
|
|
@ -0,0 +1,309 @@
|
|||
CLASS BIGNUM;
|
||||
BEGIN
|
||||
|
||||
BOOLEAN PROCEDURE TISZERO(T); TEXT T;
|
||||
TISZERO := T = "0";
|
||||
|
||||
TEXT PROCEDURE TSHL(T); TEXT T;
|
||||
TSHL :- IF TISZERO(T) THEN T ELSE T & "0";
|
||||
|
||||
TEXT PROCEDURE TSHR(T); TEXT T;
|
||||
TSHR :- IF T.LENGTH = 1 THEN "0" ELSE T.SUB(1, T.LENGTH - 1);
|
||||
|
||||
INTEGER PROCEDURE TSIGN(T); TEXT T;
|
||||
TSIGN := IF TISZERO(T) THEN 0
|
||||
ELSE IF T.SUB(1, 1) = "-" THEN -1
|
||||
ELSE 1;
|
||||
|
||||
TEXT PROCEDURE TABS(T); TEXT T;
|
||||
TABS :- IF TSIGN(T) < 0 THEN T.SUB(2, T.LENGTH - 1) ELSE T;
|
||||
|
||||
TEXT PROCEDURE TNEGATE(T); TEXT T;
|
||||
TNEGATE :- IF TSIGN(T) <= 0 THEN TABS(T) ELSE ("-" & T);
|
||||
|
||||
TEXT PROCEDURE TREVERSE(T); TEXT T;
|
||||
BEGIN
|
||||
INTEGER I, J;
|
||||
I := 1; J := T.LENGTH;
|
||||
WHILE I < J DO
|
||||
BEGIN CHARACTER C1, C2;
|
||||
T.SETPOS(I); C1 := T.GETCHAR;
|
||||
T.SETPOS(J); C2 := T.GETCHAR;
|
||||
T.SETPOS(I); T.PUTCHAR(C2);
|
||||
T.SETPOS(J); T.PUTCHAR(C1);
|
||||
I := I + 1;
|
||||
J := J - 1;
|
||||
END;
|
||||
TREVERSE :- T;
|
||||
END TREVERSE;
|
||||
|
||||
INTEGER PROCEDURE TCMPUNSIGNED(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
INTEGER ALEN, BLEN, RESULT;
|
||||
ALEN := A.LENGTH; BLEN := B.LENGTH;
|
||||
IF ALEN < BLEN THEN
|
||||
RESULT := -1
|
||||
ELSE IF ALEN > BLEN THEN
|
||||
RESULT := 1
|
||||
ELSE BEGIN
|
||||
INTEGER CMP, I; BOOLEAN DONE;
|
||||
A.SETPOS(1);
|
||||
B.SETPOS(1);
|
||||
I := 1;
|
||||
WHILE I <= ALEN AND NOT DONE DO
|
||||
BEGIN
|
||||
I := I + 1;
|
||||
CMP := RANK(A.GETCHAR) - RANK(B.GETCHAR);
|
||||
IF NOT (CMP = 0) THEN
|
||||
DONE := TRUE;
|
||||
END;
|
||||
RESULT := CMP;
|
||||
END;
|
||||
TCMPUNSIGNED := RESULT;
|
||||
END TCMPUNSIGNED;
|
||||
|
||||
INTEGER PROCEDURE TCMP(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
BOOLEAN ANEG, BNEG;
|
||||
ANEG := TSIGN(A) < 0; BNEG := TSIGN(B) < 0;
|
||||
IF ANEG AND BNEG THEN
|
||||
TCMP := -TCMPUNSIGNED(TABS(A), TABS(B))
|
||||
ELSE IF NOT ANEG AND BNEG THEN
|
||||
TCMP := 1
|
||||
ELSE IF ANEG AND NOT BNEG THEN
|
||||
TCMP := -1
|
||||
ELSE
|
||||
TCMP := TCMPUNSIGNED(A, B);
|
||||
END TCMP;
|
||||
|
||||
TEXT PROCEDURE TADDUNSIGNED(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
INTEGER CARRY, I, J;
|
||||
TEXT BF;
|
||||
I := A.LENGTH;
|
||||
J := B.LENGTH;
|
||||
BF :- BLANKS(MAX(I, J) + 1);
|
||||
WHILE I >= 1 OR J >= 1 DO BEGIN
|
||||
INTEGER X, Y, Z;
|
||||
IF I >= 1 THEN BEGIN
|
||||
A.SETPOS(I); I := I - 1; X := RANK(A.GETCHAR) - RANK('0');
|
||||
END;
|
||||
IF J >= 1 THEN BEGIN
|
||||
B.SETPOS(J); J := J - 1; Y := RANK(B.GETCHAR) - RANK('0');
|
||||
END;
|
||||
Z := X + Y + CARRY;
|
||||
IF Z < 10 THEN
|
||||
BEGIN BF.PUTCHAR(CHAR(Z + RANK('0'))); CARRY := 0;
|
||||
END ELSE
|
||||
BEGIN BF.PUTCHAR(CHAR(MOD(Z, 10) + RANK('0'))); CARRY := 1;
|
||||
END;
|
||||
END;
|
||||
IF CARRY > 0 THEN
|
||||
BF.PUTCHAR(CHAR(CARRY + RANK('0')));
|
||||
BF :- TREVERSE(BF.STRIP);
|
||||
TADDUNSIGNED :- BF;
|
||||
END TADDUNSIGNED;
|
||||
|
||||
TEXT PROCEDURE TADD(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
BOOLEAN ANEG, BNEG;
|
||||
ANEG := TSIGN(A) < 0; BNEG := TSIGN(B) < 0;
|
||||
IF NOT ANEG AND BNEG THEN ! (+7)+(-5) = (7-5) = 2 ;
|
||||
TADD :- TSUBUNSIGNED(A, TABS(B))
|
||||
ELSE IF ANEG AND NOT BNEG THEN ! (-7)+(+5) = (5-7) = -2 ;
|
||||
TADD :- TSUBUNSIGNED(B, TABS(A))
|
||||
ELSE IF ANEG AND BNEG THEN ! (-7)+(-5) = -(7+5) = -12 ;
|
||||
TADD :- TNEGATE(TADDUNSIGNED(TABS(A), TABS(B)))
|
||||
ELSE ! (+7)+(+5) = (7+5) = 12 ;
|
||||
TADD :- TADDUNSIGNED(A, B);
|
||||
END TADD;
|
||||
|
||||
TEXT PROCEDURE TSUBUNSIGNED(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
INTEGER I, J, CARRY;
|
||||
I := A.LENGTH; J := B.LENGTH;
|
||||
IF I < J OR I = J AND A < B THEN
|
||||
TSUBUNSIGNED :- TNEGATE(TSUBUNSIGNED(B, A)) ELSE
|
||||
BEGIN
|
||||
TEXT BF;
|
||||
BF :- BLANKS(MAX(I, J) + 1);
|
||||
WHILE I >= 1 OR J >= 1 DO
|
||||
BEGIN
|
||||
INTEGER X, Y, Z;
|
||||
IF I >= 1 THEN
|
||||
BEGIN A.SETPOS(I); I := I - 1;
|
||||
X := RANK(A.GETCHAR) - RANK('0');
|
||||
END;
|
||||
IF J >= 1 THEN
|
||||
BEGIN B.SETPOS(J); J := J - 1;
|
||||
Y := RANK(B.GETCHAR) - RANK('0');
|
||||
END;
|
||||
Z := X - Y - CARRY;
|
||||
IF Z >= 0 THEN
|
||||
BEGIN
|
||||
BF.PUTCHAR(CHAR(RANK('0') + Z));
|
||||
CARRY := 0;
|
||||
END ELSE
|
||||
BEGIN
|
||||
BF.PUTCHAR(CHAR(RANK('0') + MOD(10 + Z, 10)));
|
||||
CARRY := 1; ! (Z / 10);
|
||||
END;
|
||||
END;
|
||||
BF :- BF.STRIP;
|
||||
BF :- TREVERSE(BF);
|
||||
BF.SETPOS(1);
|
||||
WHILE BF.LENGTH > 1 AND THEN BF.GETCHAR = '0' DO
|
||||
BEGIN
|
||||
BF :- BF.SUB(2, BF.LENGTH - 1);
|
||||
BF.SETPOS(1);
|
||||
END;
|
||||
TSUBUNSIGNED :- BF;
|
||||
END;
|
||||
END TSUBUNSIGNED;
|
||||
|
||||
TEXT PROCEDURE TSUB(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
BOOLEAN ANEG, BNEG;
|
||||
ANEG := TSIGN(A) < 0; BNEG := TSIGN(B) < 0;
|
||||
IF ANEG AND BNEG THEN ! (-7)-(-5) = -(7-5) = -2 ;
|
||||
TSUB :- TNEGATE(TSUBUNSIGNED(TABS(A), TABS(B)))
|
||||
ELSE IF NOT ANEG AND BNEG THEN ! (+7)-(-5) = (7+5) = 12 ;
|
||||
TSUB :- TADDUNSIGNED(A, TABS(B))
|
||||
ELSE IF ANEG AND NOT BNEG THEN ! (-7)-(+5) = -(7+5) = -12 ;
|
||||
TSUB :- TNEGATE(TADDUNSIGNED(TABS(A), B))
|
||||
ELSE ! (+7)-(+5) = (7-5) = 2 ;
|
||||
TSUB :- TSUBUNSIGNED(A, B);
|
||||
END TSUB;
|
||||
|
||||
TEXT PROCEDURE TMULUNSIGNED(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
INTEGER ALEN, BLEN;
|
||||
ALEN := A.LENGTH; BLEN := B.LENGTH;
|
||||
IF ALEN < BLEN THEN
|
||||
TMULUNSIGNED :- TMULUNSIGNED(B, A)
|
||||
ELSE BEGIN
|
||||
TEXT PRODUCT; INTEGER J;
|
||||
PRODUCT :- "0";
|
||||
FOR J := 1 STEP 1 UNTIL BLEN DO BEGIN
|
||||
TEXT PART; INTEGER I, Y, CARRY;
|
||||
B.SETPOS(J); Y := RANK(B.GETCHAR) - RANK('0');
|
||||
PART :- BLANKS(ALEN + BLEN + 1); PART.SETPOS(1);
|
||||
FOR I := ALEN STEP -1 UNTIL 1 DO BEGIN
|
||||
INTEGER X, Z;
|
||||
A.SETPOS(I); X := RANK(A.GETCHAR) - RANK('0');
|
||||
Z := X * Y + CARRY;
|
||||
IF Z < 10 THEN BEGIN
|
||||
PART.PUTCHAR(CHAR(RANK('0') + Z));
|
||||
CARRY := 0;
|
||||
END ELSE BEGIN
|
||||
PART.PUTCHAR(CHAR(RANK('0') + MOD(Z, 10)));
|
||||
CARRY := Z // 10;
|
||||
END;
|
||||
END;
|
||||
IF CARRY > 0 THEN
|
||||
PART.PUTCHAR(CHAR(RANK('0') + CARRY));
|
||||
PART :- PART.SUB(1, PART.POS - 1);
|
||||
PART :- TREVERSE(PART);
|
||||
PART.SETPOS(1);
|
||||
WHILE PART.LENGTH > 1 AND THEN PART.GETCHAR = '0' DO
|
||||
BEGIN
|
||||
PART :- PART.SUB(2, PART.LENGTH - 1);
|
||||
PART.SETPOS(1);
|
||||
END;
|
||||
PRODUCT :- TADDUNSIGNED(TSHL(PRODUCT), PART);
|
||||
END;
|
||||
TMULUNSIGNED :- PRODUCT;
|
||||
END;
|
||||
END TMULUNSIGNED;
|
||||
|
||||
TEXT PROCEDURE TMUL(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
BOOLEAN ANEG, BNEG;
|
||||
ANEG := TSIGN(A) < 0; BNEG := TSIGN(B) < 0;
|
||||
IF ANEG AND BNEG THEN ! (-7)*(-5) = (7*5) => 35 ;
|
||||
TMUL :- TMULUNSIGNED(TABS(A), TABS(B))
|
||||
ELSE IF NOT ANEG AND BNEG THEN ! (+7)*(-5) = -(7*5) => -35 ;
|
||||
TMUL :- TNEGATE(TMULUNSIGNED(A, TABS(B)))
|
||||
ELSE IF ANEG AND NOT BNEG THEN ! (-7)*(+5) = -(7*5) => -35 ;
|
||||
TMUL :- TNEGATE(TMULUNSIGNED(TABS(A), B))
|
||||
ELSE ! (+7)*(+5) = (7*5) => 35 ;
|
||||
TMUL :- TMULUNSIGNED(A, B);
|
||||
END TMUL;
|
||||
|
||||
CLASS DIVMOD(DIV,MOD); TEXT DIV,MOD;;
|
||||
|
||||
REF(DIVMOD) PROCEDURE TDIVMODUNSIGNED(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
INTEGER CC;
|
||||
REF(DIVMOD) RESULT;
|
||||
IF TISZERO(B) THEN
|
||||
ERROR("DIVISION BY ZERO");
|
||||
CC := TCMPUNSIGNED(A, B);
|
||||
IF CC < 0 THEN
|
||||
RESULT :- NEW DIVMOD("0", A)
|
||||
ELSE IF CC = 0 THEN
|
||||
RESULT :- NEW DIVMOD("1", "0")
|
||||
ELSE BEGIN
|
||||
INTEGER ALEN, BLEN, AIDX;
|
||||
TEXT Q, R;
|
||||
ALEN := A.LENGTH; BLEN := B.LENGTH;
|
||||
Q :- BLANKS(ALEN); Q.SETPOS(1);
|
||||
R :- BLANKS(ALEN); R.SETPOS(1);
|
||||
R := A.SUB(1, BLEN - 1); R.SETPOS(BLEN);
|
||||
FOR AIDX := BLEN STEP 1 UNTIL ALEN DO
|
||||
BEGIN
|
||||
INTEGER COUNT; BOOLEAN DONE;
|
||||
IF TISZERO(R.STRIP) THEN
|
||||
R.SETPOS(1);
|
||||
A.SETPOS(AIDX); R.PUTCHAR(A.GETCHAR);
|
||||
WHILE NOT DONE DO
|
||||
BEGIN
|
||||
TEXT DIFF;
|
||||
DIFF :- TSUBUNSIGNED(R.STRIP, B);
|
||||
IF TSIGN(DIFF) < 0 THEN
|
||||
DONE := TRUE
|
||||
ELSE BEGIN
|
||||
R := DIFF; R.SETPOS(DIFF.LENGTH + 1);
|
||||
COUNT := COUNT + 1;
|
||||
END;
|
||||
END;
|
||||
IF (NOT (COUNT = 0)) OR (NOT (Q.POS = 1)) THEN
|
||||
Q.PUTCHAR(CHAR(COUNT + RANK('0')));
|
||||
END;
|
||||
RESULT :- NEW DIVMOD(Q.STRIP, R.STRIP);
|
||||
END;
|
||||
TDIVMODUNSIGNED :- RESULT;
|
||||
END TDIVMODUNSIGNED;
|
||||
|
||||
REF(DIVMOD) PROCEDURE TDIVMOD(A, B); TEXT A, B;
|
||||
BEGIN
|
||||
BOOLEAN ANEG, BNEG; REF(DIVMOD) RESULT;
|
||||
ANEG := TSIGN(A) < 0; BNEG := TSIGN(B) < 0;
|
||||
IF ANEG AND BNEG THEN
|
||||
BEGIN
|
||||
RESULT :- TDIVMOD(TABS(A), TABS(B));
|
||||
RESULT.MOD :- TNEGATE(RESULT.MOD);
|
||||
END
|
||||
ELSE IF NOT ANEG AND BNEG THEN
|
||||
BEGIN
|
||||
RESULT :- TDIVMOD(A, TABS(B));
|
||||
RESULT.DIV :- TNEGATE(RESULT.DIV);
|
||||
END
|
||||
ELSE IF ANEG AND NOT BNEG THEN
|
||||
BEGIN
|
||||
RESULT :- TDIVMOD(TABS(A), B);
|
||||
RESULT.DIV :- TNEGATE(RESULT.DIV);
|
||||
RESULT.MOD :- TNEGATE(RESULT.MOD);
|
||||
END
|
||||
ELSE
|
||||
RESULT :- TDIVMODUNSIGNED(A, B);
|
||||
TDIVMOD :- RESULT;
|
||||
END TDIVMOD;
|
||||
|
||||
TEXT PROCEDURE TDIV(A, B); TEXT A, B;
|
||||
TDIV :- TDIVMOD(A, B).DIV;
|
||||
|
||||
TEXT PROCEDURE TMOD(A, B); TEXT A, B;
|
||||
TMOD :- TDIVMOD(A, B).MOD;
|
||||
|
||||
END BIGNUM;
|
||||
70
Task/Pi/Simula/pi-2.simula
Normal file
70
Task/Pi/Simula/pi-2.simula
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
EXTERNAL CLASS BIGNUM;
|
||||
BIGNUM
|
||||
BEGIN
|
||||
|
||||
PROCEDURE CALCPI;
|
||||
BEGIN
|
||||
INTEGER I;
|
||||
TEXT Q, R, T, K, N, L;
|
||||
COMMENT
|
||||
! q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
|
||||
;
|
||||
Q :- COPY("1");
|
||||
R :- COPY("0");
|
||||
T :- COPY("1");
|
||||
K :- COPY("1");
|
||||
N :- COPY("3");
|
||||
L :- COPY("3");
|
||||
WHILE TRUE DO
|
||||
BEGIN
|
||||
COMMENT
|
||||
! if 4*q+r-t < n*t
|
||||
;
|
||||
IF TCMP(TSUB(TADD(TMUL("4",Q),R),T),TMUL(N,T)) < 0 THEN
|
||||
BEGIN
|
||||
TEXT NR;
|
||||
OUTTEXT(N);
|
||||
I := I + 1;
|
||||
IF I = 40 THEN
|
||||
BEGIN
|
||||
OUTIMAGE;
|
||||
I := 0;
|
||||
END;
|
||||
COMMENT
|
||||
! nr = 10*(r-n*t)
|
||||
! n = ((10*(3*q+r))//t)-10*n
|
||||
! q *= 10
|
||||
! r = nr
|
||||
;
|
||||
NR :- TMUL("10",TSUB(R,TMUL(N,T)));
|
||||
N :- TSUB(TDIV(TMUL("10",TADD(TMUL("3",Q),R)),T),TMUL("10",N));
|
||||
Q :- TMUL("10",Q);
|
||||
R :- NR;
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
TEXT NR, NN;
|
||||
COMMENT
|
||||
! nr = (2*q+r)*l
|
||||
! nn = (q*(7*k)+2+(r*l))//(t*l)
|
||||
! q *= k
|
||||
! t *= l
|
||||
! l += 2
|
||||
! k += 1
|
||||
! n = nn
|
||||
! r = nr
|
||||
;
|
||||
NR :- TMUL(TADD(TMUL("2",Q),R),L);
|
||||
NN :- TDIV(TADD(TADD(TMUL(Q,TMUL("7",K)),"2"),TMUL(R,L)),TMUL(T,L));
|
||||
Q :- TMUL(Q,K);
|
||||
T :- TMUL(T,L);
|
||||
L :- TADD(L,"2");
|
||||
K :- TADD(K,"1");
|
||||
N :- NN;
|
||||
R :- NR;
|
||||
END;
|
||||
END;
|
||||
END CALCPI;
|
||||
|
||||
CALCPI;
|
||||
END.
|
||||
25
Task/Pi/TypeScript/pi-1.type
Normal file
25
Task/Pi/TypeScript/pi-1.type
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
type AnyWriteableObject={write:((textToOutput:string)=>any)};
|
||||
|
||||
function calcPi(pipe:AnyWriteableObject) {
|
||||
let q = 1n, r=0n, t=1n, k=1n, n=3n, l=3n;
|
||||
while (true) {
|
||||
if (q * 4n + r - t < n* t) {
|
||||
pipe.write(n.toString());
|
||||
let nr = (r - n * t) * 10n;
|
||||
n = (q * 3n + r) * 10n / t - n * 10n ;
|
||||
q = q * 10n;
|
||||
r = nr;
|
||||
} else {
|
||||
let nr = (q * 2n + r) * l;
|
||||
let nn = (q * k * 7n + 2n + r * l) / (t * l);
|
||||
q = q * k;
|
||||
t = t * l;
|
||||
l = l + 2n;
|
||||
k = k + 1n;
|
||||
n = nn;
|
||||
r = nr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
calcPi(process.stdout);
|
||||
40
Task/Pi/TypeScript/pi-2.type
Normal file
40
Task/Pi/TypeScript/pi-2.type
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
type AnyWriteableObject = {write:((textToOutput:string)=>Promise<any>)};
|
||||
|
||||
async function calcPi<T extends AnyWriteableObject>(pipe:T) {
|
||||
let q = 1n, r=0n, t=1n, k=1n, n=3n, l=3n;
|
||||
while (true) {
|
||||
if (q * 4n + r - t < n* t) {
|
||||
await pipe.write(n.toString());
|
||||
let nr = (r - n * t) * 10n;
|
||||
n = (q * 3n + r) * 10n / t - n * 10n ;
|
||||
q = q * 10n;
|
||||
r = nr;
|
||||
} else {
|
||||
let nr = (q * 2n + r) * l;
|
||||
let nn = (q * k * 7n + 2n + r * l) / (t * l);
|
||||
q = q * k;
|
||||
t = t * l;
|
||||
l = l + 2n;
|
||||
k = k + 1n;
|
||||
n = nn;
|
||||
r = nr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(function(){
|
||||
console.log(); // put a new line every second
|
||||
},1000);
|
||||
|
||||
var x = calcPi({
|
||||
write: async function(phrase:string){
|
||||
return new Promise(function(resolve){
|
||||
setTimeout(function(){
|
||||
process.stdout.write(phrase);
|
||||
resolve();
|
||||
},1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
console.log('.'); //start!
|
||||
24
Task/Pi/Visual-Basic-.NET/pi-1.visual
Normal file
24
Task/Pi/Visual-Basic-.NET/pi-1.visual
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Imports System
|
||||
Imports System.Numerics
|
||||
|
||||
Public Module Module1
|
||||
Public Sub Main()
|
||||
Dim two, three, four, seven, ten, k, q, t, l, n, r, nn, nr As BigInteger,
|
||||
first As Boolean = True
|
||||
two = New BigInteger(2) : three = New BigInteger(3) : four = two + two
|
||||
seven = three + four : ten = three + seven : k = BigInteger.One
|
||||
q = k : t = k : l = three : n = three : r = BigInteger.Zero
|
||||
While True
|
||||
If four * q + r - t < n * t Then
|
||||
Console.Write(n) : If first Then Console.Write(".") : first = False
|
||||
nr = ten * (r - n * t) : n = ten * (three * q + r) / t - ten * n
|
||||
q *= ten
|
||||
Else
|
||||
nr = (two * q + r) * l : nn = (q * seven * k + two + r * l) / (t * l)
|
||||
q *= k : t *= l : l += two : k += BigInteger.One : n = nn
|
||||
End If
|
||||
r = nr
|
||||
End While
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
35
Task/Pi/Visual-Basic-.NET/pi-2.visual
Normal file
35
Task/Pi/Visual-Basic-.NET/pi-2.visual
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
Imports System, System.Numerics, System.Text
|
||||
|
||||
Module Program
|
||||
|
||||
Sub RunPiF(ByVal msg As String)
|
||||
If msg.Length > 0 Then Console.WriteLine(msg)
|
||||
Dim first As Boolean = True, stp As BigInteger = 360,
|
||||
lim As BigInteger = stp, res As StringBuilder = New StringBuilder(),
|
||||
rc As Integer = -1, u, j, k As BigInteger, q As BigInteger = 1,
|
||||
r As BigInteger = 180, t As BigInteger = 60, i As BigInteger = 2,
|
||||
y As Byte, et As TimeSpan, st As DateTime = DateTime.Now
|
||||
|
||||
While True
|
||||
While i < lim
|
||||
j = i << 1 : k = j + i : u = 3 * (k + 1) * (k + 2)
|
||||
y = CByte(((q * (9 * k - 12) + 5 * r) / (5 * t)))
|
||||
res.Append(y)
|
||||
r = (q * (k + j - 2) + r - y * t) * u * 10
|
||||
t *= u : q = 10 * q * (j - 1) * i : i += 1
|
||||
End While
|
||||
If first Then res.Insert(1, "."c) : first = False
|
||||
Console.Write(res.ToString())
|
||||
rc += res.Length : res.Clear() : lim += stp
|
||||
If Console.KeyAvailable Then Exit While
|
||||
End While
|
||||
et = DateTime.Now - st : Console.ReadKey()
|
||||
Console.Write(res.ToString()) : rc += res.Length
|
||||
Console.WriteLine(vbLf & "Produced {0} digits in {1:n4} seconds.", rc, et.TotalSeconds)
|
||||
End Sub
|
||||
|
||||
Sub Main(args As String())
|
||||
RunPiF("Press a key to exit...")
|
||||
If Diagnostics.Debugger.IsAttached Then Console.ReadKey()
|
||||
End Sub
|
||||
End Module
|
||||
35
Task/Pi/Visual-Basic/pi.vb
Normal file
35
Task/Pi/Visual-Basic/pi.vb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main()
|
||||
Const VECSIZE As Long = 3350
|
||||
Const BUFSIZE As Long = 201
|
||||
Dim buffer(1 To BUFSIZE) As Long
|
||||
Dim vect(1 To VECSIZE) As Long
|
||||
Dim more As Long, karray As Long, num As Long, k As Long, l As Long, n As Long
|
||||
|
||||
For n = 1 To VECSIZE
|
||||
vect(n) = 2
|
||||
Next n
|
||||
For n = 1 To BUFSIZE
|
||||
karray = 0
|
||||
For l = VECSIZE To 1 Step -1
|
||||
num = 100000 * vect(l) + karray * l
|
||||
karray = num \ (2 * l - 1)
|
||||
vect(l) = num - karray * (2 * l - 1)
|
||||
Next l
|
||||
k = karray \ 100000
|
||||
buffer(n) = more + k
|
||||
more = karray - k * 100000
|
||||
Next n
|
||||
Debug.Print CStr(buffer(1));
|
||||
Debug.Print "."
|
||||
l = 0
|
||||
For n = 2 To BUFSIZE
|
||||
Debug.Print Format$(buffer(n), "00000");
|
||||
l = l + 1
|
||||
If l = 10 Then
|
||||
l = 0
|
||||
Debug.Print 'line feed
|
||||
End If
|
||||
Next n
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue