diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..da799a0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet +{ + "name": "C# (.NET)", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm" + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [5000, 5001], + // "portsAttributes": { + // "5001": { + // "protocol": "https" + // } + // } + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "dotnet restore", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/exercise.main/Core.cs b/exercise.main/Core.cs index 7568220..61f6fc6 100644 --- a/exercise.main/Core.cs +++ b/exercise.main/Core.cs @@ -1,32 +1,119 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace exercise.main { + + public class Hand { + private bool isWinning; + + private Tuple values; + + private int score; + + public Hand(Tuple hand) { + values = hand; + score = values.Item1 + values.Item2; + isWinning = checkWinnings(); + } + + private bool checkWinnings() { + if (values.Item1 == values.Item2) + return true; + return false; + } + + public Tuple getSym() { + Dictionary CardValues = new Dictionary + { + { 11, "J"}, + { 12, "Q"}, + { 13, "K"}, + { 14, "A"} + }; + + if(values.Item1 == 11 || values.Item1 == 12 || values.Item1 == 13 || values.Item1 == 14) + return new Tuple(CardValues [values.Item1], CardValues[values.Item2]); + return new Tuple(values.Item1.ToString(), values.Item2.ToString()); + } + + public bool IsWinning + { + get { return isWinning; } + set { isWinning = value; } + } + public Tuple Values + { + get { return values; } + } + public int Score + { + get { return score; } + } + } + public class Core { - + private bool isWinner; //TODO: complete the following method, keeping the signature the same public bool winningPair(IEnumerable> hand, out Tuple result) { - result = new Tuple(string.Empty, string.Empty); - + List hands = new List(); + + foreach (Tuple item in hand) + { + Tuple temp = new Tuple(GetValueOfCard(item.Item1), GetValueOfCard(item.Item2)); + Hand h = new Hand(temp); + hands.Add(h); + } - + int c = 0; + int index = -1; + int score = 0; + foreach (Hand item in hands) + { + if (item.IsWinning) { + if(item.Score > score) { + score = item.Score; + index = c; + } + } + c++; + } - + if (index != -1) + result = hands[index].getSym(); + else + result = new Tuple(String.Empty, String.Empty); return result.Item1!=string.Empty ? true : false; } public int GetValueOfCard(string card) { - return 0; + Dictionary CardValues = new Dictionary + { + {"J", 11}, + {"Q", 12}, + {"K", 13}, + {"A", 14} + }; + + if (CardValues.ContainsKey(card)) + return CardValues[card]; + try { + return Int32.Parse(card); + } catch (Exception e) { + return 0; + } + } } }