Write a program in the Haskell Language to finds ALL twin pr

Write a program in the Haskell Language to finds ALL twin primes and display them in tuples in a list. Such as [(3,5),(5,7),(11, 13),...]

Solution

Ans

x:: Integer -> Bool

y:: Integer -> Bool

areTwoApart (x,y) = y - x == 2

Prelude> take 10 $ filter areTwoApart (zip allprimes (tail allprimes))

It will give you first ten prime twins

Or

main=putStrLn.(!!)
[show n++\", \"++show(n+2)|n<-[2..],all((>0).rem n)[2..n-1],all((>0).rem(n+2))[2..n]].(+)(-1)=<<readLn

Write a program in the Haskell Language to finds ALL twin primes and display them in tuples in a list. Such as [(3,5),(5,7),(11, 13),...]SolutionAns x:: Integer

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site