[Haskell-cafe] Code Golf
Sjoerd Visscher
sjoerd at w3future.com
Fri Apr 17 20:48:51 EDT 2009
Hi,
This one works for all 3 examples you gave:
diag = concat . takeWhile (not.null)
. foldr1 (flip $ zipWith (flip (++)) . ([]:))
. map ((++ repeat []) . map (:[]))
or, using Matt Hellige's pointless fun
http://matt.immute.net/content/pointless-fun
diag = foldr1 (zipWith (++) $. id ~> ([]:) ~> id)
$. map (++ repeat []) ~> takeWhile (not.null)
$. (map.map) (:[]) ~> concat
I think the second one is quite readable, thanks to Matt's notation.
The essential part is up front, and the pre- and post-transformations
that belong to each other can be grouped.
greetings,
--
Sjoerd Visscher
sjoerd at w3future.com
More information about the Haskell-Cafe
mailing list