rdm@cfcl.UUCP (Rich Morin) (01/28/88)
Several years ago, I heard a talk by M.D. McIlroy on data flow programming.
One of the ideas he mentioned stuck, and today I decided to code it up.
No comments are needed, of course, since shell scripts are self-documenting.
;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-} ;-}
:
# primes - implement M.D. McIlroy's prime generator
#
# Written by Rich Morin, CFCL, 880127
i=${1-1}
if [ $i -gt 15 ]; then
exit
fi
awk '
BEGIN {
if ('$i' == 1) {
printf "%9d %9d\n", 1, 1 > "/dev/tty"
for (i=2; i<=100; i++)
print i
exit
}
}
NR == 1 {
printf "%9d %9d\n", '$i', $1 > "/dev/tty"
factor = $1
next
}
int($1/factor)*factor != $1
' | primes `expr $i + 1`
exit
--
_ o _ |_ _ _ _ _ o _ Canta Forda Computer Laboratory
| | | | | | | | | | | | | | UNIX software consulting and training
| | |_ | | | | | |_| | | | | {hoptoad,ptsfa}!cfcl!rdm +1 415 994 6860