Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,25 @@
(defun pi-spigot ()
(labels
((g (q r t1 k n l)
(cond
((< (- (+ (* 4 q) r) t1)
(* n t1))
(princ n)
(g (* 10 q)
(* 10 (- r (* n t1)))
t1
k
(- (floor (/ (* 10 (+ (* 3 q) r))
t1))
(* 10 n))
l))
(t
(g (* q k)
(* (+ (* 2 q) r) l)
(* t1 l)
(+ k 1)
(floor (/ (+ (* q (+ (* 7 k) 2))
(* r l))
(* t1 l)))
(+ l 2))))))
(g 1 0 1 1 3 3)))

17
Task/Pi/Elixir/pi.elixir Normal file
View file

@ -0,0 +1,17 @@
defmodule Pi do
def calc, do: calc(1,0,1,1,3,3,0)
defp calc(q,r,t,k,n,l,c) when c==50 do
IO.write "\n"
calc(q,r,t,k,n,l,0)
end
defp calc(q,r,t,k,n,l,c) when (4*q + r - t) < n*t do
IO.write n
calc(q*10, 10*(r-n*t), t, k, div(10*(3*q+r), t) - 10*n, l, c+1)
end
defp calc(q,r,t,k,_n,l,c) do
calc(q*k, (2*q+r)*l, t*l, k+1, div(q*7*k+2+r*l, t*l), l+2, c)
end
end
Pi.calc

View file

@ -1 +1,3 @@
N[Pi, 1000000!]
WriteString[$Output, "3."];
For[i = -1, True, i--,
WriteString[$Output, RealDigits[Pi, 10, 1, i][[1, 1]]]; Pause[.05]];

View file

@ -19,7 +19,7 @@ sub comp([$q,$r,$s,$t], [$u,$v,$w,$x]) {
$s * $v + $t * $x]
}
my @pi :=
my $pi :=
stream -> $z { extr($z, 3) },
-> $z, $n { $n == extr($z, 4) },
-> $z, $n { comp([10, -10*$n, 0, 1], $z) },
@ -27,7 +27,7 @@ my @pi :=
<1 0 0 1>,
(1..*).map: { [$_, 4 * $_ + 2, 0, 2 * $_ + 1] }
loop {
print @pi.shift;
for ^Inf -> $i {
print $pi[$i];
once print '.'
}

View file

@ -1,22 +1,23 @@
/*REXX program spits out digits of pi (one at a time) until Ctrl-Break.*/
arg digs .; if digs=='' then digs=1e6 /*allow the specification of digs*/
fn = 'PI_DIGITS.OUT' /*file used for output: PI digits*/
numeric digits digs /*big digs, the slower the spits.*/
pi=0; s=16; r=4; v=5; vs=v*v; g=239; gg=g*g; j=1; spit=0; old=
call time 'Reset' /*reset the REXX wall-clock timer*/
/*───calculate PI with increasing*/
do n=1 by 2 /*───accuracy (up to DIGS digits)*/
pi=pi + s/(n*v) - r/(n*g) /*───using John Machin's formula.*/
if pi==old then leave /*have exceeded DIGITS accuracy. */
s=-s; r=-r; v=v*vs; g=g*gg /*set some variable for shortcuts*/
if n\==1 then do j=spit+1 to compare(pi,old) /*spit out some π digs.*/
spit=substr(pi,j,1) /*obtain a digit of π to spit out*/
call charout ,spit /*spit out one (new) digit of pi.*/
call charout fn,spit /* ···and also echo it to a file.*/
end /*j*/
spit=j-1 /*adjust for DO index increment.*/
old=pi /*use the "OLD" value next time. */
end /*n*/
/*REXX program spits out digits of π (pi) (one at a time) until Ctrl-Break.*/
parse arg digs . /*obtain optional argument from the CL.*/
if digs=='' | digs=="," then digs=1e6 /*Not specified? Then use one million.*/
fn = 'PI_DIGITS.OUT' /*fileID used for output: the π digits.*/
numeric digits digs /*with bigger digs, spitting is slower.*/
call time 'Reset' /*reset the wall-clock (elapsed) timer.*/
signal on halt /*───► HALT when Ctrl─Break is pressed.*/
pi=0; s=16; r=4; v=5; vv=v*v; g=239; gg=g*g; spit=0; old=
say; say n%2+1 'iterations took' format(time("Elapsed"),,2) 'seconds.'
/*stick a fork in it, we're done.*/
do n=1 by 2 /*calculate π with increasing accuracy */
pi=pi + s/(n*v) - r/(n*g) /* ··· using John Machin's formula.*/
if pi==old then leave /*have we exceeded the DIGITS accuracy?*/
s=-s; r=-r; v=v*vv; g=g*gg /*compute some variables for shortcuts.*/
do j=spit+1 to compare(pi,old) /*spit out some (new) digits of π (pi)*/
parse var pi =(j) spit +1 /*equivalent to: spit=substr(pi,j,1) */
call charout ,spit /*display one (new) decimal digit of π.*/
call charout fn,spit /*··· and also write π digit to a file.*/
end /*j*/ /* [↑] 0, 1, or 2 decimal dig are spit*/
spit=j-1 /*adjust for DO loop index increment.*/
old=pi /*use "OLD" value for the next COMPARE.*/
end /*n*/
say /*stick a fork in it, we're all done. */
halt: say n%2+1 'iterations took' format(time("Elapsed"),,2) 'seconds.'