Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

46
Task/Pi/Nim/pi-1.nim Normal file
View file

@ -0,0 +1,46 @@
import bigints
var
tmp1, tmp2, tmp3, acc, k = initBigInt(0)
den, num, k2 = initBigInt(1)
proc extractDigit(): int32 =
if num > acc:
return -1
tmp3 = num shl 1 + num + acc
tmp1 = tmp3 div den
tmp2 = tmp3 mod den + num
if tmp2 >= den:
return -1
result = int32(tmp1.limbs[0])
proc eliminateDigit(d: int32) =
acc -= den * d
acc *= 10
num *= 10
proc nextTerm() =
k += 1
k2 += 2
acc += num shl 1
acc *= k2
den *= k2
num *= k
var i = 0
while true:
var d: int32 = -1
while d < 0:
nextTerm()
d = extractDigit()
stdout.write chr(ord('0') + d)
inc i
if i == 40:
echo ""
i = 0
eliminateDigit d

32
Task/Pi/Nim/pi-2.nim Normal file
View file

@ -0,0 +1,32 @@
import bignum
proc calcPi() =
var
q = newInt(1)
r = newInt(0)
t = newInt(1)
k = newInt(1)
n = newInt(3)
l = newInt(3)
var count = 0
while true:
if 4 * q + r - t < n * t:
stdout.write n
inc count
if count == 40: (echo ""; count = 0)
let nr = 10 * (r - n * t)
n = 10 * (3 * q + r) div t - 10 * n
q *= 10
r = nr
else:
let nr = (2 * q + r) * l
let nn = (7 * q * k + 2 + r * l) div (t * l)
q *= k
t *= l
l += 2
k += 1
n = nn
r = nr
calcPi()