vakho

Haskell - 28.11.13

Nov 28th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Notebook =     Reminder String Int Int |       -- saxeli, ricxvi, tve
  2.         Tel String Int |            -- saxeli, telefoni
  3.         Meeting Int Int Int String deriving (Eq, Show)  -- ricxvi, tve, saati, shemxvedri
  4.  
  5. -- amocana N1 (gadavcemt saxels - gvibrunebs telefonis nomers)
  6. getTel :: [Notebook] -> String -> Int
  7. getTel [] _ = 0
  8. getTel ((Tel a b):xs) name =    if (a == name) then b
  9.             else getTel xs name
  10. getTel (x:xs) name = getTel xs name
  11.  
  12. -- amocana N2 (gadavcemt saxels - gvibrunebs dabadebis ricxvs da tves)
  13. getDate :: [Notebook] -> String -> [Int]
  14. getDate [] _ = []
  15. getDate ((Reminder a n1 n2):xs) name =  if (a == name) then [n1, n2]
  16.                 else getDate xs name
  17. getDate (x:xs) name = getDate xs name
  18.  
  19. -- amocana N3
  20. getByName :: [Notebook] -> String -> [Int]
  21. getByName [] _ = []
  22. getByName (x:xs) name = if ((getTel (x:xs) name == 0) || (getDate (x:xs) name == [0,0])) then []
  23.             else (getTel (x:xs) name):(getDate (x:xs) name)
  24.  
  25. -- amocana N4 (gadavcemt Char-s - gvibrunebs saxelebs am Char-it dawyebuls)
  26. getByLetter :: [Notebook] -> Char-> [String]
  27. getByLetter [] _ = []
  28. getByLetter (x:xs) chr = case x of
  29.         Reminder y _ _ ->   if (chr == head(y)) then y:getByLetter xs chr
  30.                     else getByLetter xs chr
  31.         Tel y _ ->      if (chr == head(y)) then y:getByLetter xs chr
  32.                     else getByLetter xs chr
  33.         Meeting _ _ _ _ -> getByLetter xs chr
  34.  
  35. {- getNameChar [] n = (-1)
  36. getNameChar (x:xs) 0 = x
  37. getNameChar (x:xs) n = getNameChar xs (n-1) -}
  38.  
  39. -- amocana N5 (gadavcemt ricxvs, tves, saats - gvibrunebs saxels shexvedris + dros)
  40. getMeeting :: [Notebook] -> Int -> Int -> Int -> [(String,[Int])]
  41. getMeeting [] _ _ _ = []
  42. getMeeting ((Meeting n1 n2 n3 name):xs) a b c =
  43.     if ((n1 == a) && (n2 == b) && (n3 == c))
  44.         then (name, [a, b, c]):getMeeting xs a b c
  45.     else getMeeting xs a b c
  46. getMeeting (x:xs) a b c = getMeeting xs a b c
  47.  
  48. -- amocana N6
  49. getReminder :: [Notebook] -> Int -> Int -> [String]
  50. getReminder [] _ _ = []
  51. getReminder ((Reminder name n1 n2):xs) a b =
  52.     if (n1 == a && n2 == b)
  53.         then name:getReminder xs a b
  54.     else getReminder xs a b
  55. getReminder (x:xs) a b = getReminder xs a b
  56.  
  57. -- amocana N7
  58. getTel2 :: [Notebook] -> Int -> [(String, [Int])]
  59. getTel2 [] _ = []
  60. getTel2 ((Reminder name n1 n2):xs) num =
  61.     if (num == getTel ((Reminder name n1 n2):xs) name)
  62.         then (name, [getTel ((Reminder name n1 n2):xs) name]):getTel2 xs num
  63.     else getTel2 xs num
  64. getTel2 (x:xs) num = getTel2 xs num
  65.  
  66. -- amocana N8 (NOT WORKING)
  67. getAssigment :: [Notebook] -> Int -> Int -> Int -> [(String, [Int])]
  68. getAssigment xs a b c = (getMeeting xs a b c) ++ (getTel2 xs getByName)
Advertisement
Add Comment
Please, Sign In to add comment