Advertisement
Guest User

Array F# 2

a guest
Jul 11th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.59 KB | None | 0 0
  1.         let swA = new System.Diagnostics.Stopwatch()
  2.         let swB = new System.Diagnostics.Stopwatch()
  3.         let arr = [| 1 .. 1800 |]
  4.  
  5.         swA.Start()
  6.         let mutable sum1 = 0
  7.         for i in 0 .. 1799 do
  8.             sum1 <- sum1 + i * arr.[i]
  9.         done
  10.         swA.Stop()
  11.  
  12.         swB.Start()
  13.         let fProdSum arr = arr |> Array.mapi (fun i j -> i * j) |> Array.sum
  14.         let sum2 = fProdSum arr
  15.         swB.Stop()
  16.  
  17.         printfn "Results: %d %d" sum1 sum2
  18.         printfn "Time elapsed Mine: %A" swA.Elapsed
  19.         printfn "Time elapsed His: %A" swB.Elapsed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement