summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-24 17:12:24 +0100
committermanuel <manuel@mausz.at>2012-03-24 17:12:24 +0100
commit4fb1e1e2889b15cbe8a163babc775fa7e56164f3 (patch)
tree2e1d4160239f77822c4793f08005099848be50b8
parenteba9949e83a6ff834c8ebaa68dd136ea005d2351 (diff)
downloadffp-4fb1e1e2889b15cbe8a163babc775fa7e56164f3.tar.gz
ffp-4fb1e1e2889b15cbe8a163babc775fa7e56164f3.tar.bz2
ffp-4fb1e1e2889b15cbe8a163babc775fa7e56164f3.zip
add some comments for pd + some whitespaces1
-rw-r--r--AufgabeFFP1.hs30
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
2where 2where
3 3
4------------------------------------------------------------------------------- 4-------------------------------------------------------------------------------
5-- Helpers
6
7-- !! Index function for Integer-type
8get :: [a] -> Integer -> a
9get (x:xs) 0 = x
10get (x:xs) n = get xs (n-1)
11
12
13-------------------------------------------------------------------------------
14 5
15-- recursive version 6-- recursive version
16pof2s :: [Integer] 7pof2s :: [Integer]
17pof2s = 1:(map (2*) pof2s) 8pof2s = [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-- ...
31pd :: [[Integer]] 32pd :: [[Integer]]
32pd = [1] : (zipWith (\x y -> zipWith (+) ([0]++x) (y++[0])) pd pd) 33pd = [[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)
57fibdiag :: Integer -> [Integer] 58fibdiag :: Integer -> [Integer]
58fibdiag n 59fibdiag 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
66get :: [a] -> Integer -> a
67get (x:xs) 0 = x
68get (x:xs) n = get xs (n-1)
69
64------------------------------------------------------------------------------- 70-------------------------------------------------------------------------------
65 71
66fibdiags :: [[Integer]] 72fibdiags :: [[Integer]]