Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created September 7, 2011 22:24
Show Gist options
  • Select an option

  • Save theburningmonk/1201982 to your computer and use it in GitHub Desktop.

Select an option

Save theburningmonk/1201982 to your computer and use it in GitHub Desktop.
ProjectEuler - Problem 40 Solution
// 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