So, I bought this book called Primes and Programming, and it's pretty tough going. Today I wrote this (simple) program from chapter 1:
#!/usr/bin/env python
import math
def find_gcd(a,b):
while b > 0:
r = a - b * math.floor(a/b)
a = b
b = r
return int(a)
if __name__ == "__main__":
import random, sys
while True:
print find_gcd(random.randrange(int(sys.argv[1])), random.randrange(int(sys.argv[2])))
...and just now I called it like so:
./gcd-rand.py 10000 10000 > concievablyreallyhugefile
...and now I'm dreaming of a bash
one-liner that breaks when concievablyreallyhugefile has reached a certain size. I guess it would look something like:
while $(du -h f) < 32M; do ./gcd-rand.py 10000 10000 > $f; done
...but I have never written a while loop in bash
before and I don't really know how the syntax works.
man bash
.fractions.gcd
method is useful.