Skip to content

Instantly share code, notes, and snippets.

@egroj97
Created July 24, 2019 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egroj97/be2775e0fffd437fc37099c706538c50 to your computer and use it in GitHub Desktop.
Save egroj97/be2775e0fffd437fc37099c706538c50 to your computer and use it in GitHub Desktop.
# All the primes...
constant p = [ (1..∞).grep(&is-prime) ];
# The definitions of "strong" and "weak"...
sub strong (\n) { n > 0 && p[n] > p[n-1, n+1].sum/2 }
sub weak (\n) { n > 0 && p[n] < p[n-1, n+1].sum/2 }
# All the strong and weak primes...
constant strong-p = p.kv.map: ->\n,\pₙ {pₙ if strong n};
constant weak-p = p.kv.map: ->\n,\pₙ {pₙ if weak n};
# Print out the first ten...
say 'strong primes: ', strong-p[^10];
say 'weak primes: ', weak-p[^10];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment