// Calculate the value of a hand. public static double HandValue(Deck deck) { var val1 = deck.Sum(c => c.Value); var aces = deck.Count(c => c.Suit == "A"); var val2 = aces > 0 ? val1 + (10 * aces) : val1; return(new double[] { val1, val2 } .Select(handValue => new { handValue, weight = Math.Abs(handValue - 21) + (handValue > 21 ? 100 : 0) }) .OrderBy(n => n.weight) .First().handValue); }