test

mail@pastecode.io avatar
unknown
plain_text
a year ago
988 B
2
Indexable
Never
using System.Linq;

static int CalculatePoints(int[] diceValues)
{
    // Check if all dice have the same value
    if (diceValues.All(x => x == diceValues[0]))
    {
        return 4000;
    }

    // Check if all dice are different
    if (diceValues.Distinct().Count() == 6)
    {
        return 2000;
    }

    // Check if three or more dice share one value
    int value = diceValues.GroupBy(x => x).Where(g => g.Count() >= 3).Select(g => g.Key).FirstOrDefault();
    if (value > 0)
    {
        return value == 1 ? 1000 : 100 * value;
    }

    // Otherwise, calculate points for individual dice
    return diceValues.Sum(x => x == 1 ? 100 : x == 5 ? 50 : 0);
}

// Rolls 6 6-faced dice and returns the values in an array
static int[] RollDice()
{
    Random random = new Random();
    return Enumerable.Range(1, 6).Select(i => random.Next(1, 7)).ToArray();
}

int points = CalculatePoints(RollDice());
Console.WriteLine("Points: " + points);