Get out of the pool!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Data.AminoAcid                 -- http://lpaste.net/107071

{--

Sorting lists by lengths.

This is the P28 problem from the P-99 problem set

Say we have the universe of amino acids from before, and a
pool of the following sequences: --}

pool :: [[AcidName]]
pool = [[A, C, D], [E, F], [G, H, I], [E, F], [K, L, M, N], [P, Q], [R]]

-- a) Write a function

lenSort :: [[a]] -> [[a]]
lenSort listolists = undefined

{--

such that child lists are arranged by length:

lenSort pool ~> [[R], [E,F], [E,F], [P,Q], [A,C,D], [G,H,I], [K,L,M,N]]

 --}

-- b) write a function

freqSort :: [[a]] -> [[a]]
freqSort listolists = undefined

{--

such that child lists are arranged by the frequency of their length:

freqSort pool ~> [[K,L,M,N], [R], [A,C,D], [G,H,I], [E,F], [E,F], [P,Q]]

Explanatory comment from the original problem:

"Note that in the above example, the first two lists in the result have 
length 4 and 1, both lengths appear just once. The third and forth list have 
length 3 which appears, there are two list of this length. And finally, the 
last three lists have length 2. This is the most frequent length."

That's it: the ultimate list problem from the P-99 problem set.

Question: what data type developed recently here would allow more-
efficient definitions of the above functions?

A solution is posted at http://lpaste.net/107308

 --}