Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.63 KB | None | 0 0
  1. def sumuj(list1:List[Int],list2:List[Int])= {
  2.     def sumujR(list1:List[Int],list2:List[Int],acc:List[Int]):List[Int]=
  3.         (list1,list2) match {
  4.         case (Nil,Nil) => acc
  5.         case (hd1::tl1,hd2::tl2) => sumujR(tl1,tl2,((hd1+hd2)::acc))
  6.         case (hd1::tl1,Nil) => sumujR(tl1,Nil,(hd1::acc))
  7.         case (Nil,hd2::tl2) => sumujR(Nil,tl2,(hd2::acc))
  8.         }
  9.     sumujR(list1,list2,Nil)
  10. }
  11.  
  12. def sumujR(list1:List[Int],list2:List[Int]):List[Int]=
  13.         (list1,list2) match {
  14.         case (hd1::tl1,hd2::tl2) => (hd1+hd2)::sumujR(tl1,tl2)
  15.         case (hd1::tl1,Nil) => hd1::sumujR(tl1,Nil)
  16.         case (Nil,hd2::tl2) => hd2::sumujR(Nil,tl2)
  17.         case (Nil,Nil) => Nil
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement