diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Utils.hs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/Utils.hs b/lib/Utils.hs index e0f9d62..d74a7bf 100644 --- a/lib/Utils.hs +++ b/lib/Utils.hs | |||
@@ -1,11 +1,11 @@ | |||
1 | module Utils where | 1 | module Utils where |
2 | 2 | ||
3 | import Data.Char (digitToInt) | ||
4 | import Control.Monad | 3 | import Control.Monad |
4 | import Data.Char (digitToInt) | ||
5 | import Data.Either | 5 | import Data.Either |
6 | import Data.List (inits, tails) | 6 | import Data.List (inits, tails) |
7 | import Data.Map (Map) | 7 | import Data.Map (Map) |
8 | import qualified Data.Map as Map | 8 | import qualified Data.Map as Map |
9 | 9 | ||
10 | binaryToInt :: String -> Int | 10 | binaryToInt :: String -> Int |
11 | binaryToInt = foldl (\a x -> a * 2 + digitToInt x) 0 | 11 | binaryToInt = foldl (\a x -> a * 2 + digitToInt x) 0 |
@@ -18,7 +18,7 @@ xor a b = (not a && b) || (a && not b) | |||
18 | 18 | ||
19 | right :: Either a b -> b | 19 | right :: Either a b -> b |
20 | right (Right b) = b | 20 | right (Right b) = b |
21 | right _ = undefined | 21 | right _ = undefined |
22 | 22 | ||
23 | bet k (l, u) = k >= l && k <= u | 23 | bet k (l, u) = k >= l && k <= u |
24 | bet' k (l, u) = k > l && k < u | 24 | bet' k (l, u) = k > l && k < u |
@@ -57,7 +57,7 @@ rotate (x, y) t = (nx, ny) | |||
57 | ny = x*sin(pi*t/180) + y*cos(pi*t/180) | 57 | ny = x*sin(pi*t/180) + y*cos(pi*t/180) |
58 | 58 | ||
59 | -- [f, f.f, f.f.f, ...] | 59 | -- [f, f.f, f.f.f, ...] |
60 | repeatF f = f : map (f .) (repeatF f) | 60 | repeatF f = f : map (f .) (repeatF f) |
61 | 61 | ||
62 | makeGrid :: String -> (Map (Int, Int) Char, Int, Int) | 62 | makeGrid :: String -> (Map (Int, Int) Char, Int, Int) |
63 | makeGrid s = (grid, width, height) where | 63 | makeGrid s = (grid, width, height) where |
@@ -66,7 +66,7 @@ makeGrid s = (grid, width, height) where | |||
66 | width = length (head rows) | 66 | width = length (head rows) |
67 | height = length rows | 67 | height = length rows |
68 | 68 | ||
69 | -- number theory | 69 | -- number theory |
70 | 70 | ||
71 | egcd :: Int -> Int -> (Int, Int) | 71 | egcd :: Int -> Int -> (Int, Int) |
72 | egcd _ 0 = (1, 0) | 72 | egcd _ 0 = (1, 0) |
@@ -92,3 +92,4 @@ chineseRemainder ls = | |||
92 | modulii = map snd ls | 92 | modulii = map snd ls |
93 | modPI = product modulii | 93 | modPI = product modulii |
94 | crtModulii = (modPI `div`) <$> modulii | 94 | crtModulii = (modPI `div`) <$> modulii |
95 | |||