File tree 1 file changed +10
-4
lines changed 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 1
1
module Math where
2
2
3
- hcf :: Int -> Int -> Int
3
+ fibs :: [Int ] -- Fibonacci sequence
4
+ fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
5
+
6
+ fib :: Int -> Int -- Fibonacci number
7
+ fib n = fibs !! n
8
+
9
+ hcf :: Int -> Int -> Int -- Highest common factor
4
10
hcf 0 y = y
5
11
hcf x y
6
12
| x < 0 = hcf (negate x) y
7
13
| x <= y = hcf x (y - x)
8
14
| otherwise = hcf y x
9
15
10
- lb :: Int -> Maybe Int
16
+ lb :: Int -> Maybe Int -- Binary logarithm, rounded down
11
17
lb 1 = Just 0
12
18
lb x
13
19
| x > 1 = fmap (+ 1 ) $ lb (div x 2 )
14
20
| otherwise = Nothing
15
21
16
- lbRnd :: Int -> Maybe Int
22
+ lbRnd :: Int -> Maybe Int -- Binary logarithm, rounded nearest
17
23
lbRnd 1 = Just 0
18
24
lbRnd x = let
19
25
m :: Floating b => Int -> b
@@ -23,7 +29,7 @@ lbRnd x = let
23
29
in
24
30
if fmap ((fromIntegral x)< ) (mid x) == Just True then lb x else lbMax x
25
31
26
- lbMax :: Int -> Maybe Int
32
+ lbMax :: Int -> Maybe Int -- Binary logarithm, rounded up
27
33
lbMax 1 = Just 0
28
34
lbMax x
29
35
| mod x 2 == 0 = fmap (+ 1 ) $ lbMax (div x 2 )
You can’t perform that action at this time.
0 commit comments