aboutsummaryrefslogtreecommitdiff
path: root/lib/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Utils.hs')
-rw-r--r--lib/Utils.hs17
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 @@
1module Utils where 1module Utils where
2 2
3import Data.Char (digitToInt)
4import Control.Monad 3import Control.Monad
4import Data.Char (digitToInt)
5import Data.Either 5import Data.Either
6import Data.List (inits, tails) 6import Data.List (inits, tails)
7import Data.Map (Map) 7import Data.Map (Map)
8import qualified Data.Map as Map 8import qualified Data.Map as Map
9 9
10binaryToInt :: String -> Int 10binaryToInt :: String -> Int
11binaryToInt = foldl (\a x -> a * 2 + digitToInt x) 0 11binaryToInt = foldl (\a x -> a * 2 + digitToInt x) 0
@@ -18,7 +18,7 @@ xor a b = (not a && b) || (a && not b)
18 18
19right :: Either a b -> b 19right :: Either a b -> b
20right (Right b) = b 20right (Right b) = b
21right _ = undefined 21right _ = undefined
22 22
23bet k (l, u) = k >= l && k <= u 23bet k (l, u) = k >= l && k <= u
24bet' k (l, u) = k > l && k < u 24bet' 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, ...]
60repeatF f = f : map (f .) (repeatF f) 60repeatF f = f : map (f .) (repeatF f)
61 61
62makeGrid :: String -> (Map (Int, Int) Char, Int, Int) 62makeGrid :: String -> (Map (Int, Int) Char, Int, Int)
63makeGrid s = (grid, width, height) where 63makeGrid 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
71egcd :: Int -> Int -> (Int, Int) 71egcd :: Int -> Int -> (Int, Int)
72egcd _ 0 = (1, 0) 72egcd _ 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