-5

Im trying to generate a list of all Numbers bigger than 0 with the following conditions:

  • all elements are odd
  • all elements divide trough 7 without remainder
  • all elements divide trough 9 with remainder 3

e.g. [21,147,273,399,...]

I tried : [x | x <- [1..] , odd x, x / 2 == 0, ... (and here I had problems)

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Mostafa_M
  • 105
  • 7
  • 1
    Have you looked up a tutorial? This is likely covered in *any* comprehension tutorial. – Carcigenicate May 15 '17 at 18:25
  • 3
    I'm voting to close this question as off-topic because there's no clear effort or attempt. StackOverflow is best seen as help with clear-cut bugs and not a from scratch code-writing service or substitute for a tutorial. – Thomas M. DuBuisson May 15 '17 at 18:27
  • Sorry Thomas. I already tried to give my previous attempt, but the system gaved message : "this post does not meet our quality standart". – Mostafa_M May 15 '17 at 20:05
  • if you didn't know about the existence of `mod`, you could've coded it yourself with a list comprehension too! `mod n d == 0` === `last [n, n-d..0] == ??` so `[x | x <- [1..] , odd x, x % 2 == 0]` === `[x | x <- [1..] , odd x, last [n, n-d..0]==??]` === `[x | x <- [1..] , odd x, y <- [n, n-d..0], y==??]`. – Will Ness May 16 '17 at 09:52
  • Here I had problems. Not exactly a helpful problem description. Read about [mcve] – GhostCat May 22 '17 at 02:57

1 Answers1

3

just to get you started a partial answer

[x | x <- [1..], odd x, mod x 7==?, ??? ]

[21,147,273,399,525,651,777,903,1029,1155...]

it can't get simpler than this, just translate your verbal description to code, exactly one to one...

karakfa
  • 66,216
  • 7
  • 41
  • 56
  • hi Karakfa, Thank you for the advice. [x | x <- [1..], odd x, mod x 7==0, mod x 9 == 3 ] works. I didnt know that there are "mod" function in haskell. my previous attempt was : [x | x<- [1..] , odd x, x / 2 == 0, (and here i had the main problems)]. – Mostafa_M May 15 '17 at 20:11
  • @MNazar if you run into problems like you mentioned, why not include them? It makes a huge difference to see what you are struggling with, compared to asking a full fledged solution. I will be glad to help if i see something like your attempt plus the error ghc produces in a future question. – epsilonhalbe May 15 '17 at 22:00