Mercurial > 12ws.info2
annotate exercises/src/Exercise_5.hs @ 12:8496af3b866b
add G5.3 and G5.4 definitions
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Wed, 14 Nov 2012 19:13:22 +0100 |
parents | a721abd5a135 |
children | 8cc37c82619c |
rev | line source |
---|---|
11 | 1 module Exercise_5 where |
2 import Data.Maybe | |
3 | |
4 {- Library DO NOT CHANGE -} | |
5 type State = Integer | |
6 type DA = (State, State -> Char -> State, State -> Bool) | |
7 type ListDA = (State, [((State, Char), State)], [State]) | |
8 | |
9 a :: DA | |
10 a = (0, delta, (==1)) | |
11 where | |
12 delta 0 'a' = 1 | |
13 delta 1 'a' = 1 | |
14 delta 2 'a' = 1 | |
15 delta 0 'b' = 2 | |
16 delta 1 'b' = 2 | |
17 delta 2 'b' = 2 | |
18 | |
19 toDA :: ListDA -> DA | |
20 toDA (start, delta, final) = (start, deltaFun delta, (`elem` final)) | |
21 where deltaFun dl = curry (fromMaybe 0 . flip lookup dl) | |
22 {- End Library -} | |
23 | |
24 | |
25 {---------------------------------------------------------------------} | |
26 {- Aufgabe G5.1 -} | |
27 | |
28 iter :: Int -> (a -> a) -> a -> a | |
29 iter n f x = undefined | |
30 | |
31 | |
32 pow :: Int -> Int -> Int | |
33 pow n k = undefined | |
34 | |
35 | |
36 drop' :: Int -> [a] -> [a] | |
37 drop' n xs = undefined | |
38 | |
39 | |
40 replicate' :: Int -> a -> [a] | |
41 replicate' n x = undefined | |
42 | |
43 | |
44 | |
45 {---------------------------------------------------------------------} | |
46 {- Aufgabe G5.2 -} | |
47 | |
48 partition_rec :: (a -> Bool) -> [a] -> ([a], [a]) | |
49 partition_rec p xs = undefined | |
50 | |
51 | |
12
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
52 partition_foldr :: (a -> Bool) -> [a] -> ([a], [a]) |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
53 partition_foldr p xs = undefined |
11 | 54 |
55 | |
56 partition_filter :: (a -> Bool) -> [a] -> ([a], [a]) | |
57 partition_filter p xs = undefined | |
58 | |
59 | |
60 zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] | |
61 zipWith' f xs ys = undefined | |
62 | |
63 | |
64 | |
65 {---------------------------------------------------------------------} | |
12
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
66 {- Aufgabe G5.3 -} |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
67 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
68 lambda_1 = (\xs -> foldr (++) [] (map (\x -> [x]) xs)) |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
69 lambda_2 = (\gg xx yy -> head (tail (zipWith gg [ xx , xx ] [ yy , yy ]))) |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
70 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
71 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
72 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
73 {---------------------------------------------------------------------} |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
74 {- Aufgabe G5.4 -} |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
75 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
76 zeros :: [Int] |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
77 zeros = 0 : zeros |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
78 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
79 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
80 length' :: [a] -> Int |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
81 length' [] = 0 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
82 length' (_:xs) = 1 + length' xs |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
83 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
84 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
85 h :: Integer -> Integer -> Integer |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
86 h m n |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
87 | m == n = 0 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
88 | m < n = h m (n - 1) |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
89 | m >= n = h n m + 1 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
90 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
91 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
92 |
8496af3b866b
add G5.3 and G5.4 definitions
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
11
diff
changeset
|
93 {---------------------------------------------------------------------} |
11 | 94 {- Aufgabe H5.1 -} |
95 | |
96 fixpoint :: (a -> a -> Bool) -> (a -> a) -> a -> a | |
97 fixpoint = undefined | |
98 | |
99 | |
100 cents :: [Integer] -> [Integer] | |
101 cents = undefined | |
102 | |
103 | |
104 trancl :: [(Integer, Integer)] -> [(Integer, Integer)] | |
105 trancl = undefined | |
106 | |
107 | |
108 | |
109 {---------------------------------------------------------------------} | |
110 {- Aufgabe H5.2 -} | |
111 | |
112 advance :: DA -> State -> String -> State | |
113 advance = undefined | |
114 | |
115 | |
116 prop_advance_empty :: ListDA -> State -> Bool | |
117 prop_advance_empty = undefined | |
118 | |
119 | |
120 prop_advance_single :: ListDA -> State -> Char -> Bool | |
121 prop_advance_single = undefined | |
122 | |
123 | |
124 prop_advance_concat :: ListDA -> State -> String -> String -> Bool | |
125 prop_advance_concat = undefined | |
126 | |
127 | |
128 accept :: DA -> String -> Bool | |
129 accept = undefined | |
130 | |
131 | |
132 reachableStates :: DA -> State -> [Char] -> [State] | |
133 reachableStates = undefined | |
134 | |
135 | |
136 | |
137 {---------------------------------------------------------------------} | |
138 {- Aufgabe H5.3 -} | |
139 | |
140 {-WETT-} | |
141 quasiSubseq :: Eq a => [a] -> [a] -> Bool | |
142 quasiSubseq xs ys = undefined | |
143 {-TTEW-} |