Advertisement
Guest User

FizzBuzz in F# v3.0 using Match pattern

a guest
Jul 14th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.67 KB | None | 0 0
  1. // FizzBuzz version using match pattern
  2. let fb nn =
  3.  
  4.     // get string associated with value
  5.     let inline s n =
  6.  
  7.         // tuple if number is multiple of 3 and/or of 5
  8.         let inline t v =
  9.             (v % 3 = 0, v % 5 = 0)
  10.  
  11.         // what case is?
  12.         match (t n) with
  13.         | (true,false) -> "Fizz"
  14.         | (false,true) -> "Buzz"
  15.         | (true,true) -> "FizzBuzz"
  16.         | _ -> n.ToString()
  17.  
  18.  
  19.     // List of all strings
  20.     List.map s [1..nn]
  21. // --------------------------------------
  22.  
  23. // examples
  24. // first 100
  25. printfn "%A" (fb 100)
  26.  
  27. // WARNING: Over a 1.000.000 values!!!!
  28. printfn "%A" (fb 1000000 |> Array.ofList).[40999..41099]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement