Skip to content

Instantly share code, notes, and snippets.

@is8ac
Created March 18, 2015 22:21
Show Gist options
  • Save is8ac/ac00c316b0d28e3eda59 to your computer and use it in GitHub Desktop.
Save is8ac/ac00c316b0d28e3eda59 to your computer and use it in GitHub Desktop.
Calculate prime gaps, and then plots their frequency.
# 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