Haskell list comprehension with two variables -


I am trying to find some special numbers, such that it is divided by 2 is divided by 1, divided by 3 Is 2 and therefore above 6

It works at all.

  [x | X & LT; - [1..1000], x`mode`2 == 1, x`mode` 3 == 2, x`modi4 ==3, x`mode`5 = 4 4x`6 == 5]   

Answer:

  [59,119,179,239,299,359,419,479,539,59 9,659,719,779,839,899,959]   

I try to improve it That's why it is not very active, but the following does not work.

  [x | X & LT; - [1..1000], Y & LT; - [2..6], x `mode` y = y (y-1)]   

It all takes X for which any of the y satisfies the condition Does, but what I want, I want x, which satisfies the condition for all y . >

You can type condition as

  [x | X & LT; - [1..1000], all (\ y -> x` mod` y == y-1) [2 .. 6]]   

but you can Do better in this specific case,

  Module = = 1 LCM Give [2. 6] [x | X & LT; - [1 .. 1000], X` modes modulus == modulus - 1] [modulus - 1, 2 * modulus - 1 .. 1000] - better than    < / Html>

Comments