From 4fb1e1e2889b15cbe8a163babc775fa7e56164f3 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 24 Mar 2012 17:12:24 +0100 Subject: add some comments for pd + some whitespaces --- AufgabeFFP1.hs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/AufgabeFFP1.hs b/AufgabeFFP1.hs index 53e5fb7..f1c0e97 100644 --- a/AufgabeFFP1.hs +++ b/AufgabeFFP1.hs @@ -1,20 +1,11 @@ module AufgabeFFP1 where -------------------------------------------------------------------------------- --- Helpers - --- !! Index function for Integer-type -get :: [a] -> Integer -> a -get (x:xs) 0 = x -get (x:xs) n = get xs (n-1) - - ------------------------------------------------------------------------------- -- recursive version pof2s :: [Integer] -pof2s = 1:(map (2*) pof2s) +pof2s = [1] ++ (map (2*) pof2s) -- alternate: -- calculates 2^ with each element of the continuous list @@ -28,8 +19,18 @@ pof2s = 1:(map (2*) pof2s) ------------------------------------------------------------------------------- -- recursive version: +-- (1) [[1]] +-- (2) zipWith (f) [[1]] [[1]] +-- (2) f(x=[1] y=[1]) +-- (2) zipWith (+) ([0,1]) ([1,0]) = [1,1] +-- (2) = [[1,1]] +-- (3) zipWith (f) [[1,1]] [[1,1]] +-- (3) f(x=[1,1] y=[1,1]) +-- (3) zipWith (+) ([0,1,1]) ([1,1,0]) = [1,2,1] +-- (3) = [[1,2,1]] +-- ... pd :: [[Integer]] -pd = [1] : (zipWith (\x y -> zipWith (+) ([0]++x) (y++[0])) pd pd) +pd = [[1]] ++ (zipWith (\x y -> zipWith (+) ([0] ++ x) (y ++ [0])) pd pd) -- alternate: -- pd :: [[Integer]] @@ -57,10 +58,15 @@ pd = [1] : (zipWith (\x y -> zipWith (+) ([0]++x) (y++[0])) pd pd) fibdiag :: Integer -> [Integer] fibdiag n | n <= 0 = [] - | otherwise = map (\x -> pd `get` (n-x) `get` (x-1)) [1..count] + | otherwise = map (\x -> pd `get` (n - x) `get` (x - 1)) [1..count] where count = (n + 1) `div` 2 +-- !! Index function for Integer-type +get :: [a] -> Integer -> a +get (x:xs) 0 = x +get (x:xs) n = get xs (n-1) + ------------------------------------------------------------------------------- fibdiags :: [[Integer]] -- cgit v1.2.3