-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpidigits.jl
47 lines (40 loc) · 996 Bytes
/
pidigits.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
# based on Mario Pernici Python's program
#print_line(ns, i) = println(rpad(string(ns), 10), '\t', ':', i)
print_line(ns,i) = 0
function pidigits(N::Int)
i = k = ns = 0
k1 = 1
n,a,d,t,u = map(BigInt,(1,0,1,0,0))
while true
k += 1
t = n << 1
n *= k
a += t
k1 += 2
a *= k1
d *= k1
if a >= n
t,u = divrem(n*3 +a, d)
u += n
if d > u
if i >= N
print_line(ns, i)
return ns
end
ns = ns*10 + t
i += 1
if mod(i,10) == 0
print_line(ns, i)
ns = 0
end
a -= d*t
a *= 10
n *= 10
end
end
end
end
n = parse(Int,ARGS[1])
@time pidigits(n)