Advertisement
biswasrohit20

f####

Jun 9th, 2021
1,771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.61 KB | None | 0 0
  1. // 1a
  2.  
  3. let printList list =
  4.   let rec helper index list =
  5.     match list with
  6.     | [] -> ()
  7.     | head :: tail ->
  8.       printfn "%d.) %A" index head
  9.       helper (index + 1) tail
  10.  
  11.   helper 1 list
  12.  
  13. printList a
  14.  
  15.  
  16.  
  17. //1 c
  18.  
  19. let max2 x y = if x > y then x else y;;
  20.  
  21. let rec getMax xs =
  22.    match xs with
  23.    | [] -> 0
  24.    | [x] -> x
  25.    | x1::x2::xs' -> getMax((max2 x1 x2)::xs')
  26.  
  27.  
  28.  
  29. printfn "%i" ( getMax [9;2;5;23;11;17;6])
  30.  
  31. //3 a
  32.  
  33. let  isNthChar(str:string, n:int, c:char):bool =
  34.     if str.[n] = c  then true
  35.     else false
  36.    
  37. printfn "%b" (isNthChar("rohit", 2, 'h'))
  38.  
  39.  
  40. // 3b
  41.  
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement