evantianx / CodeWars-Haskell

0 stars 0 forks source link

Write Number in Expanded Form #4

Open evantianx opened 5 years ago

evantianx commented 5 years ago

You will be given a number and you will need to return it as a string in Expanded Form. For example:

expandedForm 12    -- Should return '10 + 2'
expandedForm 42    -- Should return '40 + 2'
expandedForm 70304 -- Should return '70000 + 300 + 4'

NOTE: All numbers will be whole numbers greater than 0.

evantianx commented 5 years ago

Solutions

import Data.List(intercalate)

expandedForm :: Int -> String
expandedForm = intercalate " + " . map(\(n, c) -> c : replicate n '0') . reverse . filter((/='0') . snd) . zip [0..] . reverse . show