diff options
| author | manuel <manuel@mausz.at> | 2012-03-24 17:12:24 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-24 17:12:24 +0100 |
| commit | 4fb1e1e2889b15cbe8a163babc775fa7e56164f3 (patch) | |
| tree | 2e1d4160239f77822c4793f08005099848be50b8 | |
| parent | eba9949e83a6ff834c8ebaa68dd136ea005d2351 (diff) | |
| download | ffp-4fb1e1e2889b15cbe8a163babc775fa7e56164f3.tar.gz ffp-4fb1e1e2889b15cbe8a163babc775fa7e56164f3.tar.bz2 ffp-4fb1e1e2889b15cbe8a163babc775fa7e56164f3.zip | |
add some comments for pd + some whitespaces1
| -rw-r--r-- | AufgabeFFP1.hs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/AufgabeFFP1.hs b/AufgabeFFP1.hs index 53e5fb7..f1c0e97 100644 --- a/AufgabeFFP1.hs +++ b/AufgabeFFP1.hs | |||
| @@ -2,19 +2,10 @@ module AufgabeFFP1 | |||
| 2 | where | 2 | where |
| 3 | 3 | ||
| 4 | ------------------------------------------------------------------------------- | 4 | ------------------------------------------------------------------------------- |
| 5 | -- Helpers | ||
| 6 | |||
| 7 | -- !! Index function for Integer-type | ||
| 8 | get :: [a] -> Integer -> a | ||
| 9 | get (x:xs) 0 = x | ||
| 10 | get (x:xs) n = get xs (n-1) | ||
| 11 | |||
| 12 | |||
| 13 | ------------------------------------------------------------------------------- | ||
| 14 | 5 | ||
| 15 | -- recursive version | 6 | -- recursive version |
| 16 | pof2s :: [Integer] | 7 | pof2s :: [Integer] |
| 17 | pof2s = 1:(map (2*) pof2s) | 8 | pof2s = [1] ++ (map (2*) pof2s) |
| 18 | 9 | ||
| 19 | -- alternate: | 10 | -- alternate: |
| 20 | -- calculates 2^ with each element of the continuous list | 11 | -- calculates 2^ with each element of the continuous list |
| @@ -28,8 +19,18 @@ pof2s = 1:(map (2*) pof2s) | |||
| 28 | ------------------------------------------------------------------------------- | 19 | ------------------------------------------------------------------------------- |
| 29 | 20 | ||
| 30 | -- recursive version: | 21 | -- recursive version: |
| 22 | -- (1) [[1]] | ||
| 23 | -- (2) zipWith (f) [[1]] [[1]] | ||
| 24 | -- (2) f(x=[1] y=[1]) | ||
| 25 | -- (2) zipWith (+) ([0,1]) ([1,0]) = [1,1] | ||
| 26 | -- (2) = [[1,1]] | ||
| 27 | -- (3) zipWith (f) [[1,1]] [[1,1]] | ||
| 28 | -- (3) f(x=[1,1] y=[1,1]) | ||
| 29 | -- (3) zipWith (+) ([0,1,1]) ([1,1,0]) = [1,2,1] | ||
| 30 | -- (3) = [[1,2,1]] | ||
| 31 | -- ... | ||
| 31 | pd :: [[Integer]] | 32 | pd :: [[Integer]] |
| 32 | pd = [1] : (zipWith (\x y -> zipWith (+) ([0]++x) (y++[0])) pd pd) | 33 | pd = [[1]] ++ (zipWith (\x y -> zipWith (+) ([0] ++ x) (y ++ [0])) pd pd) |
| 33 | 34 | ||
| 34 | -- alternate: | 35 | -- alternate: |
| 35 | -- pd :: [[Integer]] | 36 | -- pd :: [[Integer]] |
| @@ -57,10 +58,15 @@ pd = [1] : (zipWith (\x y -> zipWith (+) ([0]++x) (y++[0])) pd pd) | |||
| 57 | fibdiag :: Integer -> [Integer] | 58 | fibdiag :: Integer -> [Integer] |
| 58 | fibdiag n | 59 | fibdiag n |
| 59 | | n <= 0 = [] | 60 | | n <= 0 = [] |
| 60 | | otherwise = map (\x -> pd `get` (n-x) `get` (x-1)) [1..count] | 61 | | otherwise = map (\x -> pd `get` (n - x) `get` (x - 1)) [1..count] |
| 61 | where | 62 | where |
| 62 | count = (n + 1) `div` 2 | 63 | count = (n + 1) `div` 2 |
| 63 | 64 | ||
| 65 | -- !! Index function for Integer-type | ||
| 66 | get :: [a] -> Integer -> a | ||
| 67 | get (x:xs) 0 = x | ||
| 68 | get (x:xs) n = get xs (n-1) | ||
| 69 | |||
| 64 | ------------------------------------------------------------------------------- | 70 | ------------------------------------------------------------------------------- |
| 65 | 71 | ||
| 66 | fibdiags :: [[Integer]] | 72 | fibdiags :: [[Integer]] |
