Created
September 7, 2011 22:24
-
-
Save theburningmonk/1201982 to your computer and use it in GitHub Desktop.
ProjectEuler - Problem 40 Solution
This file contains hidden or 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
| // the base sequence of natural numbers | |
| let naturalNumbers = Seq.unfold (fun x -> Some(x, x+1)) 1 | |
| // the decimal fraction 12345678910111213 as a sequence of strings | |
| let fraction = | |
| naturalNumbers | |
| |> Seq.collect (fun x -> x.ToString().ToCharArray() |> Seq.map (fun c -> c.ToString())) | |
| // define function d | |
| let d n = int(fraction |> Seq.nth (n-1)) | |
| let answer = [0..6] |> Seq.map (fun n -> d (pown 10 n)) |> Seq.reduce (fun acc item -> acc * item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment