Browse Source

Add the teacher anagram function

DricomDragon 5 years ago
parent
commit
a4e3b799fc
1 changed files with 5 additions and 1 deletions
  1. 5 1
      anagram.hs

+ 5 - 1
anagram.hs

@@ -3,7 +3,11 @@ import Data.List
 sweep::(String -> [String]) -> String -> String -> [String]
 sweep f l stack = case stack of
 	[] -> [l]
-	cur:substack -> concat [map (\l -> cur:l) (f (delete cur l)), sweep f l substack]
+	cur:substack -> concat [map (\xs -> cur:xs) (f (delete cur l)), sweep f l substack]
 
 ana::String -> [String]
 ana l = sweep (ana) l l
+
+-- Teacher version
+anac "" = [""]
+anac xs = concat (map (\c -> map (c:) (anac (delete c xs))) xs)