[Haskell-cafe] Code Golf
miguelimo38 at yandex.ru
Wed Apr 15 07:42:57 EDT 2009
What it should be?
Sebastian Fischer wrote on 15.04.2009 15:28:
>> Prelude> let diag = concat . diags where diags ((x:xs):xss) = [x] :
>> zipWith (:) xs (diags xss)
> this has a different semantics on finite lists, so I should add a test
> *Main> diag [[1,2,3],[4,5,6],[7,8,9]]
> Your version yields [1,2,4,3,5,7].
> Actually, there are a number of implementations that implement the same
> behaviour as the original version, e.g.,
> diag = concat . foldr diags 
> where diags  ys = ys
> diags (x:xs) ys = [x] : merge xs ys
> merge  ys = ys
> merge xs@(_:_)  = map (:) xs
> merge (x:xs) (y:ys) = (x:y) : merge xs ys
> I'd be interested if one can *derive* from the original version a
> simpler version using clever pointfree combinators.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe