Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
choose n r = product[1..n] `div` product[1..n-r] `div` product[1..r]
ratio=1.2
pass=100
man=800
woman=200
total=man+woman
ii=[0..pass]
male_fem i= if r < ratio then 0 else p
where m=fromIntegral i/ fromIntegral man
w=fromIntegral (pass-i)/fromIntegral woman
r = m/w
a = (choose man i)*(choose woman (pass-i))
b = choose total pass
p = (fromIntegral a) / (fromIntegral b)
main = do
print $ sum ( map male_fem ii)
import Data.Maybe
main :: IO()
main
= putStrLn(show(encode "ABC"))
{-Question 1: Morse Code-}
{-1.1-}
type Morse = [MorseVal]
data MorseVal = DOT | DASH | GAP deriving (Show)
dict :: [(Char, Morse)]
dict
= [('A', m ".-"), ('B', m "-..."), ('C', m "-.-."),
('D', m "-.."), ('E', m "."), ('F', m "..-."),
('G', m "--."), ('H', m "...."), ('I', m ".."),
('J', m ".---"), ('K', m "-.-"), ('L', m ".-.."),
('M', m "--"), ('N', m "-."), ('O', m "---"),
('P', m ".--."), ('Q', m "--.-"), ('R', m ".-."),
('S', m "..."), ('T', m "-"), ('U', m "..-"),
('V', m "...-"), ('W', m ".--"), ('X', m "-..-"),
('Y', m "-.--"), ('Z', m "--..")]
where m = map toWord
toWord '.' = DOT
toWord '-' = DASH
{-1.2-}
encode :: [Char] -> Morse
encode [] = []
encode (x:xs)
= fromJust(lookup x dict) ++ [GAP] ++ encode xs
{-1.3-}
{-Question 2: Suko-}
suko :: [Int] -> [Int]
suko [] = []
suko {-filter???-}
{-Question 3: Transform-}
main :: IO ()
main
= print (Node Tip 100 (Node Tip 200 Tip))
len :: [Int] -> Int
len [] = 0
len (x:xs) = 1 + len xs
contains :: Eq a => [a] -> a -> Bool
contains [] element = False
contains (x:xs) element = if x == element then True else contains xs element
-- set :: [String] -> Bool
-- set [] = True
-- set (x:xs) =
-- if contains xs x then False
-- else set xs
--another way of doing it
set :: [String] -> Bool
set []
= True
set (x:xs)
= not (contains xs x) && set xs
--don't forget it will return true if it gets down to an empty list, else it will return false
nodups :: [Int] -> Bool
nodups []
= True
nodups (x:xs)
= if contains xs x then False
else nodups xs
zipped :: ([a],[b]) -> [(a,b)]
zipped (xs,[]) = []
zipped ([],ys) = []
zipped ((x:xs), (y:ys))
= (x,y) : zipped (xs,ys)
insert :: Int -> [Int] -> [Int]
insert e []
= [e]
insert e (x:xs)
| e > x = x : insert e xs
| otherwise = e : x : xs
sort :: [Int] -> [Int]
sort [] = []
sort (x:xs) = insert x (sort xs)
data Tree
= Tip
| Node Tree Int Tree
deriving show
mirror :: Tree -> Tree
mirror Tip
= Tip
mirror (Node l x r)
= Node (mirror r) x (mirror l)
formulag :: Float -> Float -> Float -> Float
formulag a b c = 2 * a
formulag2 a b c = b * b
formulag3 a b c = 4 * a * c
formulag4 a b c = (sqrt((b*b)-(4*a*c)))/(2*a)
main = do
putStrLn "Formula General"
print(formulag 2.0 5.5 5.0)
print(formulag2 2.0 5.5 5.0)
print(formulag3 2.0 5.5 5.0)
print(formulag4 2.0 58.5 5.0)
main = do
premierMot <- getLine
deuxiemeMot <- getLine
putStr "Le premier mot est "
putStrLn premierMot
putStr "Le second mot est "
putStrLn deuxiemeMot
putStrLn (trouverOrdre premierMot deuxiemeMot)
trouverOrdre :: String -> String -> String
trouverOrdre (premiereLettreMot1:suiteMot1) (premiereLettreMot2:suiteMot2)
| premiereLettreMot1 < premiereLettreMot2 = "Le premier mot est avant le second"
| premiereLettreMot1 > premiereLettreMot2 = "Le second mot est avant le premier"
| premiereLettreMot1 == premiereLettreMot2 = trouverOrdre suiteMot1 suiteMot2