blob: 39d6077ebdfbcb9172599bda46813923a92053e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/usr/bin/gawk
# Challenge 004
#
# Challenge #1
# Write a script to output the same number of PI digits as the size of your script.
# Say, if your script size is 10, it should print 3.141592653.
#
# we need a big-math library to compute any large number of digits
BEGIN {
size = ARGV[1] ? ARGV[1] : 1000;
bc = "echo 'scale=" (size+10) "; 4*a(1)' | bc -l";
pi = "";
while ((bc | getline temp) > 0) {
gsub(/\\/, "", temp);
pi = pi temp;
}
pi = substr(pi, 1, size+1)
print pi;
exit 0;
}
|