[Haskell-cafe] How to devide matrix into small blocks

Daniel Fischer daniel.is.fischer at web.de
Thu Jun 14 15:26:09 EDT 2007


What about

blocks w h = concatMap transpose . map (map (chop w)) . chop h

?

@L. Guo: 
map concat . blocks w h

is what you want.

Cheers,
Daniel

Am Donnerstag, 14. Juni 2007 09:42 schrieb Janis Voigtlaender:
> Anyway, as a challenge to others on the list: write a one-liner that
> splits an "image" like ["abcd","efgh","ijkl","mnop"], interpreted as
>
> abcd
> efgh
> ijkl
> mnop
>
> into the list of images:
>
> [
> ab
> ef
> ,
> cd
> gh
> ,
> ij
> mn
> ,
> kl
> op
> ]
>
> for (w,h)=(2,2), into:
>
> [
> a
> e
> ,
> b
> f
> ,
> c
> g
> ,
> d
> h
> ,
> i
> m
> ,
> j
> n
> ,
> k
> o
> ,
> l
> p
> ]
>
> for (w,h)=(1,2), and so on.
>
> (Where an image like
>
> ab
> ef
>
> is represented as ["ab","ef"].)
>
> Have fun, Janis.



More information about the Haskell-Cafe mailing list