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.
Tutorialspoint

定員100で男子800人女子200人が受験して合格率の男女比1.2

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)

Compile and Execute Haskell Online

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-}

Compile and Execute Haskell Online

main :: IO()
main = putStrLn(show(trans [[1,2,3],[4,5,6],[7,8,9]]))

applist :: [ a ] -> [ a ] -> [ a ]
applist xs [] = xs
applist [] ys = ys
applist (x:xs) ys = x : applist xs ys

revlist :: [ a ] -> [ a ]
revlist [] = []
revlist (x:xs) = applist (revlist xs) [ x ]

pam :: [ (a->b) ] -> a -> [ b ]
pam [] y = []
pam (x:xs) y = x y : pam xs y

concatlist :: [ [ a ] ] -> [ a ]
concatlist = foldr (++) []

sumlist :: [ Int ] -> Int
sumlist = foldr (+) 0

trans :: [ [ Int ] ] -> [ [ Int ] ]
trans ([]:xss) = []
trans xss = map head xss : trans (map tail xss) 

Lab 1

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)

Haskell Formula General

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)

haskell01

main = print $ "Hello, world!"

safediv:: Float->Float->Maybe Float
safediv = error"TODO: safediv"

formula:: Float->Float->Maybe Float
formula = error"TODO:formula"

haskell01

main = print $ "Hello, world!"

safediv:: Float->Float->Maybe Float
safediv = error"TODO: safediv"

alphabetique

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

Maximo 3 numeros

x :: Integer
y :: Integer
z :: Integer
x = 12
y = 5
z=1

main = print $ (max x (max y z))

Compile and Execute Haskell Online

xs::[Integer]
xs=[2,3,4]

main = do
print (tail xs ++ [head xs])

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.