
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

On 18 May 2015 at 13:23, Dananji Liyanage
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?
One easy way would be to first look at the `split` package to find the function `chunksOf` and then simply `Data.List.transpose` the result. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus

On Mon, 18 May 2015 13:23:41 +0200, Dananji Liyanage
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]
Try the function chunksOf of package split[0] Regards, Henk-Jan van Tuyl [0] http://haddocks.fpcomplete.com/fp/7.8/20140916-162/split/Data-List-Split-Int... -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

Thank you all!!
Got it working with Data.List.transpose
On Mon, May 18, 2015 at 5:09 PM, Henk-Jan van Tuyl
On Mon, 18 May 2015 13:23:41 +0200, Dananji Liyanage
wrote: 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]
Try the function chunksOf of package split[0]
Regards, Henk-Jan van Tuyl
[0] http://haddocks.fpcomplete.com/fp/7.8/20140916-162/split/Data-List-Split-Int...
-- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/
http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --
-- Regards, Dananji Liyanage
participants (3)
-
Dananji Liyanage
-
Henk-Jan van Tuyl
-
Magnus Therning