-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththing.hs
More file actions
47 lines (39 loc) · 1.3 KB
/
thing.hs
File metadata and controls
47 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--import System.Random
irepeat :: (a -> a) -> a -> Int -> a
irepeat f x i = iterate f x !! i
dub :: String -> Char -> String
dub [] c = []
dub (x:xs) c
| x == c = x:x:(dub xs c)
| otherwise = x:(dub xs c)
replace :: [a] -> (Int, Int) -> [a] -> [a]
replace new (lower, upper) list = x ++ new ++ w
where
(x, y) = splitAt lower list
(z, w) = splitAt ((upper - lower)+ 1) y
--found this improvised algorithm at http://stackoverflow.com/questions/21276844/prime-factors-in-haskell
factor :: Int -> [Int]
factor 1 = []
factor n
| factors == [] = [n]
| otherwise = factors ++ factor (n `div` (head factors))
where factors = take 1 $ filter (\x -> (n `mod` x) == 0) [2 .. n-1]
--functions for use in monte carlo
under :: (Double -> Double) -> (Double, Double) -> Bool
under f (x, y) = y < a
where
a = f(x)
--ran :: (Double, Double) -> (Double, Double) -> Int-> (Double, Double)
--ran (mi, ma) (low, high) = (x, y)
--do
--g <- newStdGen
--h <- newStdGen
--where
--(x, t) = randomR (mi, ma) g
--(y, u) randomR (low, high) h
--rans :: (Double, Double) -> (Double, Double) -> Int -> [(Double, Double)]
--monte :: (Double -> Double) -> (Double, Double) -> Double -> IO Double
--monte = do
--let i = 5 :: Double
--r <- random :: IO Double
--let M = max(f(x) | x ∈ [a,b])