DEV Community

Discussion on: Please help me with this haskell program.

Collapse
gopinathvarad profile image
gopinathvarad

even I want this answer !!

Collapse
benjioe profile image
Benjioe

With Recursion :

dropOdds :: Int -> Int
dropOdds x
    | x >= 10 = 10 * dropOdds restDigits + filterDrops firstDigit
    | otherwise = filterDrops x
    where 
      firstDigit = x `mod` 10
      restDigits = x `div` 10


filterDrops x 
    | x `mod` 2 == 0 = x -- x is even => we keep it
    | otherwise = 0 -- x is drop => we 


main =  do
   print(dropOdds 0)
   print(dropOdds 8)
   print(dropOdds 10)
   print(dropOdds 1357)
Enter fullscreen mode Exit fullscreen mode