Compare commits
2 Commits
a45b84ee9c
...
76b85d7d84
Author | SHA1 | Date |
---|---|---|
Sayantan Santra | 76b85d7d84 | |
Sayantan Santra | 01eeffd2a4 |
|
@ -1,5 +1,5 @@
|
|||
import Data.List
|
||||
import System.Random
|
||||
import Data.List (nub)
|
||||
import System.Random (getStdGen, randomRs)
|
||||
|
||||
rndSelect :: [a] -> Int -> IO [a]
|
||||
rndSelect ls n = do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Data.List
|
||||
import System.Random
|
||||
import Data.List (nub)
|
||||
import System.Random (getStdGen, randomRs)
|
||||
|
||||
diffSelect :: Int -> Int -> IO [Int]
|
||||
diffSelect n m = do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Data.List
|
||||
import System.Random
|
||||
import Data.List (nub)
|
||||
import System.Random (getStdGen, randomRs)
|
||||
|
||||
rndPermu :: [a] -> IO [a]
|
||||
rndPermu ls = do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Data.List
|
||||
import Data.List (groupBy, nub, permutations, sortBy)
|
||||
|
||||
group' :: [Int] -> [a] -> [[[a]]]
|
||||
group' ln ls = map ((([([fst] <*>)] <*>) . groupBy grouper . sortBy sorter) . zip ls) (nub (permutations placers))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Data.List
|
||||
import Data.List (sortBy)
|
||||
|
||||
lsort :: [[a]] -> [[a]]
|
||||
lsort = sortBy (\x y -> length x `compare` length y)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
isqrt :: (Integral n) => n -> n
|
||||
isqrt = floor . sqrt . fromIntegral
|
||||
|
||||
isPrime :: (Integral n) => n -> Bool
|
||||
isPrime n = (n >= 2) && all ((/= 0) . (n `mod`)) [2 .. isqrt n]
|
|
@ -0,0 +1,7 @@
|
|||
myGCD :: (Integral n) => n -> n -> n
|
||||
myGCD m n =
|
||||
if remainder == 0
|
||||
then abs n
|
||||
else myGCD n remainder
|
||||
where
|
||||
remainder = m `mod` n
|
|
@ -0,0 +1,10 @@
|
|||
myGCD :: (Integral n) => n -> n -> n
|
||||
myGCD m n =
|
||||
if remainder == 0
|
||||
then abs n
|
||||
else myGCD n remainder
|
||||
where
|
||||
remainder = m `mod` n
|
||||
|
||||
coprime :: (Integral n) => n -> n -> Bool
|
||||
coprime m n = myGCD m n == 1
|
|
@ -0,0 +1,13 @@
|
|||
myGCD :: (Integral n) => n -> n -> n
|
||||
myGCD m n =
|
||||
if remainder == 0
|
||||
then abs n
|
||||
else myGCD n remainder
|
||||
where
|
||||
remainder = m `mod` n
|
||||
|
||||
coprime :: (Integral n) => n -> n -> Bool
|
||||
coprime m n = myGCD m n == 1
|
||||
|
||||
totient :: (Integral n) => n -> n
|
||||
totient m = fromIntegral $ length $ filter (coprime m) [1 .. m - 1]
|
|
@ -0,0 +1,10 @@
|
|||
import Data.List (find)
|
||||
|
||||
isqrt :: (Integral n) => n -> n
|
||||
isqrt = floor . sqrt . fromIntegral
|
||||
|
||||
primeFactors :: (Integral n) => n -> [n]
|
||||
primeFactors n =
|
||||
case find ((== 0) . (n `mod`)) [2 .. isqrt n] of
|
||||
Nothing -> [n]
|
||||
Just m -> m : primeFactors (n `div` m)
|
|
@ -0,0 +1,13 @@
|
|||
import Data.List (find, group)
|
||||
|
||||
isqrt :: (Integral n) => n -> n
|
||||
isqrt = floor . sqrt . fromIntegral
|
||||
|
||||
primeFactors :: (Integral n) => n -> [n]
|
||||
primeFactors n =
|
||||
case find ((== 0) . (n `mod`)) [2 .. isqrt n] of
|
||||
Nothing -> [n]
|
||||
Just m -> m : primeFactors (n `div` m)
|
||||
|
||||
primeFactorsMult :: (Integral n) => n -> [(n, n)]
|
||||
primeFactorsMult = map (\g -> (head g, fromIntegral $ length g)) . group . primeFactors
|
|
@ -0,0 +1,16 @@
|
|||
import Data.List (find, group)
|
||||
|
||||
isqrt :: (Integral n) => n -> n
|
||||
isqrt = floor . sqrt . fromIntegral
|
||||
|
||||
primeFactors :: (Integral n) => n -> [n]
|
||||
primeFactors n =
|
||||
case find ((== 0) . (n `mod`)) [2 .. isqrt n] of
|
||||
Nothing -> [n]
|
||||
Just m -> m : primeFactors (n `div` m)
|
||||
|
||||
primeFactorsMult :: (Integral n) => n -> [(n, n)]
|
||||
primeFactorsMult = map (\g -> (head g, fromIntegral $ length g)) . group . primeFactors
|
||||
|
||||
phi :: (Integral n) => n -> n
|
||||
phi = product . map (\(p, r) -> (p - 1) * p ^ (r - 1)) . primeFactorsMult
|
|
@ -0,0 +1,8 @@
|
|||
isqrt :: (Integral n) => n -> n
|
||||
isqrt = floor . sqrt . fromIntegral
|
||||
|
||||
isPrime :: (Integral n) => n -> Bool
|
||||
isPrime n = (n >= 2) && all ((/= 0) . (n `mod`)) [2 .. isqrt n]
|
||||
|
||||
primesR :: (Integral n) => n -> n -> [n]
|
||||
primesR m n = filter isPrime [m .. n]
|
|
@ -0,0 +1,16 @@
|
|||
import Data.List (find)
|
||||
|
||||
isqrt :: (Integral n) => n -> n
|
||||
isqrt = floor . sqrt . fromIntegral
|
||||
|
||||
isPrime :: (Integral n) => n -> Bool
|
||||
isPrime n = (n >= 2) && all ((/= 0) . (n `mod`)) [2 .. isqrt n]
|
||||
|
||||
goldbach :: (Integral n) => n -> (n, n)
|
||||
goldbach n =
|
||||
if odd n
|
||||
then error "Odd number was given"
|
||||
else (p, n - p)
|
||||
where
|
||||
Just p = find (\p -> (n - p) `elem` primes) primes
|
||||
primes = filter isPrime [2 .. n - 1]
|
|
@ -0,0 +1,22 @@
|
|||
import Data.List (find)
|
||||
|
||||
isqrt :: (Integral n) => n -> n
|
||||
isqrt = floor . sqrt . fromIntegral
|
||||
|
||||
isPrime :: (Integral n) => n -> Bool
|
||||
isPrime n = (n >= 2) && all ((/= 0) . (n `mod`)) [2 .. isqrt n]
|
||||
|
||||
goldbach :: (Integral n) => n -> (n, n)
|
||||
goldbach n =
|
||||
if odd n
|
||||
then error "Odd number was given"
|
||||
else (p, n - p)
|
||||
where
|
||||
Just p = find (\p -> (n - p) `elem` primes) primes
|
||||
primes = filter isPrime [2 .. n - 1]
|
||||
|
||||
goldbachList' :: (Integral n) => n -> n -> n -> [(n, n)]
|
||||
goldbachList' m n d = filter (\(p, q) -> p > d && q > d) $ map goldbach $ filter even [m .. n]
|
||||
|
||||
goldbachList :: (Integral n) => n -> n -> [(n, n)]
|
||||
goldbachList m n = goldbachList' m n 1
|
Loading…
Reference in New Issue