Skip to content

Instantly share code, notes, and snippets.

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 krishnanraman/427ad599b68063c80e9a5fa76882d045 to your computer and use it in GitHub Desktop.
Save krishnanraman/427ad599b68063c80e9a5fa76882d045 to your computer and use it in GitHub Desktop.
# Find x such that x+1, 2x+3,3x+5 and 4x+7 are prime.
library(DescTools)
# This works
subset(expand.grid(x=1:1000),IsPrime(x+1) & IsPrime(2*x+3) & IsPrime(3*x+5) & IsPrime(4*x+7))
# Alternate solution
which(mapply(function(x) IsPrime(x+1) & IsPrime(2*x+3) & IsPrime(3*x+5) & IsPrime(4*x+7), 1:1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment