Skip to content

Instantly share code, notes, and snippets.

@csoroz
Created June 5, 2019 17:08
Show Gist options
  • Save csoroz/4aba11e1fee1317106fe214ab361633d to your computer and use it in GitHub Desktop.
Save csoroz/4aba11e1fee1317106fe214ab361633d to your computer and use it in GitHub Desktop.
Sheldon's Theorem
-- [Sheldon's (Conjecture) Theorem](https://www.math.dartmouth.edu/~carlp/sheldonresub011119.pdf)
import Test.QuickCheck
import Data.Tuple
import Data.List
unDigits base = foldl (\a b -> a * base + b) 0
digitsRev base = unfoldr step
where
step 0 = Nothing
step n = Just $ swap (divMod n base)
primes = sieve [2..] where sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /= 0]
index = zip [1..]
sheldon (n,p) = isProduct && isMirror
where
isProduct = n == product (r10 p)
isMirror = rev p == primes !! (rev n - 1)
rev = unDigits 10 . r10
r10 = digitsRev 10
isPrimeSheldon x = x == snd p && sheldon p
where
p = head $ dropWhile ((x>).snd) (index primes)
sheldonPrimes = map snd $ filter sheldon (index primes)
test = head sheldonPrimes == 73
prop_Sheldon :: Positive Int -> Property
prop_Sheldon (Positive x) = classify (x == 73) "= 73" $
(x == 73) === (isPrimeSheldon x)
main = quickCheck $ withMaxSuccess 100000 prop_Sheldon
@csoroz
Copy link
Author

csoroz commented Jun 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment