diff options
Diffstat (limited to 'AufgabeFFP6.hs')
| -rw-r--r-- | AufgabeFFP6.hs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/AufgabeFFP6.hs b/AufgabeFFP6.hs index 1fde756..c60053d 100644 --- a/AufgabeFFP6.hs +++ b/AufgabeFFP6.hs | |||
| @@ -91,22 +91,26 @@ yield_bt f w = map (\(_, _, _, g) -> listArray (1, length g) g) nodes | |||
| 91 | yield_gtf :: F -> W -> [G] | 91 | yield_gtf :: F -> W -> [G] |
| 92 | yield_gtf = filt . transform . generate | 92 | yield_gtf = filt . transform . generate |
| 93 | 93 | ||
| 94 | -- produce [G] by using get_combinations | ||
| 94 | generate :: F -> W -> (F, W, [G]) | 95 | generate :: F -> W -> (F, W, [G]) |
| 95 | generate f w = (f, w, [ array (1,n) entries | entries <- get_combinations n ] ) | 96 | generate f w = (f, w, [ array (1,n) entries | entries <- get_combinations n ] ) |
| 96 | where | 97 | where |
| 97 | n = (snd $ bounds f) - 1 | 98 | n = (snd $ bounds f) - 1 |
| 98 | 99 | ||
| 100 | -- provide all selections of length n, work recursively and attach index for level (convenient for creating arrays) | ||
| 99 | get_combinations :: Int -> [[(Int, Op)]] | 101 | get_combinations :: Int -> [[(Int, Op)]] |
| 100 | get_combinations 1 = [[(1,(+))], [(1, (-))], [(1, (*))], [(1,(./.))]] | 102 | get_combinations 1 = [[(1,(+))], [(1, (-))], [(1, (*))], [(1,(./.))]] |
| 101 | get_combinations n = [ (up i) ++ entr | entr <- get_combinations (n-1), i <- get_combinations 1 ] | 103 | get_combinations n = [ (up i) ++ entr | entr <- get_combinations (n-1), i <- get_combinations 1 ] |
| 102 | where | 104 | where |
| 103 | up = map (\(num, x) -> ((num+n-1), x)) | 105 | up = map (\(num, x) -> ((num+n-1), x)) |
| 104 | 106 | ||
| 107 | -- attaches a list of results | ||
| 105 | transform :: (W -> (F,W,[G])) -> W -> ((F, W, [G]), [W]) | 108 | transform :: (W -> (F,W,[G])) -> W -> ((F, W, [G]), [W]) |
| 106 | transform fun w = ((f, w, g), map (eval f) g ) | 109 | transform fun w = ((f, w, g), map (eval f) g ) |
| 107 | where | 110 | where |
| 108 | (f, w, g) = fun w | 111 | (f, w, g) = fun w |
| 109 | 112 | ||
| 113 | -- take those, where the entry in the result list corresponds to | ||
| 110 | filt :: (W -> ((F,W,[G]),[W]) ) -> W -> [G] | 114 | filt :: (W -> ((F,W,[G]),[W]) ) -> W -> [G] |
| 111 | filt fun w = [ g!!i | i <- [0..n], res!!i == w ] | 115 | filt fun w = [ g!!i | i <- [0..n], res!!i == w ] |
| 112 | where | 116 | where |
