Advertisement
ElfikCo

f# lab 1

Mar 9th, 2022
2,870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.07 KB | None | 0 0
  1. exception UJEMNY_ARGUMENT ;;
  2.  
  3. let rec ( ^^ ) b p =
  4.     if p = 0 then 1
  5.     elif p < 0 then -1
  6.     else b * (b ^^ (p - 1))
  7.  
  8. let rec suma m n =
  9.     if n = 0 then m
  10.     elif n > 0 then m + n + suma m (n - 1)
  11.     else raise UJEMNY_ARGUMENT
  12.  
  13. let tylkoMaleLitery s =
  14.     Array.forall(fun el -> System.Char.ToLower el = el) (Seq.toArray s)
  15.  
  16. let rec mRn m n =
  17.     if n = 0 then 0
  18.     elif n = 1 then m
  19.     elif n > 0 then m + mRn m (n - 1)
  20.     else raise UJEMNY_ARGUMENT
  21.  
  22. let rec wystOdItego (str: string, i, ch) =
  23.     if str = "" then 0
  24.     elif i <= str.Length then 0
  25.     elif (str.Substring i).StartsWith ch then 1 + wystOdItego (str.Substring 1) 0 ch
  26.     else -1
  27.  
  28.  
  29. [<EntryPoint>]
  30. let main _ =
  31.     printf "^^: %d %d %d\n" (2 ^^ 4) (2 ^^ 0) (2 ^^ -1)
  32.     printf "suma: %d %d %d\n" (suma 2 4) (suma 2 0) (suma 2 -1)
  33.     printf "tylkoMaleLitery abc %b Abc %b '' %b" (tylkoMaleLitery "abc") (tylkoMaleLitery "Abc") (tylkoMaleLitery "")
  34.     printf "\nmRn %d %d %d %d" (mRn 4 5) (mRn 4 0) (mRn 4 1) (mRn -4 2)
  35.     printf "\nwystOdItego %d" (wystOdItego "abccab" 2 "a")
  36.     0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement