Anonymous user
Sexy primes: Difference between revisions
m
→{{header|Haskell}}
Line 741:
</pre>
Slight variation which only holds on to the display results. Does not perform any better than above though. Both run ~ 250ms.
<lang haskell>
import Control.Lens (makeLenses, over, (^.), to, view)
import Data.Numbers.Primes (isPrime, primes)
import Text.Printf (printf)
data Group a = Group { _count :: Int, _results :: [a] } deriving (Show)
makeLenses ''Group
type Triplet = (Int, [(Int, Int, Int)])▼
type Quad = (Int, [(Int, Int, Int, Int)])▼
type Result = (
, Group Int)
initialGroups = let newGroup = Group 0 []
in (newGroup, newGroup, newGroup, newGroup, newGroup)
| 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 771 ⟶ 773:
n4 = n-24
addPair = over
addTriplet = over
addQuad = over
addQuin = over
addUnSexy = over
main :: IO ()
main = do
let (
where
collectGroups =
=={{header|Java}}==
|