We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2642de3 commit 76daf2dCopy full SHA for 76daf2d
collatz-conjecture/src/CollatzConjecture.hs
@@ -1,15 +1,12 @@
1
module CollatzConjecture (collatz) where
2
3
-collatz_internal :: Integer -> Integer
4
-collatz_internal num
5
- | num == 1 = 0
6
- | isEven = 1 + collatz_internal (num `div` 2)
7
- | otherwise = 1 + collatz_internal (3 * num + 1)
8
- where
9
- isEven = rem num 2 == 0
10
-
11
collatz :: Integer -> Maybe Integer
12
collatz num
13
| num > 0 = Just (collatz_internal num)
14
| otherwise = Nothing
+ where
+ collatz_internal pnum
+ | pnum == 1 = 0
+ | even pnum = 1 + collatz_internal (pnum `div` 2)
+ | otherwise = 1 + collatz_internal (3 * pnum + 1)
15
0 commit comments