Advertisement
CamolaZ

AulaP2 PLP

Mar 12th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unitaryN :: Int ->[[Int]]
  2. unitaryN n=[[ if i==j then 1 else 0 |i <- [1..n]]| j<-[1..n]]
  3.  
  4. myNu :: Int -> String
  5. myNu 5 = "Happy Child"
  6. myNu 10 = "Some troubles?"
  7. myNu 17 = "I want to travel"
  8. myNu 20 = "The world is mine"
  9. myNu x = "I do not know this number"
  10.  
  11. age :: Int -> String
  12. age x
  13.    | x<=0 =  "Wrong age!"
  14.    | x< 7 =  "Sweet child"
  15.    | x<18 =  "Youth"
  16.    | otherwise = "Work"
  17.    
  18. disc :: Double -> Double
  19. disc r = pi*r*r
  20.    
  21. disc' r = pi*sq -- We can use prim '  on the name as have disc2 or 1
  22.    where
  23.    sq=r*r
  24.    
  25. disc'' r =
  26.   let
  27.   sq=r*r
  28.   in pi*sq
  29.  
  30. --charN :: Int -> String -> Char
  31. charN n s = s !! (n-1)
  32.  
  33. second (a,b,c) = b
  34. second' (_,b,_) = b
  35.  
  36.  
  37. pair [] _ = (0,0)
  38. pair _ [] = (0,0)
  39. pair x y = (head x, last y)
  40.  
  41. {-
  42. Ex. 2.
  43. =======
  44. Define two lists: listA, listB;
  45. listA is a list of 6 ordered pairs of strings - names and surnames of certain people;
  46. listB consists of two-digit numbers with the digits of tens 3, 5 or 7 and the digits of unity 3 or 4.
  47. a) Define the list named listA1 consisting only of the names from the list listA.
  48. b) Define the list named listA2 consisting only of the surnames from the list listA.
  49. c) Define the list named people - the list of  triples of all possible systems (name, surname, age), where the age is from listB.
  50. -}
  51. listA = [   ("Nicolas", "Mazard") , ("Manuel", "Curral")]
  52.  
  53. listA1' = map fst ListA
  54. listB   = [10*a+b|a<-[3,5,7],b<-[3,4]]
  55. --write ListA2
  56. people = [(n,s,a)| n<-ListA1,s<-ListA2,q<-ListB]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement