
Shorter, but thing I've done that wasn't just an exercise from a
haskell book.
The problem statement can be found at
http://kernelbob.wordpress.com/2011/03/20/same-five-digits/.
My solution can be seen at http://pastebin.com/iW95q2ex.
Thanks,

On Thu, Mar 31, 2011 at 6:18 PM, Mike Meyer
Shorter, but thing I've done that wasn't just an exercise from a haskell book.
The problem statement can be found at http://kernelbob.wordpress.com/2011/03/20/same-five-digits/.
My solution can be seen at http://pastebin.com/iW95q2ex.
Some quick comments: - Instead of '(== 0) . M.size', use 'M.null'. - Instead of 'putStrLn . show', use 'print'. - Why do you use M.map (head . show)? Why not stick with the numbers? Cheers, -- Felipe.

On Thu, Mar 31, 2011 at 02:18:32PM -0400, Mike Meyer wrote:
Shorter, but thing I've done that wasn't just an exercise from a haskell book.
The problem statement can be found at http://kernelbob.wordpress.com/2011/03/20/same-five-digits/.
My solution can be seen at http://pastebin.com/iW95q2ex.
Looks nice. A few places things could be made a bit more points-free (which isn't always a good thing -- but I think in these cases it makes things more readable, although I suppose that's mostly an issue of what you're used to) (\ s -> length s < 6) ---> ((<6) . length) (etc.) (\ (_, m) -> (== 5) $ M.size m) ---> (==5) . M.size . snd (etc.) If you have a recent enough version of base, (\ (t,m) -> (m,t)) is available as 'swap' in Data.Tuple. This one is slightly more advanced: map (\ (t,m) -> (t, head . M.keys $ M.filter (== '1') m)) can be replaced by (map . second) (head . M.keys . M.filter (== '1')) which applies the function (head . M.keys . M.filter (== '1')) to the second component of every element of a list. The 'second' function is from Control.Arrow, and can be given the type second :: (b -> c) -> (a,b) -> (a,c) (actually its type is a bit more general than that). -Brent
participants (3)
-
Brent Yorgey
-
Felipe Almeida Lessa
-
Mike Meyer