
On 4 May 2011 13:13, Barbara Shirtcliff
Hi,
In the following solution to problem 24, why is nub ignored? I.e. if you do lexOrder of "0012," you get twice as many permutations as with "012," even though I have used nub.
[snip]
lexOrder :: [Char] -> [[Char]] lexOrder s | length s == 1 = [s] | length s == 2 = z : [reverse z] | otherwise = concat $ map (\n -> h n) [0..((length s) - 1)] where z = sort $ nub s -- why is the nub ignored here? h :: Int -> [String] h n = map (z!!n :) $ lexOrder $ filter (\c -> lexI c z /= n) z
As a guess, I think it's from the usage of length on the right-hand size. Also, note that "lexOrder s@[_] = [s]" is nicer than "lexOrder s | length s == 1 = [s]". -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com