Created
January 21, 2011 10:16
-
-
Save michaelcontento/789502 to your computer and use it in GitHub Desktop.
Detect prime twins in bash
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
#!/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