[Edit 1]:- I have no idea why this question was marked as not focused .I am looking for a scientific proof for correctness or incorrectness of this program . If you cant answer/don't have time to answer , I would really appreciate if you can provide references for further reading.
[Edit 2]:- Problem statement :-
Given a set of positive integer S and an integer K , determine if it
can be split into three disjoint subset , each having sum of its
element as K and they cover S.
Example :- S : {7,3,2,1,5,4,8} and K as 10, Three subsets would be :-
{ 7 , 3} {5,4,1} {8,2}
Here is the link to the 3-way-partition problem. I came up with below solution
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
int[] arr = {7,3,2, 1, 5, 4, 8};
int sum = 10;
int[] visited = new int[arr.Length];
bool v1 = calc(sum, visited, arr);
bool v2 = calc(sum, visited, arr);
bool v3 = calc(sum, visited, arr);
bool v4 = true;
foreach (var item in visited)
{
if (item == 0)
{
v4 = false;
break;
}
}
Console.WriteLine(v1 && v2 && v3 && v4);
}
public static bool calc(int sum, int[] visited, int[] arr)
{
if (sum < 0)
{
return false;
}
if (sum == 0)
{
return true;
}
else
{
for (int i = 0; i < visited.Length; i++)
{
if (visited[i] == 0)
{
visited[i] = 1;
int[] newV = new int[visited.Length];
// Array.Copy(visited, 0, newV, 0, visited.Length);
if (calc(sum - arr[i], visited, arr) == true)
{
return true;
}
else
{
visited[i] = 0;
}
}
}
return false;
}
}
}
My Approach is to solve the problem three times using backtracking and check if I have any elements left in the array that are un-visited. How can I prove if this algorithm is correct
Proving an algorithm incorrect only requires a counter example:
[2,2,1,4,3,3]
If the first call takes [2,2,1], then the remaining calls will fail, because [4,3,3] can't be split two ways.
If the first call takes [4,1], though, then the other two can get [2,3] and [2,3]
Related
E.g. If we have an array [1,2,3,4,6,7,8] then 1 then 2 then 3 then 4 are all consecutive but 6 is not, so that's the first non-consecutive number.
If the whole array is consecutive then return null .
The array will always have at least 2 elements 1 and all elements will be numbers. The numbers will also all be unique and in ascending order. The numbers could be positive or negative and the first non-consecutive could be either too. please help me finish this code i am new in programming. My code:
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2katas
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var input = this.txtInput.Text;
var numarray = input.Split(',');
int firstValue = Convert.ToInt32(numarray[0]);
for (var i = 0; i < numarray.Length; i++)
{
if (Convert.ToInt32(numarray[i]) - i != firstValue)
{
lblPrint.Text = "";
}
else
{
lblPrint.Text = "";
}
if (this.rdbConsecutive.Checked == true)
{
lblKataRunning.Text = "Consecutive";
}
else if (this.rdbStripCleaning.Checked == true)
{
lblKataRunning.Text = "Strip Cleaning";
}
}
}
}
}
Let's extract a method:
Find the first element of an array that is not consecutive ...
If the whole array is consecutive then return null
We can implement it like this:
private static string FirstInconsecutive(string data) {
var array = data.Split(',');
if (array.Length <= 0)
return null; //TODO: what shall we return on empty array?
if (!int.TryParse(array[0], out int delta))
return array[0];
for (int i = 1; i < array.Length; ++i)
if (!int.TryParse(array[i], out int value) || value - i != delta)
return array[i];
return null;
}
Usage:
string result = FirstInconsecutive(txtInput.Text);
Please note int.TryParse which helps to return the right answer "ABC" on an input like "1, 2, 3, ABC, 4, 6, 7, 8" (user input txtInput.Text can contain any string)
A linq solution just for the fun of it:
static int? FindFirstNonConsecutive(IEnumerable<int> arr)
{
var nonConsecutiveInfo =
arr.Select((i, index) => new {Index = index, Delta = i - index})
.FirstOrDefault(t => t.Delta != arr.First());
return nonConsecutiveInfo?.Delta + nonConsecutiveInfo?.Index;
}
Note that this will only work finding non consecutive numbers in ascending order as per requirements.
Two numbers are not consecutive if the left ones + 1 <> the right one.
Check with something like this, note that you have to change your boundary checks:
for (var i = 0; i < numarray.Length - 1; i++)
{
if (Convert.ToInt32(numarray[i]) + 1 != Convert.ToInt32(numarray[i+1]))
Update your condition as below for loop and it will work. I would suggest you to have separate function so that it could be reusable if needed elsewhere in code.
Here start your loop from i = 1 and compare numarray[i-1] + 1 != numarray[i] values.
You can convert your sting[] to int[] with var numarray = input.Split(',').Select(x => Convert.ToInt32(x)).ToArray(); and use it with IsConsecutive(numarray) as per button1_Click code.
You can get first non-consecutive value with minor modification in return type and return statement as shown in GetFirstNonConsecutiveValue().
public bool IsConsecutive(int[] numarray)
{
for (int i = 1; i < numarray.Length; i++)
{
if (numarray[i-1] + 1 != numarray[i])
{
return false;
}
}
return true;
}
public int? GetFirstNonConsecutiveValue(int[] numarray)
{
for (int i = 1; i < numarray.Length; i++)
{
if (numarray[i-1] + 1 != numarray[i])
{
return numarray[i];
}
}
return null;
}
private void button1_Click(object sender, EventArgs e)
{
var input = this.txtInput.Text;
var numarray = input.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
var nonConsecutiveValue = GetFirstNonConsecutiveValue(numarray);
if (nonConsecutiveValue != null)
{
// nonConsecutiveValue is first non consecutive value.
}
else
{
// sequence is consecutive.
}
}
One way to go.
string rawData = "1,2,3,4,6,7,8,9";
IEnumerable<int> data = rawData.Split(',').Select(v => Convert.ToInt32(v));
IEnumerable<int> all = Enumerable.Range(data.Min(), data.Max() - data.Min() + 1);
IEnumerable<int> diff = all.Except(data);
if (diff.Count() == 0)
{
return null;
}
return data.ElementAt(all.ToList().IndexOf(diff.First()))
NB Not thoroughly tested.
Just test diff for being empty to get the numbers are consecutive
I'm working on a hacker rank problem and I believe my solution is correct. However, most of my test cases are being timed out. Could some one suggest how to improve the efficiency of my code?
The important part of the code starts at the "Trie Class".
The exact question can be found here: https://www.hackerrank.com/challenges/contacts
using System;
using System.Collections.Generic;
using System.IO;
class Solution
{
static void Main(String[] args)
{
int N = Int32.Parse(Console.ReadLine());
string[,] argList = new string[N, 2];
for (int i = 0; i < N; i++)
{
string[] s = Console.ReadLine().Split();
argList[i, 0] = s[0];
argList[i, 1] = s[1];
}
Trie trie = new Trie();
for (int i = 0; i < N; i++)
{
switch (argList[i, 0])
{
case "add":
trie.add(argList[i, 1]);
break;
case "find":
Console.WriteLine(trie.find(argList[i, 1]));
break;
default:
break;
}
}
}
}
class Trie
{
Trie[] trieArray = new Trie[26];
private int findCount = 0;
private bool data = false;
private char name;
public void add(string s)
{
s = s.ToLower();
add(s, this);
}
private void add(string s, Trie t)
{
char first = Char.Parse(s.Substring(0, 1));
int index = first - 'a';
if(t.trieArray[index] == null)
{
t.trieArray[index] = new Trie();
t.trieArray[index].name = first;
}
if (s.Length > 1)
{
add(s.Substring(1), t.trieArray[index]);
}
else
{
t.trieArray[index].data = true;
}
}
public int find(string s)
{
int ans;
s = s.ToLower();
find(s, this);
ans = findCount;
findCount = 0;
return ans;
}
private void find(string s, Trie t)
{
if (t == null)
{
return;
}
if (s.Length > 0)
{
char first = Char.Parse(s.Substring(0, 1));
int index = first - 'a';
find(s.Substring(1), t.trieArray[index]);
}
else
{
for(int i = 0; i < 26; i++)
{
if (t.trieArray[i] != null)
{
find("", t.trieArray[i]);
}
}
if (t.data == true)
{
findCount++;
}
}
}
}
EDIT: I did some suggestions in the comments but realized that I can't replace s.Substring(1) with s[0]... because I actually need s[1..n]. AND s[0] returns a char so I'm going to need to do .ToString on it anyways.
Also, to add a little more information. The idea is that it needs to count ALL names after a prefix for example.
Input: "He"
Trie Contains:
"Hello"
"Help"
"Heart"
"Ha"
"No"
Output: 3
I could just post a solution here that gives you 40 points but i guess this wont be any fun.
Make use of Enumerator<char> instead of any string operations
Count while adding values
any charachter minus 'a' makes a good arrayindex (gives you values between 0 and 25)
I think, this link must be very helpfull
There, you can find the good implementation of a trie data structure, but it's a java implementation. I implemented trie on c# with that great article one year ago, and i tried to find solution to an another hackerrank task too ) It was successful.
In my task, i had to a simply trie (i mean my alphabet equals 2) and only one method for adding new nodes:
public class Trie
{
//for integer representation in binary system 2^32
public static readonly int MaxLengthOfBits = 32;
//alphabet trie size
public static readonly int N = 2;
class Node
{
public Node[] next = new Node[Trie.N];
}
private Node _root;
}
public void AddValue(bool[] binaryNumber)
{
_root = AddValue(_root, binaryNumber, 0);
}
private Node AddValue(Node node, bool[] val, int d)
{
if (node == null) node = new Node();
//if least sagnificient bit has been added
//need return
if (d == val.Length)
{
return node;
}
// get 0 or 1 index of next array(length 2)
int index = Convert.ToInt32(val[d]);
node.next[index] = AddValue(node.next[index], val, ++d);
return node;
}
just for fun I am trying to do the change making problem - more or less. My problem is that I get doubled results and through using the debugger I found out that the compiler jumps back into the method again even when it should finish.
private static void Main(string[] args)
{
string temp = Console.ReadLine();
int input;
if (int.TryParse(temp, out input))
{
if(input == 0)
{
System.Environment.Exit(Environment.ExitCode);
}
else
{
ChangeMaking(input);
}
}
else
{
Console.WriteLine("Not a number.");
}
}
private static int ChangeMakingHelper(int input, int euro)
{
return input / euro;
}
static int[] euro = { 1, 2, 5, 10, 20, 50, 100, 200, 500 };
static int counter = 0;
static List<int[]> result = new List<int[]>();
static int[] tempResult = new int[euro.Length];
private static void ChangeMaking(int input)
{
for (int i = euro.Length -1; i >= 0; i--)
{
if(euro[i] <= input)
{
tempResult[i] = ChangeMakingHelper(input, euro[i]);
input = input - euro[i];
if((input % euro[i] != 0))
{
ChangeMaking(input % euro[i]);
}
}
}
result.Add(tempResult);
}
For example if the input is 11 then after the for-loop completes and adding tempResult to result the compiler jumps back into this part:
if((input % euro[i] != 0))
{
ChangeMaking(input % euro[i]);
}
My expected behavior for input 11 would be one array with this values {1, 0, 0, 1, 0, 0, 0, 0, 0} which I get but doubled.
The issue is that you are using static variables to pass data between function calls. Don't do that. Use return values instead.
public static void Main()
{
var result = ChangeMaking(11);
Console.WriteLine(string.Join(", ", result));
}
private static int ChangeMakingHelper(int input, int euro)
{
return input / euro;
}
static readonly int[] euro = { 1, 2, 5, 10, 20, 50, 100, 200, 500 };
private static int[] ChangeMaking(int input)
{
var result = new int[euro.Length];
for (int i = euro.Length -1; i >= 0; i--)
{
if (euro[i] <= input)
{
result[i] += ChangeMakingHelper(input, euro[i]);
input = input - euro[i];
if (input % euro[i] != 0)
{
var tempResult = ChangeMaking(input % euro[i]);
// Transfer the results to the local result array
for(int j = 0; j < result.Length; j++)
result[j] += tempResult[j];
}
// Also add a break statement here so you don't add the lower values twice!
break;
}
}
return result;
}
Fiddle: https://dotnetfiddle.net/7WnLWN
By the way, the reason you ended up with 2 arrays in your output is because you called ChangeMaking recursively, so it got called twice, so it called result.Add(tempResult) twice. Getting rid of the static variables as I have shown above fixes that.
Also, there's probably a more efficient way to do this without recursion, but that would require restructuring your algorithm a bit, so I'll leave that to you to figure out :)
I have a array int[] numArray . I want to know is there any straight forward way to just check whether array has negative numbers in it ?
If there is no direct method even linq will do . I am bit new to linq . Can anyone suggest ?
If you're open to using LINQ:
var containsNegatives = numArray.Any(n => n < 0);
Or, if you want to do it the "old fashioned" way...you just have to loop:
var containsNegatives = false;
foreach(var n in numArray)
{
if(n < 0)
{
containsNegatives = true;
break;
}
}
And if you really want to get fancy, you could turn that into an Extension method:
public static class EnumerableExtensions
{
public static bool ContainsNegatives(this IEnumerable<int> numbers)
{
foreach(n in numbers)
{
if(n < 0) return true;
}
return false;
}
}
And call it from your code like:
var containsNegatives = numArray.ContainsNegatives();
You could use Any:
bool containsNegative = numArray.Any(i => i < 0)
Or
bool containsNegative = numArray.Min() < 0;
EDIT
int[] negativeNumbers = numArray.Where(i => i < 0).ToArray();
var negativeExist = numArray.Any(a => a < 0);
You can use Array.Find(T) method to perform this task.
public static T Find<T>(
T[] array,
Predicate<T> match
)
For example,
using System;
using System.Drawing;
public class Example
{
public static void Main()
{
// Create an array of five Point structures.
Point[] points = { new Point(100, 200),
new Point(150, 250), new Point(250, 375),
new Point(275, 395), new Point(295, 450) };
// To find the first Point structure for which X times Y
// is greater than 100000, pass the array and a delegate
// that represents the ProductGT10 method to the static
// Find method of the Array class.
Point first = Array.Find(points, ProductGT10);
// Note that you do not need to create the delegate
// explicitly, or to specify the type parameter of the
// generic method, because the C# compiler has enough
// context to determine that information for you.
// Display the first structure found.
Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y);
}
// This method implements the test condition for the Find
// method.
private static bool ProductGT10(Point p)
{
if (p.X * p.Y > 100000)
{
return true;
}
else
{
return false;
}
}
}
/* This code example produces the following output:
Found: X = 275, Y = 395
*/
Traditional:
foreach (int number in numArray) { if (number < 0) return true; }
return false;
With LINQ:
bool result = numArray.Any(x => x < 0);
A bit twidling version would be
public static bool AnyNegative(int[] arr){
const long firstBit = 2147483648;
var res = false;
for (var i = 0; i < arr.Length && !res; i++) res = (arr[i] & firstBit) == firstBit;
return res;
}
you can the call it like this>
int arr = {...}
if(arr.AnyNegative()){
//do stuf if there's any negative numbers
}
of course this is just an obfuscated version of
public static bool AnyNegative(int[] arr){
var res = false;
for (var i = 0; i < arr.Length && !res; i++) res = arr[i] < 0;
return res;
}
I'm making a dice game. There are 5 dice in which I have all the values for and I need to determine if they make up a full house (3 of one and 2 of another), small straight (1-4, 2-6 or 3-6) or a large straight (1-5, 2-6).
Perhaps the best way to approach this seems to be to use regular expressions.
Does anyone know how I would go about representing these rules in regex?
Or if you can provide a better solution, I'd appreciate that.
Examples:
Full house = 44422 or 11166 or 12212 etc.
Small Straight = 12342 or 54532 etc.
Large Straight = 12345 or 52643 etc.
Edit
Changed wording to highlight that this is my inexperienced opinion.
I know how to achieve this using code, but it seems like such a long winded solution, I'm wondering if there's a more simplistic approach.
I would order all the numbers decreasing and then do some linear criteria matching on each value as you go along it whether it be in an int[] or a string.
Don't know about c#, but in a scripting language I'd take the regexp route. For each side, calculate how many times it occurs in the combination and join the results together. For example, for the combination 12342 the counter string will be 121100. Then match the counter string against these patterns:
/5/ = Five of a kind
/4/ = Four of a kind
/20*3|30*2/ = Full house
/1{5}/ = Large Straight
/[12]{4}/ = Small Straight
/3/ = Three of a kind
/2[013]*2/ = Two pair
/2/ = One pair
You could always do a LINQ aggregate query and count the number of same cards. It would be something similar to (can't test it):
var query = from card in hand
group card by card into groupedCards
select new { Card = groupedCards.Key, Count = groupedCards.Count() };
This way you would easily know if you are dealing with a possible straight (or nothing at all), a pair, a triple, etc.
I am no LINQ expert and I can not test this bit of code at the moment, so I am not sure if it will compile as it is, but it might help you or give you an idea on how to approach the problem at hand.
For example:
if count query = 5 : We are dealing with an empty hand, a flush or a straight => Run particular flush/straight logic.
if count query = 4 : We are dealing with a single pair.
if count query = 3 : We are dealing with a double pair or a triple => if max count =3 then triple
if count query = 2 : We are dealing with a full house / poker. If max count = 4 then poker
I won't comment on how you seek the results, but rather on how you store the result for later lookup.
Since you have only 46656 possible combinations and one byte can store the resulting hand strength, this problem is much easier than a poker hand problem.
You can have a lookup table, consisting of hands as indexes and associated with results (some hands can have multiple results) of that hand. Each byte can store all hand types as a binary representation (hopefully, if not use a short).
Each number you get (eg. 66655 - full house) is a number in base six (1-6), convert it into a base 10 number to get the index in the lookup table.
It will require about 46656 bytes (+ CPU alignment), and can fit into CPU L2 cache. Speed would be enourmous, since the only operation you would need to do is convert number base, and the binary OR operation to extract a hand strenght.
What you will miss is the real strength of a hand. Eg. 66655 is better than 66644. You can easily figure that out - you will need a bigger type to store result into :)
I decided to try myself, and I ended up not using regular expressions -- I thought maybe with the simplicity of the searches required, regular expressions would add more complexity than they save. I used similar logic to another answer though: count the quantity of each number and base all the scoring on that:
enum RollScoreType
{
HighDie,
Pair,
TwoPair,
ThreeOfAKind,
SmallStright,
PairSmallStriaght,
FullHouse,
LargeStraight,
FourOfAKind,
FiveOfAKind
}
struct RollScore
{
public RollScoreType type;
public byte highestDie;
public byte nextHighestDie;
public RollScore(RollScoreType type, byte highest, byte next)
{
this.type = type;
this.highestDie = highest;
this.nextHighestDie = next;
}
public override string ToString()
{
return string.Format("{0} {1} {2}", type, highestDie, nextHighestDie);
}
}
static RollScore GetDiceScore(string input)
{
char[] dice = input.ToCharArray();
byte[] diceCount = new byte[6];
for (int i = 0; i < dice.Length; i++)
diceCount[int.Parse(dice[i].ToString())-1]++;
if (Array.IndexOf(diceCount, (byte)5) >= 0)
return new RollScore(RollScoreType.FiveOfAKind, (byte)(Array.IndexOf(diceCount, (byte)5) + 1), 0);
else if (Array.IndexOf(diceCount, (byte)4) >= 0)
return new RollScore(RollScoreType.FourOfAKind, (byte)(Array.IndexOf(diceCount, (byte)4) + 1), (byte)(Array.IndexOf(diceCount, (byte)1) + 1));
else if (Array.IndexOf(diceCount, (byte)3) >= 0)
{
byte three = (byte)(Array.IndexOf(diceCount, (byte)3) + 1);
if (Array.IndexOf(diceCount, (byte)2) >= 0)
{
byte pair = (byte)(Array.IndexOf(diceCount, (byte)2) + 1);
return new RollScore(RollScoreType.FullHouse, Math.Max(pair, three), Math.Min(pair, three));
}
else
return new RollScore(RollScoreType.ThreeOfAKind, three, (byte)(Array.LastIndexOf(diceCount, (byte)1) + 1));
}
else if (Array.IndexOf(diceCount, (byte)2) >= 0)
{
byte pair = (byte)(Array.IndexOf(diceCount, (byte)2) + 1);
byte highPair = (byte)(Array.LastIndexOf(diceCount, (byte)2) + 1);
if (highPair != pair)
return new RollScore(RollScoreType.TwoPair, highPair, pair);
else
{
byte lowMissingDie = (byte)Array.IndexOf(diceCount, (byte)0);
byte highMissingDie = (byte)Array.LastIndexOf(diceCount, (byte)0);
switch (lowMissingDie)
{
case 0:
if (highMissingDie == 5)
return new RollScore(RollScoreType.PairSmallStriaght, 5, 4);
if (highMissingDie == 1)
return new RollScore(RollScoreType.PairSmallStriaght, 6, 5);
break;
case 4:
return new RollScore(RollScoreType.PairSmallStriaght, 4, 3);
}
return new RollScore(RollScoreType.Pair, pair, (byte)(Array.LastIndexOf(diceCount, (byte)1) + 1));
}
}
byte missingDie = (byte)Array.IndexOf(diceCount, (byte)0);
switch(missingDie)
{
case 0:
return new RollScore(RollScoreType.LargeStraight, 6, 5);
case 1:
return new RollScore(RollScoreType.SmallStright, 6, 5);
case 4:
return new RollScore(RollScoreType.SmallStright, 4, 3);
case 5:
return new RollScore(RollScoreType.LargeStraight, 5, 4);
default:
return new RollScore(RollScoreType.HighDie, 6, (byte)(Array.LastIndexOf(diceCount, (byte)1, 3) + 1));
}
}
I discovered, to my surprise, that the probability of a small straight and a large straight are equal in 5-die rolls. Is that true!?
EDIT: Fixed; I see that when I include small straights that include a pair, the probability of a small straight goes up significantly.
When I think about it, a pair and a small straight should probably use the pair as the highest die and the highest number in the straight as the next highest (in order to [properly compare two rolls that are both a pair with a small straight). If so, I'd replace the block of code for handling PairSmallStraight with this:
switch (lowMissingDie)
{
case 0:
if (highMissingDie == 5)
return new RollScore(RollScoreType.PairSmallStriaght, pair, 5);
if (highMissingDie == 1)
return new RollScore(RollScoreType.PairSmallStriaght, pair, 6);
break;
case 4:
return new RollScore(RollScoreType.PairSmallStriaght, pair, 4);
}
You could try to put your values in to a list. This would allow you to quickly sort your values. And if you add the values that would give you the hand. 111AA = 29 and 222KK = 30. Just an idea.
Here is my Code:
public static int CalculateTotalOfSingles (int pipNumber)
{
//
var myScore = 0;
foreach (var myDie in Roll5Player.MyHand.Dice)
{
{ if (myDie.Pips == pipNumber)
myScore+= pipNumber;
}
}
//
return myScore;
}
public static int CalculateDicePips ()
{
//
var myScore = 0;
foreach (var myDie in Roll5Player.MyHand.Dice)
{
{myScore += myDie.Pips;
}
}
//
return myScore;
}
//
//
//
public static int CalculateTotalOfAllSingles (int pipNumber)
{
//
var myScore = 0;
for (int i = 1; i <= 6; i++)
{
myScore += pipNumber;
}
//
return myScore;
}
public static bool CalculateIsNOfaKind (int count)
{
//
for (var index = 1; index <= 6; index++)
{
var cntr = 0;
foreach (var myDie in Roll5Player.MyHand.Dice)
{
if (myDie.Pips == index)
cntr++;
}
//
if (cntr == count)
{
return true;
;
}
}
//
return false;
}
public static int CalculateNOfaKind (int count )
{
//
var myScore = 0;
for (var index = 1; index <= 6; index++)
{
var cntr = 0;
foreach (var myDie in Roll5Player.MyHand.Dice)
{
if (myDie.Pips == index)
cntr++;
}
//
if (cntr >= count)
{ myScore = CalculateDicePips();
return myScore;
;
}
}
//
return myScore;
}
///
public static int CaluclateFullHouse ( )
{
//
var myScore = 0;
var cntr = new int[6];
for (var index = 1; index <= 6; index++)
{
foreach (var myDie in Roll5Player.MyHand.Dice)
{
if (myDie.Pips == index)
cntr[index-1]++;
}
}
//
var boolCondA = false;
var boolCondB = false;
foreach (var i in cntr)
{
if (i == 3)
{boolCondA = true;
break;
}
}
if (boolCondA)
{
foreach (var i in cntr)
{
if (i == 2)
{boolCondB = true;
break;
}
}
}
//
if (boolCondB )
myScore = CalculateDicePips();
//
//
//
return myScore;
}
public static int CaluclateStraights (int straightCount, int score)
{
//
var tempPip = 0;
var myScore = 0;
var isFirstIteration = true;
var cntr = 0;
int[] sortedDice = new int[5];
var sortedDiceLise = new List<int>();
foreach (var myDie in Roll5Player.MyHand.Dice)
{
sortedDiceLise.Add(myDie.Pips);
}
sortedDiceLise.Sort();
foreach (var myDie in sortedDiceLise)
{
//
//
if (!isFirstIteration)
{
if (myDie == tempPip + 1)
cntr++;
}
//
isFirstIteration = false;
tempPip = myDie;
}
if (cntr == straightCount - 1)
{myScore = score;
}
//
//
//
return myScore;
}
public static int CalculateYahtzee ()
{
//
for (var index = 1; index <= 6; index++)
{
var cntr = 0;
foreach (var myDie in Roll5Player.MyHand.Dice)
{
if (myDie.Pips == index)
cntr++;
}
//
if (cntr == 5)
{
return 50;
;
}
}
//
return 0;
}