From af2639ac7e4bd714fae65fbe17ccb1177f0e2abb Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 23 Mar 2012 17:44:30 +0100 Subject: implement pd --- AufgabeFFP1.hs | 16 ++++++++++++++++ TestAufgabeFFP1.hs | 12 +++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/AufgabeFFP1.hs b/AufgabeFFP1.hs index eb9d1fc..8dd52e1 100644 --- a/AufgabeFFP1.hs +++ b/AufgabeFFP1.hs @@ -1,5 +1,21 @@ module AufgabeFFP1 where +-- calculates 2^ with each element of the continuous list pof2s :: [Integer] pof2s = map (2^) [0,1..] + +-- alternate: +-- pof2s :: [Integer] +-- pof2s = iterate (2*) 1 + +------------------------------------------------------------------------------- + +-- iterate steps: +-- (1) [1] +-- (2) zipWith (+) ([0,1]) ([1,0]) = [1,1] +-- (3) zipWith (+) ([0,1,1]) ([1,1,0]) = [1,2,1] +-- (4) zipWith (+) ([0,1,2,1]) ([1,2,1,0]) = [1,3,3,1] +-- ... +pd :: [[Integer]] +pd = iterate (\row -> zipWith (+) ([0] ++ row) (row ++ [0])) [1] diff --git a/TestAufgabeFFP1.hs b/TestAufgabeFFP1.hs index 1380c17..e119a3e 100644 --- a/TestAufgabeFFP1.hs +++ b/TestAufgabeFFP1.hs @@ -16,8 +16,18 @@ pof2sTests = TestList [pof2s1] ------------------------------------------------------------------------------- +pd1 :: Test +pd1 = TestCase (assertEqual "pd" [[1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1], + [1,5,10,10,5,1], [1,6,15,20,15,6,1], [1,7,21,35,35,21,7,1], + [1,8,28,56,70,56,28,8,1], [1,9,36,84,126,126,84,36,9,1], + [1,10,45,120,210,252,210,120,45,10,1]] (take 11 pd)) + +pdTests = TestList [pd1] + +------------------------------------------------------------------------------- + tests :: [Test] -tests = [pof2s1] +tests = [pof2s1, pdTests] main = do forM tests $ \test -> -- cgit v1.2.3