private double GetExpectedPrizeExcludingSomeVowelsAndConsonants(ILotteryTicket ticket) { uint numExcludedConsonants = Constants.NumberOfConsonants - (ticket.NumberOfGivenCharacters - NumberOfGivenVowels); uint numExcludedVowels = Constants.NumberOfVowels - NumberOfGivenVowels; List <double> prizes = new List <double>(); List <double> excludedWords = new List <double>(); double totalExcludedWords = 0; foreach (var vCombo in Vowels.GetCombinations(numExcludedVowels)) { var givenVowels = Constants.Vowels.Except(vCombo); foreach (var cCombo in Consonants.GetCombinations(numExcludedConsonants)) { var givenConsonants = Constants.Consonants.Except(cCombo); var allGivenChars = givenVowels.Concat(givenConsonants); var allExcludedChars = vCombo.Concat(cCombo); double prize = ticket.GetPrize(allGivenChars); uint numExcludedWords = ticket.Crossword.CountExcludedWords(allExcludedChars); prizes.Add(prize); excludedWords.Add(numExcludedWords); totalExcludedWords += numExcludedWords; } } return(CalculateExpectedPrize(prizes, excludedWords, totalExcludedWords)); }
public double GetExpectedPrize(ILotteryTicket ticket) { double expectedPrize = 0; double probability = 1.0 / Combinatorics.GetNumberOfCombinations( Constants.AlphabetSize, ticket.NumberOfGivenCharacters); foreach (var combo in Alphabet.GetCombinations(ticket.NumberOfGivenCharacters)) { double prize = ticket.GetPrize(combo); expectedPrize += prize * probability; } return(expectedPrize); }
public double GetExpectedPrize(ILotteryTicket ticket) { if (ticket.NumberOfGivenCharacters == 0) { return(0); } else if (ticket.NumberOfGivenCharacters == Constants.AlphabetSize) { return(ticket.MaxPrize); } uint numExcludedCharacters = Constants.AlphabetSize - ticket.NumberOfGivenCharacters; List <double> prizes = new List <double>(); List <double> excludedWords = new List <double>(); double totalExcludedWords = 0; // For each combination, compute the number of words excluded by the combination and // store its prize. foreach (var combo in Alphabet.GetCombinations(numExcludedCharacters)) { var givenCharacters = Constants.Alphabet.Except(combo); double prize = ticket.GetPrize(givenCharacters); uint numExcludedWords = ticket.Crossword.CountExcludedWords(combo); prizes.Add(prize); excludedWords.Add(numExcludedWords); totalExcludedWords += numExcludedWords; } // Compute the expected prize double expectedPrize = 0; for (int i = 0; i < excludedWords.Count; ++i) { expectedPrize += prizes[i] * (excludedWords[i] / totalExcludedWords); } return(expectedPrize); }
public double GetExpectedPrize(ILotteryTicket ticket) { if (ticket.NumberOfGivenCharacters == 0) { return(0); } else if (ticket.NumberOfGivenCharacters == Constants.AlphabetSize) { return(ticket.MaxPrize); } else if (NumberOfGivenVowels == Constants.NumberOfVowels) { return(GetExpectedPrizeIncludingAllVowels(ticket)); } else if (ticket.NumberOfGivenCharacters - NumberOfGivenVowels == Constants.NumberOfConsonants) { return(GetExpectedPrizeIncludingAllConsonants(ticket)); } else { return(GetExpectedPrizeExcludingSomeVowelsAndConsonants(ticket)); } }
public HomeController(ILogger <HomeController> logger, ILotteryTicket lotteryTicket, ISettingService <LotterySettings> settingService) { _logger = logger; _lotteryTicket = lotteryTicket; _settingService = settingService; }