Skip to content

Instantly share code, notes, and snippets.

@michaelcontento
Created January 21, 2011 10:16
Show Gist options
  • Save michaelcontento/789502 to your computer and use it in GitHub Desktop.
Save michaelcontento/789502 to your computer and use it in GitHub Desktop.
Detect prime twins in bash
#!/usr/bin/env bash
START=2
STOP=300
lastprime=2
primes=$(wget -O - -q http://www.math.utah.edu/~alfeld/math/p10000.html \
| cut -c8- \
| egrep -o '^ [0-9 ]+$' \
| awk '{ list = list $0 } END { print list }')
for prime in $primes; do
if [ $prime -gt $STOP ]; then
break
fi
if [ $prime -lt $START ]; then
continue
fi
if [ $((prime - $lastprime)) -eq 2 ]; then
echo -e "$lastprime\t$prime"
fi
lastprime=$prime
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment