vakho

17.10.13 - Haskell

Oct 17th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-factorial :: Integer -> Integer
  2. factorial n = n * (if (n == 1) then 1 else factorial (n-1))
  3.  
  4. myfactorial 0 = 1
  5. myfactorial n = n * myfactorial(n-1)
  6.  
  7. len [] = 0
  8. len s = 1 + len(tail s)
  9.  
  10. len2 (x:xs) = 1 + len2 xs
  11.  
  12. sum_pair p = fst p + snd p
  13.  
  14. sum_pair2 (x, y) = x + y
  15.  
  16. sum_triple (x, y, z) = x + y + z
  17.  
  18.  
  19. --siis pirveli ori ricxvis shekreba
  20.  
  21. fs xs = head xs + head (tail xs)
  22. fs1 (a:b:cs) = a + b
  23.  
  24. myhead (x:xs) = x
  25. myhead2 (x:_) = x
  26.  
  27. mytail (_:xs) = xs
  28.  
  29.  
  30. func2 [] = 0
  31. func2 (x:y:xs) = x-y + func2 xs
  32.  
  33. square [] = []
  34. square (x:xs) = x*x : square xs-}
  35. --------------------------------------------------------------
  36.  
  37. kenti 0 = []
  38. kenti n =   if (n < 0) then []
  39.         else if ((mod n 2) == 0) then kenti (n-1)
  40.             else n:kenti (n-2)
  41.  
  42. luwi 0 = []
  43. luwi n =    if (n < 0) then []
  44.         else if ((mod n 2) /= 0) then luwi (n-1)
  45.             else n:luwi (n-2)
  46.        
  47. squares 0 = []
  48. squares n = (n*n):squares (n-1)
  49.  
  50. myfactorial 0 = 1
  51. myfactorial n = n * myfactorial(n-1)
  52. factorials 0 = [1]
  53. factorials n = myfactorial(n):factorials(n-1)
  54.  
  55. xarisxebi 0 = [1]
  56. xarisxebi n = 2^n:xarisxebi (n-1)
  57.  
  58. --sashualo (x:xs) = x + sashualo xs
Advertisement
Add Comment
Please, Sign In to add comment