vivek828
BAN USERpublic void PathArray()
{
int[,] ipmatrix = new int[4, 4] { { 1,1,0,0 }, { 1,1,1,0}, {0,1,1,0}, { 1,0,1,1} };
int rowlen=ipmatrix.GetLength(0);
int collen=ipmatrix.GetLength(1);
int count = 0;
count= wrapperpatharray(ipmatrix, 0, 0, rowlen, collen);
}
public int wrapperpatharray(int[,] ip,int i,int j, int rowlen, int collen)
{
if (i == rowlen - 1 && j == collen - 1)
{
Console.WriteLine("Pathfound");
return 1;
}
if (i > rowlen - 1 || j > collen - 1)
return 0;
if (ip[i, j] == 0)
return 0;
return( wrapperpatharray(ip, i, j + 1, rowlen, collen)+
wrapperpatharray(ip, i + 1, j, rowlen, collen));
}
public void Dspiral()
{
int[,] ipmatrix = new int[4, 4] { { 1, 5, 3, 2 }, { 2, 8, 4, 0 }, { 3, 7, 1, 9 }, { 5, 2, 8, 6 } };
int rowlength = ipmatrix.GetLength(0);
int columnlength = ipmatrix.GetLength(1);
int chk = 0;
for (int i = 0; i < rowlength; i++)
{
for (int j = 0; j < columnlength; j++)
{
Console.Write(ipmatrix[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine("Spiralled matrix");
for (int i = 0; i < rowlength; i++)
{
if ((chk % 2) == 0)
{
for (int j = 0; j < columnlength; j++)
{
Console.Write(ipmatrix[i, j]);
}
chk++;
}
else
{
for (int j = columnlength - 1; j >= 0; j--)
{
Console.Write(ipmatrix[i, j]);
}
chk++;
}
Console.WriteLine();
}
}
public void ParenthesisDepth(string ip)
{
char[] iparray = ip.ToCharArray();
int buffcount = 0;
int max = 0;
for (int i = 0; i < iparray.Length; i++)
{
if (iparray[i] == '(')
{
buffcount = buffcount + 1;
if (max < buffcount)
{
max = buffcount;
}
}
if (iparray[i] == ')')
{
if (buffcount > 0)
{
buffcount=buffcount-1;
}
else { throw new Exception("Incorrect bracket formation"); }
}
}
Console.WriteLine(max);
}
public bool SudoKuVerfier(int[,] ip)
- vivek828 February 08, 2014{
int i = 0;
int j = 0;
int m = 0;
int rowlen = ip.GetLength(0);
int collen = ip.GetLength(1);
List<int> lst = new List<int>();
while (i < rowlen && j < collen)
{
if (i > 0)
{
m = i - 1;
while (m >= 0)
{
if (!lst.Contains(ip[m, j]))
{
lst.Add(ip[m, j]);
}
else
{
return false;
}
m--;
}
m = i;
while (m < rowlen)
{
if (!lst.Contains(ip[m, j]))
{
lst.Add(ip[m, j]);
}
else
{ return false; }
m++;
}
m = 0;
lst.Clear();
}
if (j > 0)
{
m = j - 1;
while (m >= 0)
{
if (!lst.Contains(ip[i, m]))
{
lst.Add(ip[i, m]);
}
else { return false; }
m--;
}
m = j;
while (m < collen)
{
if (!lst.Contains(ip[i, m]))
{
lst.Add(ip[i, m]);
}
else { return false; }
m++;
}
m = 0;
lst.Clear();
}
i++;
j++;
}
return true;
}