Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions exercise.main/Core.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
Expand All @@ -10,23 +12,69 @@ namespace exercise.main
{
public class Core
{

// Note:
// IEnumerable is a class that the List inherits (ie List has all the functionality of IEnumerable)
// IEnumerable allows you to use a foreach loop on the variable hands (which is a List of tuples)

//TODO: complete the winningPair method, without chaning the method signature
public bool winningPair(IEnumerable<Tuple<string, string>> hands, out Tuple<string, string> result)
{
result = new Tuple<string,string>(string.Empty, string.Empty);
public bool winningPair(IEnumerable<Tuple<string, string>> hands, out Tuple<string, string> result) {



result = new Tuple<string, string>(string.Empty, string.Empty);


// your code here...

return result.Item1!=string.Empty ? true : false;
List<Tuple<string, string>> winning_Hands =
hands.Where(hand => hand.Item1 == hand.Item2).ToList();

int current_sum = 0;
int hand_sum = 0;

foreach (var item in winning_Hands)
{
hand_sum = GetValueOfCard(item.Item1) + GetValueOfCard(item.Item2);
if (hand_sum > current_sum)
{
current_sum = hand_sum;
result = item;
}
}

return result.Item1 != string.Empty? true : false;
}

public int GetValueOfCard(string card)
{
return 0;
var card_Values = new Dictionary<string, int>()
{
{ "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}
};

if (card_Values.TryGetValue(card, out int cardValue))
{
return cardValue;

}

return -1;

}
}
}


50 changes: 49 additions & 1 deletion exercise.main/Extension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -11,10 +12,57 @@ public class Extension
//TODO: complete the following method, keeping the signature the same
public bool winningThree(IEnumerable<Tuple<string, string, string>> hand, out Tuple<string, string, string> result)
{
List<Tuple<string, string, string>> winning_Hands =
hand.Where(hand => hand.Item1 == hand.Item2 && hand.Item1 == hand.Item3).ToList();

int current_sum = 0;
int hand_sum = 0;

foreach (var item in winning_Hands)
{
hand_sum = GetValueOfCard(item.Item1) + GetValueOfCard(item.Item2) + GetValueOfCard(item.Item3);
if (hand_sum > current_sum)
{
current_sum = hand_sum;
result = item;
}
}


result = new Tuple<string, string, string>(string.Empty, string.Empty, string.Empty);

return false;
}



public int GetValueOfCard(string card)
{
var card_Values = new Dictionary<string, int>()
{
{ "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}
};

if (card_Values.TryGetValue(card, out int cardValue))
{
return cardValue;

}

return -1;

}
}
}
}