5 > dreiNplusEins :: Integer -> [Integer]
\r
6 > dreiNplusEins 1 = [1]
\r
7 > dreiNplusEins x | (x > 1) && ((mod x 2)== 0) = x : dreiNplusEins (div x 2)
\r
8 > dreiNplusEins x | (x > 1) && ((mod x 2)== 1) = x : dreiNplusEins (x*3+1)
\r
9 > dreiNplusEins _ = []
\r
13 > type UntereGrenze = Integer
\r
14 > type ObereGrenze = Integer
\r
15 > type MaxZykLaenge = Integer
\r
17 > calcmax :: [Integer] -> Integer
\r
18 > calcmax = foldl' (max) 0
\r
20 > maxZyklus :: UntereGrenze -> ObereGrenze -> (UntereGrenze,ObereGrenze,MaxZykLaenge)
\r
21 > maxZyklus m n | (m > n) = (m, n, 0)
\r
22 > maxZyklus m n | otherwise = (m,n, fromIntegral (calcmax (map fromIntegral (map length (map dreiNplusEins [m..n])))))
\r
26 > getValue :: [[Bool]] -> (Integer,Integer) -> Integer
\r
27 > getValue s (m,n) | (n<0) || (m < 0) || (fromIntegral n == length (s !! 0)) || (fromIntegral m == length s) = 0
\r
28 > getValue s (m,n) | ((s !! fromIntegral m) !! fromIntegral n) = 1
\r
29 > getValue s (m,n) | otherwise = 0
\r
31 > anzNachbarn :: [[Bool]] -> (Integer,Integer) -> Integer
\r
32 > anzNachbarn s (m,n) | ((n < 0) || (m < 0) || (fromIntegral n >= length (s !! 0)) || (fromIntegral m >= length s)) = -1
\r
33 > anzNachbarn s (m,n) | otherwise = (getValue s (m-1,n-1))+(getValue s (m-1,n))+(getValue s (m-1,n+1))+(getValue s (m,n-1))+(getValue s (m,n+1))+(getValue s (m+1,n-1))+(getValue s (m+1,n))+(getValue s (m+1,n+1))
\r
37 > trow :: [[Bool]] -> (Integer,Integer) -> [Integer]
\r
38 > trow s (m,0) = anzNachbarn s (m,0):[]
\r
39 > trow s (m,n) = trow s (m,n-1) ++ anzNachbarn s (m,n):[]
\r
41 > tcol :: [[Bool]] -> (Integer,Integer) -> [[Integer]]
\r
42 > tcol s (0,n) = trow s (0,n):[]
\r
43 > tcol s (m,n) = tcol s (m-1,n) ++ trow s (m,n) : []
\r
45 > transform :: [[Bool]] -> [[Integer]]
\r
46 > transform s = tcol s (fromIntegral (length s)-1, fromIntegral(length (s !! 0))-1)