Sexy primes: Difference between revisions

m
Line 749:
makeLenses ''Group
 
type ResultGroups = ( Group (Int, Int)
, Group (Int, Int, Int)
, Group (Int, Int, Int, Int)
, Group (Int, Int, Int, Int, Int)
, Group Int )
 
initialGroups :: ResultGroups
initialGroups = let newGroup = Group 0 []
in (newGroup, newGroup, newGroup, newGroup, newGroup)
 
computecollect :: ResultGroups -> Int -> ResultGroups
computecollect r@(pr, tt, qd, qn, un) n
| isPrime n4 && isPrime n3 && isPrime n2 && isPrime n1 = (addPair pr, addTriplet tt, addQuad qd, addQuin qn, un)
| isPrime n3 && isPrime n2 && isPrime n1 = (addPair pr, addTriplet tt, addQuad qd, qn, un)
Line 780:
 
main :: IO ()
main = do
let (pr, tt, qd, qn, un) = collectGroups primes
printf "Number of sexy prime pairs: %d\n Last 5 : %s\n\n" (pr ^. count) (pr ^. results . to (show . reverse))
Line 788:
printf "Number of unsexy primes: %d\n Last 10: %s\n\n" (un ^. count) (un ^. results . to (show . reverse))
where
collectGroups = foldl computecollect initialGroups . takeWhile (< 1000035)</lang>
 
=={{header|Java}}==
Anonymous user