Updated with F# solution