-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem13.fsx
31 lines (24 loc) · 853 Bytes
/
problem13.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(* Project Euler Problem 13
* By Weisi Dai <[email protected]>
*)
let ubound = 10
let numbers = System.IO.File.ReadLines "problem13.data"
|> Seq.map (fun str -> str.Substring(0, ubound + 1))
|> Seq.map int64
|> Array.ofSeq
(*
* I wanted to use parallel aggregation so it would be
* quicker than summing linearly.
*
let add x y = x + y
let rec sum = function
| [| x |] -> x
| [| x; y |] -> add x y
| longArr -> let len = longArr.Length
let mid = len / 2
add (longArr.[0 .. mid] |> sum)
(longArr.[mid + 1 .. len - 1] |> sum)
*)
let problem13 = (Seq.sum numbers).ToString().Substring(0, ubound)
let main = printfn "The answer is %s." (problem13)
main