[Haskell-cafe] Code Golf
sebf at informatik.uni-kiel.de
Wed Apr 15 06:32:21 EDT 2009
Fancy some Codegolf?
I wrote the following function for list diagonalization:
> diag l = foldr (.) id ((sel l . flip sel) ((:).(:))) 
> sel = foldr (\a b c -> id : mrg (a c) (b c)) (const ) . map
> mrg  ys = ys
> mrg xs  = xs
> mrg (x:xs) (y:ys) = (x.y) : mrg xs ys
Self explanatory, isn't it? Here is a test case:
*Main> take 10 $ diag [[ (m,n) | n <- [1..]] | m <- [1..]]
I was trying to golf it down [^1] but my brain explodes. If you
succeed in reducing keystrokes, I'd be happy to know!
More information about the Haskell-Cafe