I have an Int that i want to split into it's individual numbers which ideally would be contained in a list, which i can then process further. So i would like something like this:
split 245
--will then get an list containing [2,4,5]
Is anyone familiar with such a function?
import Data.Char
map digitToInt $ show 245
would the example here work for you ? http://snippets.dzone.com/posts/show/5961
convRadix :: (Integral b) => b -> b -> [b]
convRadix n = unfoldr (\b -> if b == 0 then Nothing else Just (b `mod` n, b `div` n))
example:
> convRadix 10 1234
[4, 3, 2, 1]
> convRadix 10 0
[]
> convRadix 10 (-1)
[9,9,...] (infinite)
to convert haskell radix by mokehehe on Thu Aug 21 08:11:39 -0400 2008
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With