Created
December 5, 2011 12:23
-
-
Save mnzk/1433423 to your computer and use it in GitHub Desktop.
Project Euler 26 by F# Ver.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// https://gist.github.com/1430157#file_euler26.fs の改良(高速化)版 | |
#light | |
let reccuringLength d = | |
let rec loop i dict n = | |
let r = n % d | |
match Map.tryFind r dict with | |
| Some j -> i - j | |
| None -> loop (i+1) (Map.add r i dict) (r * 10) | |
loop 0 Map.empty 1 | |
let euler26 n = | |
let rec loop d dMax lenMax = | |
if lenMax >= d then | |
dMax | |
else | |
let len = reccuringLength d | |
if len > lenMax then | |
loop (d-1) d len | |
else | |
loop (d-1) dMax lenMax | |
loop n 0 0 | |
printfn "%d" (euler26 999) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment