Created
March 18, 2015 22:21
-
-
Save is8ac/ac00c316b0d28e3eda59 to your computer and use it in GitHub Desktop.
Calculate prime gaps, and then plots their frequency.
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
# Set prime to a subset of the full prime list so it won't take forever to compute. | |
prime <- prime6[1:100000,] | |
# Calculate the prime gaps. | |
for(n in 2:length(prime$index)){ | |
prime$gap[n] <-prime$prime[n] - prime$prime[n-1] | |
} | |
# Now find the frequency of the first 100 prime gaps. | |
gapLength <- list() | |
for(gapN in (1:100)){ | |
gapLength$gap[gapN] <- gapN | |
gapLength$number[gapN] <- length(which(prime$gap==gapN)) | |
} | |
# Plot the frequency | |
plot(gapLength$gap,gapLength$number, | |
xlab="Gap length", | |
ylab="Frequency of gap") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment