|
@@ -2,6 +2,7 @@ module Utils where
|
|
|
import Data.Function
|
|
import Data.Function
|
|
|
import Data.Maybe
|
|
import Data.Maybe
|
|
|
import Data.List
|
|
import Data.List
|
|
|
|
|
+ import Data.Char
|
|
|
|
|
|
|
|
(|>) = (&)
|
|
(|>) = (&)
|
|
|
|
|
|
|
@@ -11,6 +12,12 @@ module Utils where
|
|
|
| i == 0 = car l
|
|
| i == 0 = car l
|
|
|
| otherwise = cdr l >>= \x -> x !? (i-1)
|
|
| otherwise = cdr l >>= \x -> x !? (i-1)
|
|
|
|
|
|
|
|
|
|
+ c2i :: Char -> Maybe Int
|
|
|
|
|
+ c2i c = if cv < 48 || cv > 57
|
|
|
|
|
+ then Nothing
|
|
|
|
|
+ else Just (cv - 48)
|
|
|
|
|
+ where cv = ord c
|
|
|
|
|
+
|
|
|
car :: [a] -> Maybe a
|
|
car :: [a] -> Maybe a
|
|
|
car [] = Nothing
|
|
car [] = Nothing
|
|
|
car [x] = Just x
|
|
car [x] = Just x
|
|
@@ -193,3 +200,8 @@ module Utils where
|
|
|
go' d (x:xs)
|
|
go' d (x:xs)
|
|
|
| d == tD = x
|
|
| d == tD = x
|
|
|
| otherwise = go' (dateNextDay d) xs
|
|
| otherwise = go' (dateNextDay d) xs
|
|
|
|
|
+
|
|
|
|
|
+ factorial :: Integer -> Integer
|
|
|
|
|
+ factorial 0 = 0
|
|
|
|
|
+ factorial 1 = 1
|
|
|
|
|
+ factorial x = x * factorial (x-1)
|