Untitled
unknown
c_cpp
3 years ago
6.4 kB
5
Indexable
using System; namespace testconsole { internal class Program { int correct = 0; int wrong = 0; int number = 1234; public int[] list = new int[9877]; int firstOne; int randomArrayItem; string playerNumber; int cInput1int; int cInput2int; int digit1; int digit2; int digit3; int digit4; bool value = false; public static bool win_; Random rnd = new Random(); static void Main(string[] args) { Program some = new Program(); some.askForNumber(); some.createArray(); some.avoidImposible(); do { some.selectArrayItem(); some.checkForCorrectness(); foreach (int i in some.list) { if (some.list[some.randomArrayItem] != 0) { some.firstOne = some.list[some.randomArrayItem]; some.value = some.compareNumbers(some.firstOne, i, some.cInput1int, some.cInput2int); if (some.value == false) { some.list[i] = 0; if (some.list[i] != 0) { Console.WriteLine("eliminating " + some.list[i]); } } if (some.cInput1int == 4) { win_ = true; } Console.WriteLine(" randomArrayItem: " + some.randomArrayItem + " some.firstone: " + some.list[some.randomArrayItem]); } } } while (win_ is false); } public void createArray() { // Creates array that ranges from 1234-9876 do { list[number] = number; number = number + 1; } while (number < 9877); } public void avoidImposible() { foreach (int i in list) { if (list[i] != 0) { digit1 = list[i] / 1000; digit2 = list[i] - (digit1 * 1000); digit2 = digit2 / 100; digit3 = list[i] - (digit2 * 100 + digit1 * 1000); digit3 = digit3 / 10; digit4 = list[i] - (digit2 * 100 + digit1 * 1000 + digit3 * 10); if (digit1 == 0 || digit2 == 0 || digit3 == 0 || digit4 == 0) { list[i] = 0; } if (digit1 == digit2 || digit1 == digit3 || digit1 == digit4 || digit2 == digit3 || digit2 == digit4 || digit3 == digit4) { list[i] = 0; } } } } public void askForNumber() { Console.WriteLine("Enter your 4 digit number that does not contain 0's or repeating digits: "); playerNumber = Console.ReadLine(); Console.WriteLine("Enter in '{possitive number},{negative number}' form: "); } public void selectArrayItem() { randomArrayItem = rnd.Next(0, list.Length); if (list[randomArrayItem] != 0) { Console.WriteLine(list[randomArrayItem]); } else { selectArrayItem(); } } public void checkForCorrectness() { string correctnessInput = Console.ReadLine(); string cInput1 = ToSplit(correctnessInput, 0); string cInput2 = ToSplit(correctnessInput, 1); int cInput1int = Convert.ToInt32(cInput1); int cInput2int = Convert.ToInt32(cInput2); } string ToSplit(string a, int b) { return a.Split(',')[b]; } bool compareNumbers(int a , int b, int otherCorrect, int otherWrong) { correct = 0; wrong = 0; //compares a to b and checks if otherCorrect and otherWrong is mathching gives true or false int numberDigit1 = (a / 1000); int numberDigit2 = (a - numberDigit1 * 1000) / 100; int numberDigit3 = (a - numberDigit2 * 100 + numberDigit1 * 1000) / 10; int numberDigit4 = (a - numberDigit2* 100 + numberDigit1 * 1000 + numberDigit3 * 10) / 10; int number2Digit1 = (b / 1000); int number2Digit2 = (b - number2Digit1 * 1000) / 100; int number2Digit3 = (b - number2Digit2 * 100 + number2Digit1 * 1000) / 10; int number2Digit4 = (b - number2Digit2 * 100 + number2Digit1 * 1000 + number2Digit3 * 10) / 10; if (numberDigit1 == number2Digit1) { correct++; } if (number2Digit1 == number2Digit2 || numberDigit1 == number2Digit3 || numberDigit1 == number2Digit4) { wrong++; } if (numberDigit2 == number2Digit2) { correct++; } if (numberDigit2 == number2Digit1 || numberDigit2 == number2Digit3 || numberDigit2 == number2Digit4) { wrong++; } if (numberDigit3 == number2Digit3) { correct++; } if (numberDigit3 == number2Digit1 || numberDigit3 == number2Digit2 || numberDigit3 == number2Digit4) { wrong++; } if (numberDigit4 == number2Digit4) { correct++; } if (numberDigit4 == number2Digit1 || numberDigit4 == number2Digit2 || numberDigit4 == number2Digit3) { wrong++; } if (correct == otherCorrect && wrong == otherWrong) { return true; } else { return false; } } } }
Editor is loading...