Created
August 31, 2010 13:16
-
-
Save nunorc/558997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create a list of four times 1: | |
Main> flip replicate 1 4 | |
[1,1,1,1] | |
Now do it for every element of the list and get a list of lists: | |
Main> map (flip replicate 1) [4,1,3,2] | |
[[1,1,1,1],[1],[1,1,1],[1,1]] | |
Transpose that twice to get the inner lists sorted by number of elements: | |
Main> transpose(transpose(map (flip replicate 1) [4,1,3,2])) | |
[[1,1,1,1],[1,1,1],[1,1],[1]] | |
Now for every element of that list sum the number of elements in the inner list | |
Main> map sum (transpose(transpose(map (flip replicate 1) [4,1,3,2]))) | |
[4,3,2,1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment