Advertisement
Guest User

ocaml/scala PWR

a guest
Oct 17th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.06 KB | None | 0 0
  1. let rec suma lista =
  2.     if lista == [] then float_of_int 0
  3.     else List.hd lista +. suma(List.tl lista);;
  4.  
  5. let sumak (a,b,c,d) = a+.b+.c+.d;;
  6.    
  7. let rec polacz lista sep =
  8.     if lista == [] then ""
  9.     else List.hd lista ^ (if List.tl lista != [] then sep else "") ^ polacz (List.tl lista) sep;;
  10.  
  11. let listaString = ["Ala"; "nigdy"; "nie miała"; "kota"];;
  12.  
  13.  suma [5.;3.;2.];;
  14.  suma [10.1;30.;25.];;
  15.  suma [1.1;2.2;11.1];;
  16.  suma [1.;1.;1.];;
  17.  
  18. sumak (3.,2.,5.,1.);;
  19. sumak (3.5,2.4,5.1,1.3);;
  20. sumak (33.,22.,51.,13.);;
  21. sumak (3.,2.,1.,1.1);;  
  22.  
  23.  polacz ["To"; "jest"; "napis"] "-";;
  24.  polacz ["Ala"; "nigdy"; "nie miała"; "kota"] " | ";;
  25.  polacz ["Każda"; "wichura"; "łamiąc"; "duże"; "drzewa"; "trzciną"; "zaledwie"; "kołysze";] " * ";;
  26.  
  27.  
  28.  
  29. SCALA
  30.  
  31. def mniejsze(list: List[Int], number: Int):Boolean = {
  32.   if(list.head >= number) false;
  33.   else if(list.tail == Nil) true;
  34.   else mniejsze(list.tail, number)
  35. }
  36.  
  37. mniejsze (1::2::3::4::5::Nil,6)
  38. mniejsze (1::2::2::4::5::Nil,8)
  39. mniejsze (1::2::3::46::5::Nil,6)
  40. mniejsze (1::32::3::4::5::Nil,10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement