re: Daily Challenge #53 - Faro Shuffle VIEW POST

FULL DISCUSSION
 

F#:

module FaroShuffle

type Deck = string list

let faroShuffle (deck : Deck) =
    let mid = deck.Length / 2
    [ 0..mid - 1 ]
    |> List.collect (fun i ->
           [ deck.[i]
             deck.[i + mid] ])

Tests:

module FaroShuffleTest

open FsUnit.Xunit
open Xunit
open FaroShuffle

[<Fact>]
let ``6 card deck``() =
    faroShuffle [ "ace"; "two"; "three"; "four"; "five"; "six" ]
    |> should equal [ "ace"; "four"; "two"; "five"; "three"; "six" ]

[<Fact>]
let ``2 card deck``() =
    faroShuffle [ "one"; "two" ] |> should equal [ "one"; "two" ]

[<Fact>]
let ``empty deck``() = faroShuffle [] |> should be Empty

code of conduct - report abuse