Pregunta

Problem- max number which is divisible by 13 and 7 between 0-100.

i am trying to write a code in Haskell for checking divisibility for 13 and 7. I am able to write for 13 but not able to check for 7 in the same code.

lard :: (Integral a) => a  
lard = head ( filter p[100,99..]) 
    where p x   = x `mod` 13 == 0 
¿Fue útil?

Solución

You can use && to check for both conditions. The overall evaluation is true only if both the operands are true. This operator exists for many (C-like) languages

Like:

lard :: (Integral a) => a  
lard = head ( filter p[100,99..]) 
    where p x   = (x `mod` 13 == 0) && (x `mod` 7 == 0)

Warning: There might be better ways of doing this. I just stepped into the world of Haskell. :)

Otros consejos

module Division where divisibility :: [Int] -> [String] divisibility (x:xs) = map show([if xmod13 == 0 && xmod7 == 0 then "divideby13and7" else if xmod13 == 0 then "divideby13" else if xmod7 == 0 then "divideby7" else show(x)| x<-x:xs]

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top