Sha256: 36bb9560affb2038968ac4f47f549b2755f9df74a347a5d39760fdba09b6f545

Contents?: true

Size: 1.59 KB

Versions: 51

Compression:

Stored size: 1.59 KB

Contents

module Yacht

type Category = 
    | Ones
    | Twos
    | Threes
    | Fours
    | Fives
    | Sixes
    | FullHouse
    | FourOfAKind
    | LittleStraight
    | BigStraight
    | Choice
    | Yacht

let private diceWithCount dice = 
    dice
    |> List.countBy id
    |> List.sortByDescending snd

let private valueScore value dice =
    let count = 
        dice 
        |> List.filter ((=) value) 
        |> List.length 
    count * value

let private fullHouseScore dice =
    match diceWithCount dice with
    | [(_, 3); (_, 2)] -> List.sum dice
    | _ -> 0

let private fourOfAKindScore dice =
    match diceWithCount dice with
    | [(value, 4); _] -> value * 4
    | [(value, 5)]    -> value * 4
    | _ -> 0

let private littleStraightScore dice =
    if List.sort dice = [1; 2; 3; 4; 5] then 30 else 0

let private bigStraightScore dice =
    if List.sort dice = [2; 3; 4; 5; 6] then 30 else 0

let private choiceScore dice = 
    List.sum dice

let private yachtScore dice = 
    if dice |> List.distinct |> List.length = 1 then 50 else 0

let score category dice = 
    match category with
    | Ones           -> valueScore 1 dice
    | Twos           -> valueScore 2 dice
    | Threes         -> valueScore 3 dice
    | Fours          -> valueScore 4 dice
    | Fives          -> valueScore 5 dice
    | Sixes          -> valueScore 6 dice
    | FullHouse      -> fullHouseScore dice
    | FourOfAKind    -> fourOfAKindScore dice
    | LittleStraight -> littleStraightScore dice
    | BigStraight    -> bigStraightScore dice
    | Choice         -> choiceScore dice
    | Yacht          -> yachtScore dice

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/yacht/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/yacht/Example.fs