[Haskell-cafe] list comprehension doesn't work

John knowledge1202 at gmail.com
Tue May 14 16:57:31 CEST 2013


Hi,

I have to write a function which returns a list of all pairs (x,y) where x,
y ∈ N AND:
–  x is the product of two natural numbers (x = a · b, where a, b ∈ N) AND
–  x is really bigger than 5 but really smaller than 500, AND
–  y is a squer number (y = c² where c ∈ N) NOT greater than 1000, AND
–  x is a divisor of y.

My attempt is as follows:

listPairs :: [(Int, Int)]
listPairs = [(x,y) | x<-[0..], y<-[0..], x<-[0..]*[0..], x > 5, x < 500,
(y*y) < 1001, mod y x == 0]

However it doesn't work unfortunatly 

Could anyone tell me where my mistake is?

Thanks.



--
View this message in context: http://haskell.1045720.n5.nabble.com/list-comprehension-doesn-t-work-tp5730158.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list