-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem26.fsx
More file actions
31 lines (23 loc) · 778 Bytes
/
problem26.fsx
File metadata and controls
31 lines (23 loc) · 778 Bytes
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 26
* By Weisi Dai <weisi@x-research.com>
*)
let BASE = 10
let ubound = 1000
let lenOfRecurringCycle denominator =
let rec solve numerator denominator current =
let remainder = (numerator * BASE) % denominator
try
1 + List.findIndex ((=) remainder) current
with
| :? System.Collections.Generic
.KeyNotFoundException -> solve remainder
denominator
(remainder::current)
solve 1 denominator []
let lens = seq {
for i in 1 .. ubound - 1 do
yield i, lenOfRecurringCycle i
}
let problem26 = lens |> Seq.maxBy snd |> fst
let main = printfn "The answer is %d." (problem26)
main