From 36780319f32e3d08e094dba3b270d7c43203a782 Mon Sep 17 00:00:00 2001 From: Anders Hagen Ottersland Date: Wed, 14 Aug 2024 10:04:34 +0200 Subject: [PATCH] tasks done, except the extras --- exercise.main/Core.cs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/exercise.main/Core.cs b/exercise.main/Core.cs index bf5077d..2a86bc9 100644 --- a/exercise.main/Core.cs +++ b/exercise.main/Core.cs @@ -9,7 +9,24 @@ namespace exercise.main { public class Core - { + { + private Dictionary _cardValues = new Dictionary + { + {"1",1}, + {"2",2}, + {"3",3}, + {"4",4}, + {"5",5}, + {"6",6}, + {"7",7}, + {"8",8 }, + {"9",9}, + {"10",10}, + {"J",11}, + {"Q",12}, + {"K",13}, + {"A",14} + }; // Note: // IEnumerable is a class that the List inherits (ie List has all the functionality of IEnumerable) @@ -19,14 +36,25 @@ public class Core public bool winningPair(IEnumerable> hands, out Tuple result) { result = new Tuple(string.Empty, string.Empty); + int bestScore = 0; - // your code here... + foreach (var hand in hands) + { + if (hand.Item1 == hand.Item2) + { + if (GetValueOfCard(hand.Item1) > bestScore) + { + result = hand; + bestScore = GetValueOfCard(hand.Item1); + } + } + } - return result.Item1!=string.Empty ? true : false; + return result.Item1 != string.Empty ? true : false; } public int GetValueOfCard(string card) { - return 0; + return _cardValues[card]; } } }