[Haskell-beginners] Iterating through lists

Dananji Liyanage dan9131 at gmail.com
Mon May 18 11:23:41 UTC 2015


Hi All,

I'm building a 9x9 grid like list, and I want to extract each column of
that grid.

My input is a list of integers as follows;

input = [0, 0, 0, 0, 0, 0, 4, 0, 9,
0, 0, 0, 0, 8, 0, 0, 5, 0,
7, 0, 2, 4, 5, 3, 6, 0, 0,
6, 7, 0, 0, 0, 1, 5, 0, 2,
2, 0, 8, 7, 0, 4, 3, 0, 1,
9, 0, 4, 5, 0, 0, 0, 8, 6,
0, 0, 6, 3, 1, 9, 8, 0, 7,
0, 2, 0, 0, 7, 0, 0, 0, 0,
1, 0, 7, 0, 0, 0, 0, 0, 0]

I tried list comprehension with 'take' function in lists as follows;

columns xs = [x | x <- (take 1 xs)] : columns (drop 9 xs) --> columns input

This extracts only the first column. How I can go for the other columns?

-- 
Regards,
Dananji Liyanage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150518/1f465db7/attachment.html>


More information about the Beginners mailing list