diff options
| author | manuel <manuel@mausz.at> | 2012-03-23 18:56:51 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-23 18:56:51 +0100 |
| commit | 6d7f692ac38f9e2964aed76574c989990f1e573b (patch) | |
| tree | c0c10e9c11490a4d0466b5fbf0d440fdd49d35e7 /AufgabeFFP1.hs | |
| parent | af2639ac7e4bd714fae65fbe17ccb1177f0e2abb (diff) | |
| download | ffp-6d7f692ac38f9e2964aed76574c989990f1e573b.tar.gz ffp-6d7f692ac38f9e2964aed76574c989990f1e573b.tar.bz2 ffp-6d7f692ac38f9e2964aed76574c989990f1e573b.zip | |
implementing fibdiag
Diffstat (limited to 'AufgabeFFP1.hs')
| -rw-r--r-- | AufgabeFFP1.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/AufgabeFFP1.hs b/AufgabeFFP1.hs index 8dd52e1..88d46b4 100644 --- a/AufgabeFFP1.hs +++ b/AufgabeFFP1.hs | |||
| @@ -19,3 +19,22 @@ pof2s = map (2^) [0,1..] | |||
| 19 | -- ... | 19 | -- ... |
| 20 | pd :: [[Integer]] | 20 | pd :: [[Integer]] |
| 21 | pd = iterate (\row -> zipWith (+) ([0] ++ row) (row ++ [0])) [1] | 21 | pd = iterate (\row -> zipWith (+) ([0] ++ row) (row ++ [0])) [1] |
| 22 | |||
| 23 | ------------------------------------------------------------------------------- | ||
| 24 | |||
| 25 | -- steps: | ||
| 26 | -- (1) [pd !! (1-1) !! 0] | ||
| 27 | -- (2) [pd !! (2-1) !! 0] | ||
| 28 | -- (3) [pd !! (3-1) !! 0] ++ [pd !! (3-2) !! 1] | ||
| 29 | -- (4) [pd !! (4-1) !! 0] ++ [pd !! (4-2) !! 1] | ||
| 30 | -- (5) [pd !! (5-1) !! 0] ++ [pd !! (5-2) !! 1] ++ [pd !! (5-3) !! 2] | ||
| 31 | -- (6) [pd !! (6-1) !! 0] ++ [pd !! (6-2) !! 1] ++ [pd !! (6-3) !! 2] | ||
| 32 | -- (7) [pd !! (7-1) !! 0] ++ [pd !! (7-2) !! 1] ++ [pd !! (7-3) !! 2] ++ [pd !! (7-4) !! 3] | ||
| 33 | -- ... | ||
| 34 | -- (n) [pd !! (n-1) !! 0] ++ [pd !! (n-2) !! 1] ++ [pd !! (n-3) !! 2] ++ ... | ||
| 35 | fibdiag :: Integer -> [Integer] | ||
| 36 | fibdiag (n) | ||
| 37 | | n <= 0 = [] | ||
| 38 | | otherwise = map (\x -> pd !! (fromInteger n - x) !! (x - 1)) [1..count] | ||
| 39 | where | ||
| 40 | count = (fromInteger n + 1) `div` 2 | ||
