Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Assignment 2.1 @rahulpawar08 #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
125 changes: 118 additions & 7 deletions Tavisca.Bootcamp.LanguageBasics.Exercise1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,127 @@ static void Main(string[] args)
Console.ReadKey(true);
}

private static void Test(string args, int expected)
{
private static void Test(string args, int expected)
{
var result = FindDigit(args).Equals(expected) ? "PASS" : "FAIL";
Console.WriteLine($"{args} : {result}");
Console.WriteLine($"{args} : {result}");
}

public static int FindDigit(string equation)
{
// Add your code here.
throw new NotImplementedException();
public static int FindDigit(string equation)
{
String[] data1=equation.Split('*');
String[] data2=data1[1].Split('=');
string a = data1[0];
string b = data2[0];
string c = data2[1];
if(containsQM(c))
{
double integerA=Double.Parse(a);
double integerB=Double.Parse(b);
double x = integerA * integerB;
if (!checkValidity(x)) return -1;
else
{
int integerC = Convert.ToInt32(x);
string calculatedC = integerC.ToString();
int i = getQmIndex(c);
if (checkForLeadingZero(c, calculatedC)) return -1;
else
{
for(int j=0;j<calculatedC.Length;j++)
{
if(c[j]!='?')
{
if (c[j] != calculatedC[j])
return -1;
}
}
return (calculatedC[i] - '0'); }
}
}
else if(containsQM(a))
{
double integerB = Double.Parse(b);
double integerC = Double.Parse(c);
double x = integerC / integerB;
if (!checkValidity(x)) return -1;
else
{
int integerA = Convert.ToInt32(x);
string calculatedA = integerA.ToString();
int i = getQmIndex(a);
if (checkForLeadingZero(a, calculatedA)) return -1;
else
{
for (int j = 0; j < calculatedA.Length; j++)
{
if (a[j] != '?')
{
if (a[j] != calculatedA[j])
return -1;
}
}
return (calculatedA[i] - '0');
}
}
}
else
{
double integerA = Double.Parse(a);
double integerC = Double.Parse(c);
double x = integerC / integerA;
if (!checkValidity(x)) return -1;
else
{
int integerB = Convert.ToInt32(x);
string calculatedB = integerB.ToString();
int i = getQmIndex(b);
if (checkForLeadingZero(b, calculatedB)) return -1;
else
{
for (int j = 0; j < calculatedB.Length; j++)
{
if (b[j] != '?')
{
if (b[j] != calculatedB[j])
return -1;
}
}
return (calculatedB[i] - '0');
}
}
}

throw new NotImplementedException();
}
static bool checkValidity(double x)
{
if (((x - (Convert.ToInt32(x))) == 0))
return true;
else
return false;
}
static bool checkForLeadingZero(string givenStr,string calculatedStr)
{
if (givenStr.Length > calculatedStr.Length) return true;
else return false;
}
static int getQmIndex(string s)
{
int i = 0;
for (i = 0; i < s.Length; i++)
{
if (s[i] == '?') break;
}
return i;
}
static bool containsQM(string s)
{
foreach(Char c in s)
{
if (c == '?') return true;
}
return false;
}
}
}