Created
January 26, 2019 03:02
-
-
Save 9nut/476be37e25e9561f525036bcf60a2014 to your computer and use it in GitHub Desktop.
Prime Sieve - Plan 9 rc script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prime sieve based on https://swtch.com/~rsc/talks/threads07/ | |
# primes appear on stderr | |
# example: | |
# seq 2 100 | filter | |
fn filter { | |
p=`{read -n 1} | |
if (~ $status '') { | |
echo $p >[1=2] | |
x=`{read -n 1} | |
while (~ $status '') { | |
if (test `{echo $x '%' $p | hoc} -ne 0) echo $x | |
x=`{read -n 1} | |
} | |
} | filter | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment