Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let fb nn =
- // set of all numbers
- let all =
- seq { for i in 1 .. nn do yield i }
- |> Set.ofSeq
- // an ideal of Z ring (Z = field of integers)
- // http://en.wikipedia.org/wiki/Ideal_(ring_theory)
- let nZ n =
- seq { for i in 1 .. nn/n do yield i * n }
- |> Set.ofSeq
- // no buzz, no fizz...
- let onlynormal =
- nZ 3 |> Set.union (nZ 5)
- |> Set.difference all
- |> Set.map (fun x -> (x, x.ToString()))
- // only "fizzes"
- let buzzes =
- nZ 15 |> Set.difference (nZ 3) |> Set.map (fun x -> (x, "Fizz"))
- // only "buzzes"
- let fizzes =
- nZ 15 |> Set.difference (nZ 5) |> Set.map (fun x -> (x, "Buzz"))
- // only "fizzbuzz"
- let buzzfizzes =
- nZ 15 |> Set.map ( fun x -> (x, "FizzBuzz"))
- // result
- onlynormal
- |> Set.union buzzes
- |> Set.union fizzes
- |> Set.union buzzfizzes
- |> Set.toList
- |> List.map (fun x -> snd x)
- // first 99
- printfn "%A" (fb 99)
- // 597 position
- printfn "%s" (fb 600).[597-1]
- // 1200 position
- printfn "%s" (fb 1200).[1200-1]
- // 9995 position
- printfn "%s" (fb 10000).[9995-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement