Skip to content

Instantly share code, notes, and snippets.

@9nut
Created January 26, 2019 03:02
Show Gist options
  • Save 9nut/476be37e25e9561f525036bcf60a2014 to your computer and use it in GitHub Desktop.
Save 9nut/476be37e25e9561f525036bcf60a2014 to your computer and use it in GitHub Desktop.
Prime Sieve - Plan 9 rc script
# 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