summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AufgabeFFP1.hs19
-rw-r--r--TestAufgabeFFP1.hs31
2 files changed, 49 insertions, 1 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-- ...
20pd :: [[Integer]] 20pd :: [[Integer]]
21pd = iterate (\row -> zipWith (+) ([0] ++ row) (row ++ [0])) [1] 21pd = 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] ++ ...
35fibdiag :: Integer -> [Integer]
36fibdiag (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
diff --git a/TestAufgabeFFP1.hs b/TestAufgabeFFP1.hs
index e119a3e..7cbc2c2 100644
--- a/TestAufgabeFFP1.hs
+++ b/TestAufgabeFFP1.hs
@@ -26,8 +26,37 @@ pdTests = TestList [pd1]
26 26
27------------------------------------------------------------------------------- 27-------------------------------------------------------------------------------
28 28
29fibdiag1 :: Test
30fibdiag1 = TestCase (assertEqual "fibdiag(1)" [1] (fibdiag 1))
31
32fibdiag2 :: Test
33fibdiag2 = TestCase (assertEqual "fibdiag(2)" [1] (fibdiag 2))
34
35fibdiag3 :: Test
36fibdiag3 = TestCase (assertEqual "fibdiag(3)" [1,1] (fibdiag 3))
37
38fibdiag4 :: Test
39fibdiag4 = TestCase (assertEqual "fibdiag(4)" [1,2] (fibdiag 4))
40
41fibdiag5 :: Test
42fibdiag5 = TestCase (assertEqual "fibdiag(5)" [1,3,1] (fibdiag 5))
43
44fibdiag6 :: Test
45fibdiag6 = TestCase (assertEqual "fibdiag(6)" [1,4,3] (fibdiag 6))
46
47fibdiag7 :: Test
48fibdiag7 = TestCase (assertEqual "fibdiag(7)" [1,5,6,1] (fibdiag 7))
49
50fibdiag8 :: Test
51fibdiag8 = TestCase (assertEqual "fibdiag(8)" [1,6,10,4] (fibdiag 8))
52
53fibdiagTests = TestList [fibdiag1, fibdiag2, fibdiag3, fibdiag4, fibdiag5,
54 fibdiag6, fibdiag7, fibdiag8]
55
56-------------------------------------------------------------------------------
57
29tests :: [Test] 58tests :: [Test]
30tests = [pof2s1, pdTests] 59tests = [pof2s1, pdTests, fibdiagTests]
31 60
32main = do 61main = do
33 forM tests $ \test -> 62 forM tests $ \test ->