YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
59
Task/Pi/BASIC/pi-1.basic
Normal file
59
Task/Pi/BASIC/pi-1.basic
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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-2.basic
Normal file
51
Task/Pi/BASIC/pi-2.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
|
||||
54
Task/Pi/FreeBASIC/pi.freebasic
Normal file
54
Task/Pi/FreeBASIC/pi.freebasic
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
' version 05-07-2018
|
||||
' compile with: fbc -s console
|
||||
|
||||
' unbounded spigot
|
||||
' Ctrl-c to end program or close console window
|
||||
|
||||
#Include "gmp.bi"
|
||||
|
||||
Dim As UInteger num, ndigit, fp = Not 0
|
||||
Dim As mpz_ptr q,r,t,k,n,l,tmp1,tmp2
|
||||
q = Allocate(Len(__Mpz_struct)) : Mpz_init_set_ui(q,1)
|
||||
r = Allocate(Len(__Mpz_struct)) : Mpz_init(r)
|
||||
t = Allocate(Len(__Mpz_struct)) : Mpz_init_set_ui(t,1)
|
||||
k = Allocate(Len(__Mpz_struct)) : Mpz_init_set_ui(k,1)
|
||||
n = Allocate(Len(__Mpz_struct)) : Mpz_init_set_ui(n,3)
|
||||
l = Allocate(Len(__Mpz_struct)) : Mpz_init_set_ui(l,3)
|
||||
tmp1 = Allocate(Len(__Mpz_struct)) : Mpz_init(tmp1)
|
||||
tmp2 = Allocate(Len(__Mpz_struct)) : Mpz_init(tmp2)
|
||||
|
||||
Do
|
||||
mpz_mul_2exp(tmp1, q, 2)
|
||||
mpz_add(tmp1,tmp1,r)
|
||||
mpz_sub(tmp1,tmp1,t)
|
||||
mpz_mul(tmp2, n, t)
|
||||
If mpz_cmp(tmp1, tmp2) < 0 Then
|
||||
Print mpz_get_ui(n); : ndigit += 1 : If ndigit Mod 50 = 0 Then Print " :";ndigit
|
||||
If fp Then Print "."; : fp = Not fp : Print :ndigit = 0
|
||||
mpz_sub(tmp1, r, tmp2)
|
||||
mpz_mul_ui(tmp1, tmp1, 10)
|
||||
mpz_mul_ui(tmp2, q, 3)
|
||||
mpz_add(tmp2, tmp2, r)
|
||||
mpz_mul_ui(tmp2, tmp2, 10)
|
||||
mpz_set(r, tmp1)
|
||||
mpz_mul_ui(tmp1, n, 10)
|
||||
mpz_tdiv_q(tmp2, tmp2, t)
|
||||
mpz_sub(n, tmp2, tmp1)
|
||||
mpz_mul_ui(q, q, 10)
|
||||
Else
|
||||
mpz_mul(tmp2, r, l)
|
||||
mpz_mul(tmp1, q, k)
|
||||
mpz_mul_ui(tmp1, tmp1, 7)
|
||||
mpz_add(tmp1, tmp1, tmp2)
|
||||
mpz_mul_2exp(tmp2, q, 1)
|
||||
mpz_add(tmp2, tmp2, r)
|
||||
mpz_mul(tmp2, tmp2, l)
|
||||
mpz_mul(t, t, l)
|
||||
mpz_tdiv_q(tmp1, tmp1, t)
|
||||
mpz_mul(q, q, k)
|
||||
mpz_add_ui(k, k, 1)
|
||||
mpz_add_ui(l, l, 2)
|
||||
mpz_set(n, tmp1)
|
||||
mpz_set(r, tmp2)
|
||||
End If
|
||||
Loop
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import strutils, unsigned, bigints
|
||||
import strutils, bigints
|
||||
|
||||
var
|
||||
tmp1, tmp2, tmp3, acc, k, dd = initBigInt(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue