changeset 28:e0ae5d8b55d3

there was no solution here.
author Markus Kaiser <markus.kaiser@in.tum.de>
date Thu, 10 Jan 2013 14:04:09 +0100
parents a316877ed3d9
children 53732b9605c7
files exercises/src/Exercise_11.hs
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/exercises/src/Exercise_11.hs	Wed Jan 09 21:00:13 2013 +0100
+++ b/exercises/src/Exercise_11.hs	Thu Jan 10 14:04:09 2013 +0100
@@ -26,15 +26,23 @@
 {- Aufgabe G11.1 -}
 
 safeUnscrambleWord :: [String] -> String -> Either (String, [String]) String
-safeUnscrambleWord vocabs word
-        | word `elem` vocabs = Right word
-        | otherwise = Left (word,
-                filter (\v -> sort v == sorted) vocabs)
-        where sorted = sort word
+safeUnscrambleWord vocabs word = undefined
 
 
 safeUnscrambleWords :: [String] -> [String] -> [Either (String, [String]) String]
-safeUnscrambleWords vocabs words = map (safeUnscrambleWord vocabs) words
+safeUnscrambleWords vocabs words = undefined
+
+{- Musterlösung H7.2 -}
+unscrambleWord :: [String] -> String -> String
+unscrambleWord vocabs word
+  | word `elem` vocabs = word
+  | otherwise =
+    case find (\vocab -> sort vocab == sort word) vocabs of
+      Nothing -> word
+      Just vocab -> vocab
+
+unscrambleWords :: [String] -> [String] -> [String]
+unscrambleWords = map . unscrambleWord