Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. \begin{code}
  2. import qualified Data.Char as Char
  3. data Tree = L | T(Int, Tree, Tree)
  4.  
  5.  
  6.  
  7. getAllKeys [] = []
  8. getAllKeys ((x, n):xs)= x:(getAllKeys xs)
  9.  
  10. biggestValue [] val = val
  11. biggestValue ((x, n):xs) val = if(val < n) then (biggestValue xs n)
  12. else (biggestValue xs val)
  13.  
  14. getMaxValueKey ((x, n):xs) = (getMaxValueKeyCompute ((x, n):xs) (biggestValue ((x, n):xs) 0))
  15.  
  16. getMaxValueKeyCompute ((x, n):xs) val = if(val == n) then x
  17. else (getMaxValueKeyCompute xs val)
  18.  
  19. firstWord (x:xs) = (firstWordCompute (x:xs) 0)
  20. firstWordCompute (x:xs) flag = if(flag == 0 && x == ' ') then (firstWordCompute xs 0)
  21. else if(flag == 0 && x /= ' ') then x:(firstWordCompute xs 1)
  22. else if(flag == 1 && x /= ' ') then x:(firstWordCompute xs 1)
  23. else []
  24. firstWordCompute [] 1 = []
  25. firstWordCompute [] 0 = []
  26.  
  27.  
  28. formatSentence (x:xs) = (formatSentenceCompute (x:xs) 0)
  29. formatSentenceCompute (x:xs) flag = if(flag == 0 && x == ' ') then (formatSentenceCompute xs 0)
  30. else if(flag == 0 && x /= ' ') then x:(formatSentenceCompute xs 1)
  31. else if(flag == 1 && x == ' ') then x:(formatSentenceCompute xs 2)
  32. else if(flag == 1 && x /= ' ') then x:(formatSentenceCompute xs 1)
  33. else if(flag == 2 && x /= ' ') then x:(formatSentenceCompute xs 1)
  34. else (formatSentenceCompute xs 2)
  35. formatSentenceCompute [] 1 = []
  36. formatSentenceCompute [] 0 = []
  37. formatSentenceCompute [] 2 = []
  38.  
  39.  
  40. formatText (x:xs) = (formatTextCompute (x:xs) 0)
  41. formatTextCompute (x:xs) flag = if(flag == 0 && x /= ' ') then (Char.toUpper x):(formatTextCompute xs 1)
  42. else if(flag == 0 && x == ' ') then x:(formatTextCompute xs 0)
  43. else if(flag == 1 && x /= ' ') then x:(formatTextCompute xs 1)
  44. else x:(formatTextCompute xs 0)
  45. formatTextCompute [] 1 = []
  46. formatTextCompute [] 0 = []
  47.  
  48. my_map f [] = []
  49. my_map f (x:xs) = (f x):(my_map f xs)
  50.  
  51.  
  52. dropit (x:xs) = (dropCompute (x:xs) 1)
  53. dropCompute [] 1 = []
  54. dropCompute [] 2 = []
  55. dropCompute (x:xs) flag = if(flag == 1) then x:(dropCompute xs 2)
  56. else (dropCompute xs 1)
  57.  
  58.  
  59. sumit L = 0
  60. sumit (T(k,left,right)) = (k + (sumit left) + (sumit right))
  61.  
  62. replaceAll [] charC charR = []
  63. replaceAll (x:xs) (y:ys) (g:gs) = if(x == y) then g:(replaceAll xs (y:ys) (g:gs))
  64. else x:(replaceAll xs (y:ys) (g:gs))
  65.  
  66.  
  67. isPower2 x = if(x `mod` 2 == 0 && x < 6 || x == 1) then True
  68. else if(x `mod` 2 == 1 && x < 6) then False
  69. else (isPower2 (x `div` 2))
  70.  
  71. dropitp (x:xs) = (dropComputep (x:xs))
  72.  
  73. dropComputep [] = []
  74. dropComputep (x:xs) = if(isPower2 x) then (dropComputep xs)
  75. else x:(dropComputep xs)
  76.  
  77. getElement [] val = val
  78. getElement (x:xs) val = (getElement xs x)
  79.  
  80. functie [] = []
  81. functie (x:xs) = if((getElement x ' ') == 'a') then 1:(functie xs)
  82. else 0:(functie xs)
  83. pairSum [] = 0
  84. pairSum ((x,y):xs) = ((x*y) + (pairSum xs))
  85.  
  86.  
  87. formatText2 (x:xs) = (formatTextCompute2 (x:xs) 0)
  88. formatTextCompute2 (x:xs) flag = if(flag == 0 && x /= ' ') then (toEnum(fromEnum x - 32)::Char):(formatTextCompute2 xs 1)
  89. else if(flag == 0 && x == ' ') then x:(formatTextCompute2 xs 0)
  90. else if(flag == 1 && x /= ' ') then x:(formatTextCompute2 xs 1)
  91. else x:(formatTextCompute2 xs 0)
  92. formatTextCompute2 [] 1 = []
  93. formatTextCompute2 [] 0 = []
  94. \end{code}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement