Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
newMultQ working on more2
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using ShuffleExtension; using System.Threading; using System.Data; using MathSpace; using CountExtension; namespace Rextester { public class Program { public int ratio1; public int ratio2; public int ratio3; public int num1, num2, num3; public static void Main(String[] args){ //makeMixedNum(); //LCM(12,10,5); //LCM3Q(); //makeDeciQ(); //simultQ(); //makeDivQ3by2(); //addSub3Q(); //makeOpQ(); //RandomDie(); // makeMultQ(2,10,2,10); //addSubQ(); //simult4x4(); //simult3x3(); // quadSeq(); newDivQ(); //MultDiv(); //newMultQ(); /*for (int a = 11; a<101; a++) { for (int b = 2; b<10; b++) { int c = a/b; if (a%b==0 && a/b>10) Console.WriteLine(c); } }*/ //makeDivQ2by1(); } public static void quadSeq() { int a, b, c; int count =0; while (count<10) { a = Rand.NextPM(1,5); b = Rand.NextPM(1,6); c = Rand.NextPM(1,10); if (a==1) { Console.Write("n^2 "+b+"n "+c+" = "); } else if (a==-1) { Console.Write("-n^2 "+b+"n "+c+" = "); } else Console.Write(a+"n^2 "+b+"n "+c+" = "); for (int n=1; n<6; n++) { Console.Write(a*n*n+b*n+c+", "); } Console.WriteLine(); count++; } } public static void simult3x3() { double[] c = new double[12]; int limit = 50; double x, y, z; int count = 0; while (count<1) { for (int i = 0; i<c.Length; i++) { c[i] = Rand.NextPM(1,10); } /* c[0] = 2; c[1] = 1; c[2] = -1; c[3] = 5; c[4] = 3; c[5] = -1; c[6] = 2; c[7] = -1; c[8] = 1; c[9] = -1; c[10] = -1; c[11] = 0; // c[0] = 1; c[1] = -3; c[2] = 3; c[3] = -4; c[4] = 2; c[5] = 3; c[6] = -1; c[7] = 15; c[8] = 4; c[9] = -3; c[10] = -1; c[11] = 19; */ x = ( (c[10]*c[5]-c[6]*c[9])*(c[6]*c[3]-c[2]*c[7]) - (c[6]*c[1]-c[2]*c[5])*(c[10]*c[7]-c[6]*c[11]) ) / ( (c[10]*c[5]-c[6]*c[9])*(c[6]*c[0]-c[2]*c[4]) - (c[6]*c[1]-c[2]*c[5])*(c[10]*c[4]-c[6]*c[8]) ); y = ((c[6]*c[3]-c[2]*c[7]) - (c[6]*c[0]-c[2]*c[4])*x ) / (c[6]*c[1]-c[2]*c[5]); z = (c[3] - c[0]*x - c[1]*y ) / c[2]; if ((x%1==0.5 || x%1==0) && (y%1==0.5 || y%1==0) && (z%1==0.5 || z%1==0) && Math.Abs(x)<limit && Math.Abs(y)<limit && Math.Abs(z)<limit) { for (int i = 0; i <c.Length; i++) { //num[i] = Rand.NextPM(1,10); Console.Write(c[i]+ " "); if ((i+1)%4==0 && i>0) { Console.WriteLine(); } } Console.WriteLine(); Console.WriteLine("x, y, z = {0}, {1}, {2}", x,y,z); Console.WriteLine(); count++; } } } public static void simult4x4() { double a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4,e1,e2,e3,e4; double w,x,y,z; int count = 0; int limit = 50; while (count<1) { int[] num = new int[20]; for (int i = 0; i <num.Length; i++) { num[i] = Rand.NextPM(0,10); //Console.WriteLine(num[i]); } /* a1 = 2 ;b1 = -1; c1 = 5; d1 = 1; e1 = -3; a2 = 3; b2 = 2; c2 = 2; d2 = -6; e2 = -32; a3 = 1; b3 = 3; c3 = 3; d3 = -1; e3 = -47; a4 = 5; b4 = -2; c4 = -3; d4 = 3; e4 = 20; // a1 = 3; b1 = 8; c1 = 9; d1 = 2; e1 = 1; a2 = 5; b2 = 2; c2 = 7; d2 = 3; e2 = 2; a3 = 6; b3 = 4; c3 = 3; d3 = 6; e3 = 1; a4 = 2; b4 = 2; c4 = 5; d4 = 6; e4 = 3; */ a1 = Convert.ToDouble(num[0]); b1 = Convert.ToDouble(num[1]); c1 = Convert.ToDouble(num[2]); d1 = Convert.ToDouble(num[3]); e1 = Convert.ToDouble(num[4]); a2 = Convert.ToDouble(num[5]); b2 = Convert.ToDouble(num[6]); c2 = Convert.ToDouble(num[7]); d2 = Convert.ToDouble(num[8]); e2 = Convert.ToDouble(num[9]); a3 = Convert.ToDouble(num[10]); b3 = Convert.ToDouble(num[11]); c3 = Convert.ToDouble(num[12]); d3 = Convert.ToDouble(num[13]); e3 = Convert.ToDouble(num[14]); a4 = Convert.ToDouble(num[15]); b4 = Convert.ToDouble(num[16]); c4 = Convert.ToDouble(num[17]); d4 = Convert.ToDouble(num[18]); e4 = Convert.ToDouble(num[19]); //Console.WriteLine("{0} {1} {2} {3} {4}",a1,b1,c1,d1,e1); x = (( ( (d4*c3-d3*c4)*(d3*b2-d2*b3)-(d3*c2-d2*c3)*(d4*b3-d3*b4) ) * ( (d3*c2-d2*c3)*(d2*e1-d1*e2)-(d2*c1-d1*c2)*(d3*e2-d2*e3) ) )-( (d3*c2-d2*c3)*(d2*b1-d1*b2)-(d2*c1-d1*c2)*(d3*b2-d2*b3) ) * ( (d4*c3-d3*c4)*(d3*e2-d2*e3)-(d3*c2-d2*c3)*(d4*e3-d3*e4) )) / ( ( (d4*c3-d3*c4)*(d3*b2-d2*b3)-(d3*c2-d2*c3)*(d4*b3-d3*b4) ) * ( (d3*c2-d2*c3)*(d2*a1-d1*a2)-(d2*c1-d1*c2)*(d3*a2-d2*a3) ) - ( (d3*c2-d2*c3)*(d2*b1-d1*b2)-(d2*c1-d1*c2)*(d3*b2-d2*b3) )* ( (d4*c3-d3*c4)*(d3*a2-d2*a3)-(d3*c2-d2*c3)*(d4*a3-d3*a4) ) ); y = ( (d3*c2-d2*c3)*(d2*e1-d1*e2) - (d2*c1-d1*c2)*(d3*e2-d2*e3) - ( (d3*c2-d2*c3)*(d2*a1-d1*a2) - (d2*c1-d1*c2)*(d3*a2-d2*a3) )*x ) / ( (d3*c2-d2*c3)*(d2*b1-d1*b2) - (d2*c1-d1*c2)*(d3*b2-d2*b3) ); z = (d3*e2-d2*e3-(d3*a2-d2*a3)*x-(d3*b2-d2*b3)*y ) / (d3*c2-d2*c3); w = (e1-a1*x-b1*y-c1*z) / d1; if ((x%1==0.5 || x%1==0) && (y%1==0.5 || y%1==0) && (z%1==0.5 || z%1==0) && (w%1==0.5 || w%1==0) && Math.Abs(x)<limit && Math.Abs(y)<limit && Math.Abs(z)<limit && Math.Abs(w)<limit) { for (int i = 0; i <num.Length; i++) { //num[i] = Rand.NextPM(1,10); Console.Write(num[i]+ " "); if ((i+1)%5==0 && i>0) { Console.WriteLine(); } } /*Console.WriteLine(); Console.WriteLine("{0} {1} {2} {3} {4}",a1,b1,c1,d1,e1); Console.WriteLine("{0} {1} {2} {3} {4}",a2,b2,c2,d2,e2); Console.WriteLine("{0} {1} {2} {3} {4}",a3,b3,c3,d3,e3); Console.WriteLine("{0} {1} {2} {3} {4}",a4,b4,c4,d4,e4); */ Console.WriteLine("x, y, z, w = {0}, {1}, {2}, {3}", x,y,z,w); Console.WriteLine(); count++; } } } public static void RandomDie() { int numerator = 0; for (int i = 0; i<10000; i++){ int die = Rand.Next(1,7); if (die==1) { numerator++; } double result = (double) numerator/i; Console.WriteLine("{0}/{1} = {2}", numerator, i, result); } } public static void LCMQ() { List<string> lcmQ = new List<string>(); int count=0; while(count<100) { int left = Rand.Next(2,100); int right = Rand.Next(2,100); if (lcm(left,right)<120 && Fraction.GCD(left,right)!=1 && lcm(left,right)!=left && lcm(left,right)!=right) { count++; lcmQ.Add(" \\item " + left + " and " + right + " lcm = " + lcm(left,right)); } } while (count>=100 && count<130) { int left = Rand.Next(2,100); int right = Rand.Next(2,100); if (lcm(left,right)<120 && Fraction.GCD(left,right)==1 && Math.Abs(left-right)<20) { count++; lcmQ.Add(" \\item " + left + " and " + right + " lcm = " + lcm(left,right)); } } lcmQ.Shuffle(); Print(lcmQ,"Lowest Common Multiple (1)","Find the LCM (or lowest common multiple) of each pair of numbers",20); } public static void LCM3Q() { List<string> lcmQ = new List<string>(); int count=0; while(count<100) { int left = Rand.Next(2,100); int right = Rand.Next(2,100); if (lcm(left,right)<120 && Fraction.GCD(left,right)!=1 && lcm(left,right)!=left && lcm(left,right)!=right) { count++; lcmQ.Add(" \\item " + left + " and " + right + " @lcm(" + left + "," + right + ")=" + lcm(left,right)); } } while (count>=100 && count<130) { int left = Rand.Next(2,100); int right = Rand.Next(2,100); if (lcm(left,right)<120 && Fraction.GCD(left,right)==1 && Math.Abs(left-right)<20) { count++; lcmQ.Add(" \\item " + left + " and " + right + " @lcm(" + left + "," + right + ")=" + lcm(left,right)); } } while(count<150) { int left = Rand.Next(2,100); int middle = Rand.Next(2,100); int right = Rand.Next(2,100); if (left!=middle && middle!=right && lcm(left,middle,right)<120 && GCD(left,middle,right)!=1 && lcm(left,right)!=left && lcm(left,right)!=right) { count++; lcmQ.Add(" \\item " + left + ", " + middle + ", " + right + " @lcm(" + left + "," + middle + "," + right + ")=" + lcm(left,middle,right)); } } while (count>=150 && count<170) { int left = Rand.Next(2,100); int middle = Rand.Next(2,100); int right = Rand.Next(2,100); if (left!=middle && middle!=right && lcm(left,middle,right)<120 && GCD(left,middle,right)==1 && Math.Abs(max(left,middle,right)-min(left,middle,right))<20) { count++; lcmQ.Add(" \\item " + left + ", " + middle + ", " + right + " @lcm(" + left + "," + middle + "," + right + ")=" + lcm(left,middle,right)); } } lcmQ.Shuffle(); Print(lcmQ,"Lowest Common Multiple (3)","Find the LCM (or lowest common multiple) of each set of numbers",20); } public static void LCM2Q() { List<string> lcmQ = new List<string>(); int count=0; while(count<100) { int left = Rand.Next(2,100); int middle = Rand.Next(2,100); int right = Rand.Next(2,100); if (left!=middle && middle!=right && lcm(left,middle,right)<120 && GCD(left,middle,right)!=1 && lcm(left,right)!=left && lcm(left,right)!=right) { count++; lcmQ.Add(" \\item " + left + ", " + middle + ", " + right + " @lcm(" + left + "," + middle + "," + right + ")=" + lcm(left,middle,right)); } } while (count>=100 && count<130) { int left = Rand.Next(2,100); int middle = Rand.Next(2,100); int right = Rand.Next(2,100); if (left!=middle && middle!=right && lcm(left,middle,right)<120 && GCD(left,middle,right)==1 && Math.Abs(max(left,middle,right)-min(left,middle,right))<20) { count++; lcmQ.Add(" \\item " + left + ", " + middle + ", " + right + " @lcm(" + left + "," + middle + "," + right + ")=" + lcm(left,middle,right)); } } lcmQ.Shuffle(); Print(lcmQ,"Lowest Common Multiple (2)", "Find the LCM (or lowest common multiple) of each pair of numbers", 20); } public static void Reversal() { // finds the 4-digit reverse number for (int a = 0; a<10;a++){ for (int b = 0; b<10;b++){ for (int c = 0; c<10;c++){ for (int d = 0; d<10;d++){ double n = 9; if ((n*1000*a+n*100*b+n*10*c+n*d)==(1000*d+100*c+10*b+a)) { Console.WriteLine(a+""+b+""+c+""+d); } } } } } } public static int Tens(){ // randomises 10 or 100 int rand = Rand.Next(0,2); if (rand==0) { return 10; } else return 100; } public static int Tens2() { // returns 1, 10 or 100 randomly int rand = Rand.Next(0,3); if (rand==0) { return 1; } else if (rand==1) { return 10; } else return 100; } public static void simpleArith() { int maxNum = 3600; //string title = "Addition \\& Subtraction (2 by 1 digits) $<$ "+ maxNum; string title = "Addition Speed Practice"; List<string> questions = new List<string>(); List<string> addQ = new List<string>(); List<string> subQ = new List<string>(); while(addQ.Count()<maxNum) { //int left = Rand.Next(11,70); //int right = Rand.Next(2,10); int left = Rand.Next(1,10); int right = Rand.Next(1,10); int result = left + right; if (result<=10) addQ.Add(" \\item \\("+left+"+"+right+"=\\underline{\\hspace{2cm}}\\)"); } while(subQ.Count()<maxNum) { int left = Rand.Next(11,70); int right = Rand.Next(2,10); subQ.Add(" \\item \\("+left+"-"+right+"=\\underline{\\hspace{2cm}}\\)"); } questions.AddRange(addQ); //questions.AddRange(subQ); questions.Shuffle(); PrintArithmetic(questions, title,50); //PrintAnswerKey(questions, title, 30); } public static void addSub3TQ() { // add and sub 3 terms string title = "Addition \\& Subtraction (3 term) (2)"; List<string> addsubQ = new List<string>(); DataTable dt = new DataTable(); int n1, n2, n3; for (int k=0; k<9000; k++){ int[] n = new int[3]; n[0] = Rand.Next(101,1000); n[1] = Rand.Next(11,1000); n[2] = Rand.Next(11,1000); int[] op = new int[2]; op[0] = Rand.Next(0,2); op[1] = Rand.Next(0,2); string[] operand = new string[2]; operand[0] = "+"; operand[1] = "-"; int result; if (n[0]-n[1]>=0&& (n[0]-n[1])-n[2]>=0 && (n[0]+n[1]+n[2]<1000) && addsubQ.Count()<300){ result = Convert.ToInt32(dt.Compute(n[0]+operand[op[0]]+n[1]+operand[op[1]]+n[2], null)); addsubQ.Add(" \\item \\(\\mathmakebox[3.0cm][r]{"+n[0]+operand[op[0]]+n[1]+operand[op[1]]+n[2]+"}=\\underline{\\hspace{2cm}}\\)"); //Console.WriteLine(result); } } //Console.WriteLine(addsubQ.Count()); //addsubQ.Shuffle(); PrintArithmetic(addsubQ, title); } public static void addSubQ() { // add and sub questions string title = "Addition \\& Subtraction (1)"; string subtitle = "without carry over or borrowing"; List<string> addQ = new List<string>(); while (addQ.Count()<120) { int i = Rand.Next(10,100); int j = Rand.Next(10,100); //if (i+j<100) addQ.Add(" \\item \\(\\mathmakebox[1.5cm][r]{"+i+"+"+j+"}=\\underline{\\hspace{2cm}}\\)"); //\\mathmakebox[1.45cm][r]{ if ((i/10+j/10)<10 && (i%10+j%10)<10) addQ.Add(" \\item \\(\\mathmakebox[1.5cm][r]{"+i+"+"+j+"}=\\underline{\\hspace{2cm}}\\)"); // for no carry over } List<string> subQ = new List<string>(); while (subQ.Count()<120) { int i = Rand.Next(10,100); int j = Rand.Next(10,100); //if (i>j && i%10>j%10) { subQ.Add(" \\item \\(\\mathmakebox[1.5cm][r]{"+i+"-"+j+"}=\\underline{\\hspace{2cm}}\\)");} if ((i/10>j/10) && (i%10>j%10)) subQ.Add(" \\item \\(\\mathmakebox[1.5cm][r]{"+i+"-"+j+"}=\\underline{\\hspace{2cm}}\\)"); } List<string> questions = new List<string>(); //Console.WriteLine(addQ.Count()); //Console.WriteLine(subQ.Count()); addQ.Shuffle(); subQ.Shuffle(); questions.AddRange(addQ); questions.AddRange(subQ); questions.Shuffle(); PrintArithmetic(questions, title, subtitle); } public static void addSub2Q() { // add and sub questions string title = "Addition \\& Subtraction (2 Digits)"; List<string> addQ = new List<string>(); while(addQ.Count()<150){ int i = Rand.Next(11,100); int j = Rand.Next(11,100); int result = i+j; if (i+j<100) addQ.Add(" \\item \\("+i+"+"+j+"=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); //\\mathmakebox[1.45cm][r]{ } List<string> subQ = new List<string>(); while(subQ.Count()<150) { int i = Rand.Next(11,100); int j = Rand.Next(11,100); int result = i-j; if (i>j){subQ.Add(" \\item \\("+i+"-"+j+"=\\underline{\\hspace{2cm}}\\)"+result+"\\)");} } List<string> questions = new List<string>(); //Console.WriteLine(addQ.Count()); //Console.WriteLine(subQ.Count()); addQ.Shuffle(); subQ.Shuffle(); questions.AddRange(addQ); questions.AddRange(subQ); questions.Shuffle(); PrintArithmetic(questions, title); PrintAnswerKey(questions, title, 30); } public static void addSub3Q() { // add and sub questions string title = "Addition \\& Subtraction (3 Digits)"; List<string> addQ = new List<string>(); while(addQ.Count()<150){ int i = Rand.Next(101,1000); int j = Rand.Next(101,1000); int result = i+j; if (i+j<1000) addQ.Add(" \\item \\("+i+"+"+j+"=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); //\\mathmakebox[1.45cm][r]{ } List<string> subQ = new List<string>(); while(subQ.Count()<150){ int i = Rand.Next(101,1000); int j = Rand.Next(101,1000); int result = i-j; if (i>j){subQ.Add(" \\item \\("+i+"-"+j+"=\\underline{\\hspace{2cm}}\\)"+result+"\\)");} } List<string> questions = new List<string>(); //Console.WriteLine(addQ.Count()); //Console.WriteLine(subQ.Count()); addQ.Shuffle(); subQ.Shuffle(); questions.AddRange(addQ); questions.AddRange(subQ); questions.Shuffle(); PrintArithmetic(questions, title); PrintAnswerKey(questions, title, 30); } public static void multDivQ() { // mult and div questions string title = "Multplication \\& Division (1)"; List<string> multQ = new List<string>(); DataTable dt = new DataTable(); for (int k=0; k<4; k++){ for (int i=2; i<=9; i++){ for (int j=2; j<=9; j++){ if (multQ.Count()<200) multQ.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+i+"\\times"+j+"}=\\underline{\\hspace{2cm}}\\)"); //\\mathmakebox[1.45cm][r]{ } } } List<string> divQ = new List<string>(); for (int k=0; k<4; k++){ for (int i=10; i<=100; i++){ for (int j=2; j<=9; j++){ if (divQ.Count()<200 && i>j && i%j==0 &&i/j<10){divQ.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+i+"\\div"+j+"}=\\underline{\\hspace{2cm}}\\)");} } } } List<string> questions = new List<string>(); //Console.WriteLine(multQ.Count()); //Console.WriteLine(divQ.Count()); questions.AddRange(multQ); questions.AddRange(divQ); questions.Shuffle(); PrintArithmetic(questions, title); } public static void MultDiv() { List<int> multdivList = new List<int>(); List<int> subList = new List<int>(); while (multdivList.Count<10) { int multdivSwitch = Rand.Next(0,2); if (multdivList.Count<=2) { // add the 0 or 1 to List multdivList.Add(multdivSwitch); } else if (multdivList.Count>2) { // no more than 3 of the same subList = multdivList.GetRange(multdivList.Count-3,3); // check if current switch (0 or 1) has appeared in previous 3. If previous 3 the same (0 0 0 or 1 1 1) don't add to List if (UniqueInListInt(multdivSwitch,subList)) { multdivList.Add(multdivSwitch); } } } foreach (var obj in multdivList) { Console.Write(obj+" "); } } public static void newMultQ() { string title = "Multiplication New (1)"; List<string> questions = new List<string>(); List<string> multQ = new List<string>(); List<string> multiplicand = new List<string>(); List<string> multiplier = new List<string>(); List<string> product = new List<string>(); int num = 90; int count = 0; while (multQ.Count()<num) { int a = Rand.Next(1,11); int b = Rand.Next(1,11); int c = a*b; if (multQ.Count()==0) { // 1st quotient // 4\times8=32, 10\times10=100 string q = Convert.ToString(a)+"\\times"+Convert.ToString(b)+"="+Convert.ToString(c); multQ.Add(q); // for multiplicand (leftSubstring) int qTo = q.IndexOf("\\times"); string leftSubstring = q.Substring(0,qTo); // end multiplicand ///for multiplier (rightSubstring) int pFrom = q.IndexOf("\\times") + "\\times".Length; int pTo = q.LastIndexOf("="); string rightSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end multiplier // start product int rFrom = q.IndexOf("=")+1; int rTo = q.Length; string productSubstring = q.Substring(rFrom, rTo - rFrom); // end product multiplicand.Add(leftSubstring); multiplier.Add(rightSubstring); product.Add(productSubstring); questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } else if (multQ.Count()==1 && !multQ.Contains(Convert.ToString(a)+"\\times"+Convert.ToString(b)+"="+Convert.ToString(c))) { string q = Convert.ToString(a)+"\\times"+Convert.ToString(b)+"="+Convert.ToString(c); // start multiplicand (leftSubstring) int qTo = q.IndexOf("\\times"); string leftSubstring = q.Substring(0,qTo); // end multiplicand // start multiplier (rightSubstring) int pFrom = q.IndexOf("\\times") + "\\times".Length; int pTo = q.LastIndexOf("="); string rightSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end multiplier // start product int rFrom = q.IndexOf("=")+1; int rTo = q.Length; string productSubstring = q.Substring(rFrom, rTo - rFrom); // end product if (!leftSubstring.Equals(multiplicand[multQ.Count-1]) && !rightSubstring.Equals(multiplier[multQ.Count-1]) && !productSubstring.Equals(product[multQ.Count-1])) { //if current quotient is unique to previous quotient multQ.Add(q); multiplicand.Add(leftSubstring); multiplier.Add(rightSubstring); product.Add(productSubstring); questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } else if (multQ.Count()==2 && !multQ.Contains(Convert.ToString(a)+"\\times"+Convert.ToString(b)+"="+Convert.ToString(c))) { string q = Convert.ToString(a)+"\\times"+Convert.ToString(b)+"="+Convert.ToString(c); // start multiplicand (leftSubstring) int qTo = q.IndexOf("\\times"); string leftSubstring = q.Substring(0,qTo); // end multiplicand // start multiplier (rightSubstring) int pFrom = q.IndexOf("\\times") + "\\times".Length; int pTo = q.LastIndexOf("="); string rightSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end multiplier // start product int rFrom = q.IndexOf("=")+1; int rTo = q.Length; string productSubstring = q.Substring(rFrom, rTo - rFrom); // end product List<string> subMultiplicand = multiplicand.GetRange(multiplicand.Count()-2,2); List<string> subMultiplier = multiplier.GetRange(multiplier.Count()-2,2); List<string> subProduct = product.GetRange(product.Count()-2,2); if (UniqueInList(leftSubstring,subMultiplicand) && UniqueInList(rightSubstring,subMultiplier) && UniqueInList(productSubstring,subProduct)) { //if quotient is equal to one of previous 2 quotients (NOT unique) multQ.Add(q); multiplicand.Add(leftSubstring); multiplier.Add(rightSubstring); product.Add(productSubstring); questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } else if (multQ.Count()>=3 && !multQ.Contains(Convert.ToString(a)+"\\times"+Convert.ToString(b)+"="+Convert.ToString(c))) { string q = Convert.ToString(a)+"\\times"+Convert.ToString(b)+"="+Convert.ToString(c); // start multiplicand (leftSubstring) int qTo = q.IndexOf("\\times"); string leftSubstring = q.Substring(0,qTo); // end multiplicand // start multiplier (rightSubstring) int pFrom = q.IndexOf("\\times") + "\\times".Length; int pTo = q.LastIndexOf("="); string rightSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end multiplier // start product int rFrom = q.IndexOf("=")+1; int rTo = q.Length; string productSubstring = q.Substring(rFrom, rTo - rFrom); // end product List<string> subMultiplicand = multiplicand.GetRange(multiplicand.Count()-3,3); List<string> subMultiplier = multiplier.GetRange(multiplier.Count()-3,3); List<string> subProduct = product.GetRange(product.Count()-3,3); if (UniqueInList(leftSubstring,subMultiplicand) && UniqueInList(rightSubstring,subMultiplier) && UniqueInList(productSubstring,subProduct)) { //if quotient is equal to one of previous 2 quotients (NOT unique) multQ.Add(q); multiplicand.Add(leftSubstring); multiplier.Add(rightSubstring); product.Add(productSubstring); questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+a+"\\times"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } } PrintArithmetic(questions,title); } /***********NEW DIVISION PROBLEMS***********/ public static void newDivQ() { string title = "Division New (1)"; List<string> questions = new List<string>(); List<string> divQ = new List<string>(); List<string> divisor = new List<string>(); List<string> quotient = new List<string>(); List<string> dividend = new List<string>(); int num = 30; int count =0; while (divQ.Count()<num) { int a = Rand.Next(2,101); int b = Rand.Next(2,11); int c = a/b; if (a%b==0 && a/b<=10) { if (divQ.Count()==0) { // 1st quotient string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); divQ.Add(q); // for dividend string dividendSubstring = q.Substring(0,q.IndexOf("\\div")); // for quotient string substring = divQ[divQ.Count-1].Substring(divQ[divQ.Count-1].IndexOf("=")+1); quotient.Add(substring); ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end divisor dividend.Add(dividendSubstring); divisor.Add(divisorSubstring); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } else if (divQ.Count()==1 && !divQ.Contains(Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c))) { // 2nd quotient string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); // for dividend string dividendSubstring = q.Substring(0,q.IndexOf("\\div")); // for quotient string substring = q.Substring(q.IndexOf("=")+1); ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end divisor if (!substring.Equals(quotient[divQ.Count-1]) && !divisorSubstring.Equals(divisor[divQ.Count-1])) { //if current quotient is unique to previous quotient divQ.Add(q); dividend.Add(dividendSubstring); quotient.Add(substring); divisor.Add(divisorSubstring); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } else if (divQ.Count()==2 && !divQ.Contains(Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c))) { // 1st quotient if (divQ.Count()>0 && divQ.Count()<=30) { int counter = 0; for (int i=0; i<divQ.Count(); i++) { // compare from entry 0 to current string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); // for dividend string dividendSubstring = q.Substring(0,q.IndexOf("\\div")); // gets the "a" from question q // for quotient string substring = q.Substring(q.IndexOf("=")+1); // gets the "c" from question q ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question q // end divisor if (dividend[i].Equals(dividendSubstring) && (divisor[i]+quotient[i]).Equals(divisorSubstring+substring)) { // if the sum of divisor and quotient are the same //do nothing } else { // if the sum of divisor and quotient are different counter++; //should equal to the total questions on that page if unique } if (counter==divQ.Count%30) { // compare the last three divisors and quotients and if different List<string> subQuotient = quotient.GetRange(quotient.Count()-2,2); List<string> subDivisor = divisor.GetRange(divisor.Count()-2,2); if (UniqueInList(substring,subQuotient) && UniqueInList(divisorSubstring,subDivisor)) { //if quotient is equal to one of previous 3 quotients (NOT unique) divQ.Add(q); dividend.Add(dividendSubstring); quotient.Add(substring); divisor.Add(divisorSubstring); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } } } //else if 0-30 } else if (divQ.Count()>=3 && !divQ.Contains(Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c))) { // 1st quotient if (divQ.Count()>0 && divQ.Count()<=30) { int counter = 0; for (int i=0; i<divQ.Count(); i++) { // compare from entry 0 to current string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); // for dividend string dividendSubstring = q.Substring(0,q.IndexOf("\\div")); // gets the "a" from question q // for quotient string substring = q.Substring(q.IndexOf("=")+1); // gets the "c" from question q ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question q // end divisor if (dividend[i].Equals(dividendSubstring) && (divisor[i]+quotient[i]).Equals(divisorSubstring+substring)) { // if the sum of divisor and quotient are the same //do nothing } else { // if the sum of divisor and quotient are different counter++; //should equal to the total questions on that page if unique } if (counter==divQ.Count%30) { // compare the last three divisors and quotients and if different List<string> subQuotient = quotient.GetRange(quotient.Count()-3,3); List<string> subDivisor = divisor.GetRange(divisor.Count()-3,3); if (UniqueInList(substring,subQuotient) && UniqueInList(divisorSubstring,subDivisor)) { //if quotient is equal to one of previous 3 quotients (NOT unique) divQ.Add(q); dividend.Add(dividendSubstring); quotient.Add(substring); divisor.Add(divisorSubstring); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } } } //else if 0-30 /* else if (divQ.Count()>30 && divQ.Count()<=60) { int counter = 0; for (int i=0; i<divQ.Count()-1; i++) { // compare from entry 30 to current string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); // for dividend string dividendSubstring = q.Substring(0,q.IndexOf("\\div")); // gets the "a" from question q // for quotient string substring = q.Substring(q.IndexOf("=")+1); // gets the "c" from question q ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question q // end divisor if (dividend[i].Equals(dividendSubstring) && (divisor[i]+quotient[i]).Equals(divisorSubstring+substring)) { // if the sum of divisor and quotient are the same //do nothing } else { // if the sum of divisor and quotient are different counter++; //should equal to the total questions on that page if unique } if (counter==divQ.Count%30) { // compare the last three divisors and quotients and if different List<string> subQuotient = quotient.GetRange(quotient.Count()-3,3); List<string> subDivisor = divisor.GetRange(divisor.Count()-3,3); if (UniqueInList(substring,subQuotient) && UniqueInList(divisorSubstring,subDivisor)) { //if quotient is equal to one of previous 3 quotients (NOT unique) divQ.Add(q); dividend.Add(dividendSubstring); quotient.Add(substring); divisor.Add(divisorSubstring); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } } }//else if 30-60 else if (divQ.Count()>60 && divQ.Count()<=90) { int counter = 0; for (int i=0; i<divQ.Count()-1; i++) { // compare from entry 0 to current string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); // for dividend string dividendSubstring = q.Substring(0,q.IndexOf("\\div")); // gets the "a" from question q // for quotient string substring = q.Substring(q.IndexOf("=")+1); // gets the "c" from question q ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question q // end divisor if (dividend[i].Equals(dividendSubstring) && (divisor[i]+quotient[i]).Equals(divisorSubstring+substring)) { // if the sum of divisor and quotient are the same //do nothing } else { // if the sum of divisor and quotient are different counter++; //should equal to the total questions on that page if unique } if (counter==divQ.Count%30) { // compare the last three divisors and quotients and if different List<string> subQuotient = quotient.GetRange(quotient.Count()-3,3); List<string> subDivisor = divisor.GetRange(divisor.Count()-3,3); if (UniqueInList(substring,subQuotient) && UniqueInList(divisorSubstring,subDivisor)) { //if quotient is equal to one of previous 3 quotients (NOT unique) divQ.Add(q); dividend.Add(dividendSubstring); quotient.Add(substring); divisor.Add(divisorSubstring); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } } } //else if 60-90 */ } //else if divQ.Count>=3 } //if }//while PrintArithmetic(questions, title); } //method /*************END OF NEW DIVISION PROBLEMS****************/ public static void makeMultQ(int lower1, int upper1, int lower2, int upper2) { string title = "Multiplication (1)"; List<string>[] questions = new List<string>[5]; List<string> multQ = new List<string>(); // the way this code works is it goes through all combinations of the times table without imbalance such as duplicates // or missing a particular question. the code goes through that in five loops and adds all the lists together before // printing them out. for (int k=0; k<5; k++){ questions[k] = new List<string>(); for (int i=lower1; i<=upper1; i++){ for (int j=lower2; j<=upper2; j++){ questions[k].Add(" \\item \\("+i+"\\times"+j+"=\\underline{\\hspace{2cm}}\\)"); //\\mathmakebox[1.45cm][r]{ } } questions[k].Shuffle(); multQ.AddRange(questions[k]); } PrintArithmetic(multQ, title); } /*List<int> listNumbers = new List<int>(); do { int numbers = rand.Next(1,49); if(!listNumbers.Contains(number)) { listNumbers.Add(numbers); } } while (listNumbers.Count < 6) */ public static void makeMultQ3by1() { string title = "Multplication (3 by 1 Digits)"; List<string> questions = new List<string>(); for (int k=0; k<300; k++){ int i = Rand.Next(101,1000); int j = Rand.Next(11,100); i = Rand.Next(101,1000); i = Rand.Next(101,1000); j = Rand.Next(2,10); j = Rand.Next(2,10); questions.Add(" \\item \\("+i+"\\times"+j+"=\\underline{\\hspace{2cm}}\\)"); //\\mathmakebox[1.45cm][r]{ } questions.Shuffle(); PrintArithmetic(questions, title); //Console.WriteLine(questions.Count()); } public static void makeDivQ(int lower1, int upper1, int lower2, int upper2) { string title = "Division (2 by 1 digits) General"; List<string> questions = new List<string>(); for (int k=0; k<4; k++){ for (int i=lower1; i<=upper1; i++){ for (int j=lower2; j<=upper2; j++){ if (i>j){questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+i+"\\div"+j+"}=\\underline{\\hspace{2cm}}\\)");} } } } questions.Shuffle(); PrintArithmetic(questions, title); } public static void makeDivQ2by1() { string title = "Division New (2 by 1 digits) General"; List<string> questions = new List<string>(); List<string> divQ = new List<string>(); List<string> divisor = new List<string>(); List<string> quotient = new List<string>(); int num = 90; int count =0; while (divQ.Count()<num) { int a = Rand.Next(2,101); int b = Rand.Next(2,11); int c = a/b; if (a/b>10) { if (divQ.Count()==0) { // 1st quotient string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); divQ.Add(q); string substring = divQ[divQ.Count-1].Substring(divQ[divQ.Count-1].IndexOf("=")+1); quotient.Add(substring); ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end divisor divisor.Add(divisorSubstring); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } else if (divQ.Count()==1 && !divQ.Contains(Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c))) { // 2nd quotient string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); string substring = q.Substring(q.IndexOf("=")+1); ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end divisor if (!substring.Equals(quotient[divQ.Count-1]) && !divisorSubstring.Equals(divisor[divQ.Count-1])) { //if current quotient is unique to previous quotient divQ.Add(q); quotient.Add(substring); divisor.Add(divisorSubstring); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } else if (divQ.Count()==2 && !divQ.Contains(Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c))) { // 1st quotient string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); string substring = q.Substring(q.IndexOf("=")+1); ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end divisor List<string> subQuotient = quotient.GetRange(quotient.Count()-2,2); List<string> subDivisor = divisor.GetRange(divisor.Count()-2,2); if (UniqueInList(substring,subQuotient) && UniqueInList(divisorSubstring,subDivisor)) { //if quotient is equal to one of previous 2 quotients (NOT unique) divQ.Add(q); quotient.Add(substring); divisor.Add(divisorSubstring); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } else if (divQ.Count()>=3 && !divQ.Contains(Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c))) { // 1st quotient string q = Convert.ToString(a)+"\\div"+Convert.ToString(b)+"="+Convert.ToString(c); string substring = q.Substring(q.IndexOf("=")+1); ///for divisor int pFrom = q.IndexOf("\\div") + "\\div".Length; int pTo = q.LastIndexOf("="); string divisorSubstring = q.Substring(pFrom, pTo - pFrom); // gets the "b" from the question // end divisor List<string> subQuotient = quotient.GetRange(quotient.Count()-3,3); List<string> subDivisor = divisor.GetRange(divisor.Count()-3,3); if (UniqueInList(substring,subQuotient) && UniqueInList(divisorSubstring,subDivisor)) { //if quotient is equal to one of previous 3 quotients (NOT unique) divQ.Add(q); quotient.Add(substring); divisor.Add(divisorSubstring); //questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"); questions.Add(" \\item \\(\\mathmakebox[1.55cm][r]{"+a+"\\div"+b+"}=\\underline{\\hspace{2cm}}\\)"+c); } } } } PrintArithmetic(questions,title); } public static void makeDivQ3by1() { string title = "Division (2 by 1 digits) General"; List<string> questions = new List<string>(); for (int k=0; k<100; k++) { int i = Rand.Next(101,1000); int j = Rand.Next(2,10); if (i>j){questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+i+"\\div"+j+"}=\\underline{\\hspace{2cm}}\\)");} } questions.Shuffle(); PrintArithmetic(questions, title); } public static void makeDivQ3by2() { string title = "Division (3 by 2 digits)"; List<string> questions = new List<string>(); while(questions.Count()<150) { int i = Rand.Next(101,1000); int j = Rand.Next(11,100); int result = i/j; if (i>j && i%j==0) { questions.Add(" \\item \\("+i+"\\div"+j+"=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } } questions.Shuffle(); // PrintArithmetic(questions, title); PrintAnswerKey(questions, title, 30); } public static void makeDeciQ(){ string title = "Decimal Arithmetic General"; // Division List<string> divQ = new List<string>(); for (int i=0; i<6500; i++) { int tens = Tens(); double argument = Math.Truncate(Rand.NextD(1.0,99.99)*tens)/tens; decimal num1 = Rand.Next(2,100); int dividend = Rand.Next(2,1000); decimal result = dividend/num1; int count = BitConverter.GetBytes(decimal.GetBits(result)[3])[2]; //Console.WriteLine(count); if(count<4 && divQ.Count()<120) { //Console.WriteLine("{0}/{1}={2}", dividend,num1, dividend/num1); divQ.Add(" \\item \\(\\mathmakebox[3cm][r]{"+dividend+"\\div"+num1+"}=\\underline{\\hspace{2cm}}\\)"); } } //Multiplication List<string> multQ = new List<string>(); for (int i=0; i<120; i++) { double number = Rand.NextD(1.0,99.99); int hund; double num1; if (number>=10) { num1 = Math.Truncate(number*10)/10; hund = 10; } else { num1 = Math.Truncate(number*100)/100; hund = 10; } double num2 = Math.Truncate(Rand.NextD(2,hund)*hund)/hund; double result = num1*num2; if ( (Math.Floor(num1)!=num1 || Math.Floor(num2)!=num2) && multQ.Count()<120) { multQ.Add(" \\item \\(\\mathmakebox[3cm][r]{"+num1+"\\times"+num2+"}=\\underline{\\hspace{2cm}}\\)"); } } //Add List<string> addQ = new List<string>(); for (int i=0; i<120; i++) { double number = Rand.NextD(1.0,99.99); int hund = Tens(); double num1; if (number>=10) { num1 = Math.Truncate(number*10)/10; //hund = 100; } else { num1 = Math.Truncate(number*100)/100; //hund = 10; } double num2 = Math.Truncate(Rand.NextD(2,hund)*hund)/hund; double result = num1+num2; addQ.Add(" \\item \\(\\mathmakebox[3cm][r]{"+num1+"+"+num2+"}=\\underline{\\hspace{2cm}}\\)"); } //Subtract List<string> subQ = new List<string>(); for (int i=0; i<300; i++) { double number = Rand.NextD(1.0,99.99); int hund = Tens(); double num1; if (number>=10) { num1 = Math.Truncate(number*10)/10; //hund = 100; } else { num1 = Math.Truncate(number*100)/100; //hund = 10; } double num2 = Math.Truncate(Rand.NextD(2,hund)*hund)/hund; if(num1>num2) { double result = num1-num2; subQ.Add(" \\item \\(\\mathmakebox[3cm][r]{"+num1+"+"+num2+"}=\\underline{\\hspace{2cm}}\\)"); } } List<string> questions = new List<string>(); //questions.AddRange(addQ); //questions.AddRange(subQ); questions.AddRange(multQ); //questions.AddRange(divQ); questions.Shuffle(); PrintArithmetic(questions,title); } public static void makeDeciDivQ() { string title = "Decimal Division General"; // Division List<string> divQ = new List<string>(); for (int i=0; i<6500; i++) { int tens = Tens(); decimal divisor = (decimal) Rand.Next(2,100)/Tens2(); decimal dividend = (decimal) Rand.Next(2,1000)/Tens2(); decimal result = dividend/divisor; int resultInt = Convert.ToInt32(result); int count = BitConverter.GetBytes(decimal.GetBits(result)[3])[2]; //Console.WriteLine(count); if(count<4 && divQ.Count()<120) { //Console.WriteLine("{0}/{1}={2}", dividend,num1, dividend/num1); divQ.Add(" \\item \\(\\mathmakebox[3cm][r]{"+dividend+"\\div"+divisor+"}=\\underline{\\hspace{2cm}}\\)"); } //if (divisor!=1 && count<4 && resultInt.Count()<4) Console.WriteLine(dividend+ " / " +divisor + " = " + result); // if (count<4 && resultInt.Count()<4 ) Console.WriteLine((int)result); if ( !(BitConverter.GetBytes(decimal.GetBits(divisor)[3])[2]==0 && BitConverter.GetBytes(decimal.GetBits(dividend)[3])[2]==0 && BitConverter.GetBytes(decimal.GetBits(result)[3])[2]==0) && divisor!=1 && count<4 && divQ.Count()<120) { Console.WriteLine(dividend+ " / " +divisor + " = " + result); } } } /*public static void makeDeciQ(double upper1) { string title = "Division (2 by 1 digits) General"; List<string> addquestions = new List<string>(); List<string> subquestions = new List<string>(); List<string> multquestions = new List<string>(); List<string> divquestions = new List<string>(); string[] op = new string[4] {"+", "-", "\\times", "\\div"}; for (int i=1; i<=upper1; i++){ int operand = Rand.Next(1,4); double[] num = new double[2] {Math.Truncate(Rand.NextD(1.0,99.99)*100)/100, Rand.Next(2,999)}; decimal num1 = Convert.ToDecimal(num[1])); //if (operand==2){questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+num[0]+op[operand]+num[1]+"}=\\underline{\\hspace{2cm}}\\)");} if (operand==4 && num[2]%num1==0){questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+num[0]+op[operand]+num[1]+"}=\\underline{\\hspace{2cm}}\\)");} //else if (operand==1) {questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+num[0]+op[operand]+num[1]+"}=\\underline{\\hspace{2cm}}\\)");} //else if (operand==3) {questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+num[0]+op[operand]+num[1]+"}=\\underline{\\hspace{2cm}}\\)");} } //questions.Shuffle(); //PrintArithmetic(questions, title); }*/ public static void makeSubQ2by2(int lower1, int upper1, int lower2, int upper2){ string title = "Subtraction (2 by 2 Digits)"; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[2] {"(", ")("}; string end =")=\\)"; List<string> questions = new List<string>(); for (int i=lower1; i<=upper1; i++){ //for (int i=10; i<100;i++){ for (int j=lower2; j<=upper2; j++){ //for (int j=10; j<100;j++){ if (i!=j && i+j<100){questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+i+"-"+j+"}=\\underline{\\hspace{2cm}}\\)");} /*if (i>j) { questions.Add(" \\item \\("+i+"-"+j+"=\\)"); }*/ } } questions.Shuffle(); //Console.WriteLine(questions.Count()); PrintArithmetic(questions, title); /*for (int i=0; i<questions.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); //Console.WriteLine("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(i/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(questions[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\pagebreak[4]"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); //Console.WriteLine("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+((i+30)/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } }*/ } public static void makeAddQ2by1(int lower1, int upper1, int lower2, int upper2){ string title = "Subtraction (2 by 2 Digits)"; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[2] {"(", ")("}; string end =")=\\)"; List<string> questions = new List<string>(); for (int i=lower1; i<=upper1; i++){ //for (int i=10; i<100;i++){ for (int j=lower2; j<=upper2; j++){ //for (int j=10; j<100;j++){ questions.Add(" \\item \\(\\mathmakebox[1.45cm][r]{"+i+"+"+j+"}=\\underline{\\hspace{2cm}}\\)"); /*if (i>j) { questions.Add(" \\item \\("+i+"-"+j+"=\\)"); }*/ } } questions.Shuffle(); PrintArithmetic(questions, title); } public static void makeAlg() { // algebraic questions int[] n = new int[10]; for (int j=0; j<50; j++) { for (int i =0; i<n.Length; i++){ n[i] = Rand.Next(1,10); } char[] op = new char[] {'+','-'}; int x = Rand.Next(0,2); int y = Rand.Next(0,2); int z = Rand.Next(0,2); Console.WriteLine("\\(\\dfrac{{{7}(x{4}{0})}}{{{1}}}{6}\\dfrac{{{8}(x{5}{2})}}{{{3}}}=\\)\\\\",n[0],n[1],n[2],n[3],op[x],op[y],op[z],n[4],n[5]); } } public static void makeQ(int lower1, int upper1, int lower2, int upper2){ for (int i=lower1; i<=upper1; i+=9){ for (int j=lower2; j<=upper2; j+=9){ Console.WriteLine(" \\item \\("+i+"\\operation"+j+"=\\)"); } } } public static void makeFracQ(){ string title = "Algebra Simplification Introduction"; string exerciseTitle = "Simplify the algebraic expressions"; int m=0; int i_final=30000; int incre= 0; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string mathbox = "\\mathmakebox[1.45cm][r]{"; string[] op = new string[2] {"(", ")("}; string end =")=\\)"; List<string> questions = new List<string>(); //for (int i=lower1; i<=upper1; i+=9){ for (int i=1; i<100;i++){ //for (int j=lower2; j<=upper2; j+=9){ for (int j=10; j<100;j++){ int num1 = Rand.Next(1,10); int num2 = Rand.Next(1,10); int denom1 = Rand.Next(2,10); int denom2 = Rand.Next(2,10); int mixed1 = Rand.Next(0,10); int mixed2 = Rand.Next(0,10); if (num1!=denom1 && num2!=denom1 && num1<denom1 && num2<denom1){questions.Add(" \\item \\("+mixed1+"\\dfrac{"+num1+"}{"+denom1+"}+"+mixed2+"\\dfrac{"+num2+"}{"+denom1+"}=\\underline{\\hspace{2cm}}\\)");} /*if (i>j) { questions.Add(" \\item \\("+i+"-"+j+"=\\)"); }*/ } } questions.Shuffle(); //Console.WriteLine(questions.Count()); for (int i=0; i<questions.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); //Console.WriteLine("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(i/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(questions[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\pagebreak[4]"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); //Console.WriteLine("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+((i+30)/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } /*public static void makeDivQ(int lower1, int upper1, int lower2, int upper2){ for (int i=lower1; i<=upper1; i++){ for (int j=lower2; j<=upper2; j++){ if (i%j==0) { Console.WriteLine("\\("+i+"\\div"+j+"=\\)"); } } } }*/ public static void makeAlgebra(){ //string[] vari = new string[24] {"a","b","c","d","f","g","h","k","m","n","p","q","r","s","t","u","v","w","x","y","z","\\delta", "\\epsilon", "\\phi"}; string[] vari = new string[21] {"a","b","c","ab","bc","ac","abc","x","y","z","xy","yz","xz","xyz","k","m","n","km","kn","mn","kmn"}; //var[0] = "a"; //var[1] = "b"; //var[2] = "c"; int n=-1; // n is the random number of variables per question int m=0; int i_final=30000; int incre= 0; string title = "Algebra Simplification Introduction"; string exerciseTitle = "Simplify the algebraic expressions"; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[4] {"+","-","(", ")("}; int operand = Rand.Next(0,1); //string end =")=\\)"; string end = "=\\)"; for (int i=1; i<=i_final; i++) { int num2=Rand.Next(0,7); // range of number of different variables per question int num = Rand.Next(2,5); // range of number of total variables per question int consts=Rand.Next(-9,10); // range of coefficients of the variables while (true) { consts=Rand.Next(-9,10); if (consts==0) { consts=Rand.Next(-9,10); } else break; } if(i==1){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); //Console.WriteLine("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(m/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } if (n==-1){ //first variable of each question Console.Write(" \\item \\("); } if (n==0){ Console.Write(consts+vari[num2+7*incre]+op[operand]); } else if (n>0 && n<num){ Console.Write(consts+vari[num2+7*incre]+op[operand]); } n++; if (n==num){ m++; Console.Write(consts+vari[num2+7*incre]); Console.Write(end); Console.WriteLine(); if (m%30==0) { incre=Rand.Next(0,3); Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\pagebreak[4]"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); //Console.WriteLine("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(m/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.Write(" \\item \\("); n=0; } else if (n>num){ m++; Console.Write(consts+vari[num2+3*incre]); Console.Write(end); Console.WriteLine(); if (m%30==0) { incre=Rand.Next(0,3); Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\pagebreak[4]"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); //Console.WriteLine("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+((m+30)/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.Write(" \\item \\("); n=0; } /* if(i==i_final){ Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); }*/ } } public static void makeDiv4by2() { for (int i =0; i<10000; i++) { int dividend = Rand.Next(1001,10000); int divisor = Rand.Next(11,99); if (dividend%divisor==0) { Console.WriteLine(" \\item \\("+dividend+"\\div"+divisor+"=\\)"); } } } public static void makeSciNot(){ for (int i=0; i<100; i++){ int num1 = Rand.Next(1,10); int dec1 = Rand.Next(1,10); int num2 = Rand.Next(1,10); int dec2 = Rand.Next(1,10); int exp = Rand.Next(-9,10); int plusminus = Rand.Next(-1,2); if (num1>num2 && exp != exp+plusminus){ Console.WriteLine(" \\item \\({0}.{3} \\times 10^{{{2}}}+{1}.{4} \\times 10^{{{5}}}=\\)",num1,num2,exp,dec1,dec2,exp+plusminus); } } } public static void DN(){ //st<string> sign = new List<string>(new string[] {"+","-","*","/"}); List<char> sign = new List<char>(new char[] {'+','-','*','/'}); for (int i=0;i<100;i++){ string question = "{0}{1}{2}{3}{4}{5}{6}"; int pick1= Rand.Next(0+sign.Count()); int pick2= Rand.Next(0+sign.Count()); int pick3= Rand.Next(0+sign.Count()); int num1=Rand.Next(-9,10); int num2=Rand.Next(-9,10); int num3=Rand.Next(-9,10); int num4=Rand.Next(-9,10); string num1_str, num2_str, num3_str, num4_str; bool num1_b = num1<0; bool num2_b = num2<0; bool num3_b = num3<0; bool num4_b = num4<0; if (num1_b && !num2_b && !num3_b && !num4_b) { num1_str = "("+num1.ToString()+")"; Console.WriteLine(question,num1_str,sign[pick1],num2,sign[pick2],num3,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num2_b && !num1_b && !num3_b && !num4_b){ num2_str = "("+num2.ToString()+")"; Console.WriteLine(question,num1,sign[pick1],num2_str,sign[pick2],num3,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num3_b && !num1_b && !num2_b && !num4_b){ num3_str = "("+num3.ToString()+")"; Console.WriteLine(question,num1,sign[pick1],num2,sign[pick2],num3_str,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num4_b && !num1_b && !num2_b && !num3_b){ num4_str = "("+num4.ToString()+")"; Console.WriteLine(question,num1,sign[pick1],num2,sign[pick2],num3,sign[pick3],num4_str); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num1_b && num2_b &&!num3_b && !num4_b){ num1_str = "("+num1.ToString()+")"; num2_str = "("+num2.ToString()+")"; Console.WriteLine(question,num1_str,sign[pick1],num2_str,sign[pick2],num3,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num1_b && num3_b && !num2_b && !num4_b){ num1_str = "("+num1.ToString()+")"; num3_str = "("+num3.ToString()+")"; Console.WriteLine(question,num1_str,sign[pick1],num2,sign[pick2],num3_str,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num1_b && num4_b && !num2_b && !num3_b){ num1_str = "("+num1.ToString()+")"; num4_str = "("+num4.ToString()+")"; Console.WriteLine(question,num1_str,sign[pick1],num2,sign[pick2],num3,sign[pick3],num4_str); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num2_b && num3_b && !num1_b && !num4_b){ num2_str = "("+num2.ToString()+")"; num3_str = "("+num3.ToString()+")"; Console.WriteLine(question,num1,sign[pick1],num2_str,sign[pick2],num3_str,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num2_b && num4_b && !num1_b && !num3_b){ num2_str = "("+num2.ToString()+")"; num4_str = "("+num4.ToString()+")"; Console.WriteLine(question,num1,sign[pick1],num2_str,sign[pick2],num3,sign[pick3],num4_str); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num3_b && num4_b && !num1_b && !num2_b){ num3_str = "("+num3.ToString()+")"; num4_str = "("+num4.ToString()+")"; Console.WriteLine(question,num1,sign[pick1],num2,sign[pick2],num3_str,sign[pick3],num4_str); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num1_b && num2_b && num3_b && !num4_b){ num1_str = "("+num1.ToString()+")"; num2_str = "("+num2.ToString()+")"; num3_str = "("+num3.ToString()+")"; Console.WriteLine(question,num1_str,sign[pick1],num2_str,sign[pick2],num3_str,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num1_b && num3_b && num4_b && !num2_b){ num1_str = "("+num1.ToString()+")"; num3_str = "("+num3.ToString()+")"; num4_str = "("+num4.ToString()+")"; Console.WriteLine(question,num1_str,sign[pick1],num2,sign[pick2],num3_str,sign[pick3],num4_str); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num1_b && num2_b && num4_b && !num3_b){ num1_str = "("+num1.ToString()+")"; num2_str = "("+num2.ToString()+")"; num4_str = "("+num4.ToString()+")"; Console.WriteLine(question,num1_str,sign[pick1],num2_str,sign[pick2],num3,sign[pick3],num4_str); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else if (num2_b && num3_b && num4_b && !num1_b){ num2_str = "("+num2.ToString()+")"; num3_str = "("+num3.ToString()+")"; num4_str = "("+num4.ToString()+")"; Console.WriteLine(question,num1,sign[pick1],num2_str,sign[pick2],num3_str,sign[pick3],num4_str); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } else { Console.WriteLine(question,num1,sign[pick1],num2,sign[pick2],num3,sign[pick3],num4); Console.WriteLine(num1+sign[pick1]+num2+sign[pick2]+num3+sign[pick3]+num4); } } } public static void makeMixedNum() { int numQ = 150; int[] n = new int[10]; List<string> questions = new List<string> (); //Add List<string> addQ = new List<string> (); while (addQ.Count()<numQ) { //n[0] = Rand.Next(10,400); // for prime factorization int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } int y = Rand.Next(0,2); int z = Rand.Next(0,2); //Console.WriteLine("\\("+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+op[x]+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}=\\)"); if (n[1]!=n[3] && n[0]<n[1] && n[2]<n[3]) { double n0 = (double)n[0]; double n1 = (double)n[1]; double n2 = (double)n[2]; double n3 = (double)n[3]; Fraction left = new Fraction(n[4],n[0],n[1]); Fraction right = new Fraction(n[5],n[2],n[3]); Fraction result = (left + right).toMixed().Simplify(); // if the result is small enough (denominator <=20) if (result.denom <= 20 && result.integer<=20 && n[0]!=n[1] && n[2]!=n[3]) { if (result.integer!=0) { if (result.num!=0) { addQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+"+"+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.integer+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else addQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+"+"+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.integer+"\\)"); } else addQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+"+"+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } } } //Sub List<string> subQ = new List<string> (); while (subQ.Count()<numQ) { //n[0] = Rand.Next(10,400); // for prime factorization int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } int y = Rand.Next(0,2); int z = Rand.Next(0,2); //Console.WriteLine("\\("+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+op[x]+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}=\\)"); if (n[1]!=n[3] && n[0]<n[1] && n[2]<n[3]) { double n0 = (double)n[0]; double n1 = (double)n[1]; double n2 = (double)n[2]; double n3 = (double)n[3]; Fraction left = new Fraction(n[4],n[0],n[1]); Fraction right = new Fraction(n[5],n[2],n[3]); Fraction result = (left + right).toMixed().Simplify(); // if the result is small enough (denominator <=20) if (result.denom <= 20 && result.integer<=20 && n[0]!=n[1] && n[2]!=n[3]) { if (result.integer!=0) { if (result.num!=0) { subQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+"-"+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.integer+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else subQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+"-"+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.integer+"\\)"); } else subQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+"-"+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } } } //Mult List<string> multQ = new List<string> (); int q = numQ/2; int m = 5; int m2 = 15; while (multQ.Count()<q/m) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (multQ.Count()<(q/m)*2) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (multQ.Count()<(q/m)*3) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (multQ.Count()<(q/m)*4) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); if (GCD(n[0],n[1])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (multQ.Count()<(q/m)*5) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); if (GCD(n[2],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (multQ.Count()<q+q/m) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*2) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*3) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*4) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*5) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*6) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*7) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*8) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*9) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*10) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*11) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*12) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*13) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*14) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (multQ.Count()<q+(q/m2)*15) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left * right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { multQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\times"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } //Div List<string> divQ = new List<string> (); int q1 = numQ/2; int k = 5; int k2 = 15; while (divQ.Count()<q1/k) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (divQ.Count()<(q1/k)*2) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (divQ.Count()<(q1/k)*3) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (divQ.Count()<(q1/k)*4) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); if (GCD(n[0],n[1])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (divQ.Count()<(q1/k)*5) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); if (GCD(n[2],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } while (divQ.Count()<q1+q1/k) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*2) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*3) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*4) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*5) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction mixed, right regular fraction if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]<n[3]) { //Console.WriteLine(n[0] + "/" + n[1] +" " +n[4] + " " + n[6] +"/"+n[1]); if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div\\dfrac{"+n[2]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*6) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*7) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*8) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*9) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*10) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // left fraction regular, right mixed if (n[0]<n[1] && n[2]>n[3] && n[2]%n[3]!=0) { //Console.WriteLine(" " + n[2] + "/" + n[3] +" " +n[5] + " " + n[7] +"/"+n[3]); if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{\\dfrac{"+n[0]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*11) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*12) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*13) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[1],n[2])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*14) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[0],n[1])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } while (divQ.Count()<q1+(q1/k2)*15) { int size = 99; List<int> list = new List<int>(size); for(int i = 1; i <= size; i++) { list.Add(i); } //while(list.Count() > 0) { for (int i=0; i<n.Count(); i++) { int index = Rand.Next(list.Count()); n[i] = list[index]; list.RemoveAt(index); } Fraction left = new Fraction (n[0],n[1]); Fraction right = new Fraction (n[2],n[3]); Fraction result = (left / right).Simplify(); Fraction leftMixed = left.toMixed(); n[4] = (int) leftMixed.Integer; n[6] = (int) leftMixed.Num; Fraction rightMixed = right.toMixed(); n[5] = (int) rightMixed.Integer; n[7] = (int) rightMixed.Num; // both mixed fractions if (n[0]>n[1] && n[0]%n[1]!=0 && n[2]>n[3] && n[2]%n[3]!=0) { if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom!=1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+"\\dfrac{"+result.num+"}{"+result.denom+"}\\)"); } else if (GCD(n[2],n[3])!=1 && GCD(n[0],n[3])!=1 && result.denom <20 && result.num <20 && n[0]!=n[1] && n[2]!=n[3] && result.denom==1) { divQ.Add(" \\item \\(\\mathmakebox[2.05cm][r]{"+n[4]+"\\dfrac{"+n[6]+"}{"+n[1]+"}"+"\\div"+n[5]+"\\dfrac{"+n[7]+"}{"+n[3]+"}}="+"\\underline{\\hspace{3cm}\\vphantom{\\dfrac{1}{2}}}\\)"+result.num+"\\)"); } } } //questions.AddRange(addQ); //questions.AddRange(subQ); questions.AddRange(multQ); questions.AddRange(divQ); questions.Shuffle(); string title = "Fraction Multiplication \\& Division (General)"; string exerciseTitle = "Leave your +/- answers in simplest Mixed Number form and $\\times/\\div$ in Improper Fraction form unless otherwise instructed"; PrintFraction(questions, title, exerciseTitle); PrintAnswerKey(questions, title, 20); } public static Fraction[] simultF(int[] c, int[] d) { Fraction x, y; //int[] c = new int[3]; //int[] d = new int[3]; if(c.Length != 3 && d.Length!=3) throw new ArgumentException("array should be int[3]"); int yLeft = c[0]*d[2]-d[0]*c[2]; int yRight = c[0]*d[1]-d[0]*c[1]; y = new Fraction(yLeft, yRight); Fraction xLeft = c[2]-c[1]*y; int xRight = c[0]; x = new Fraction(xLeft,xRight); Fraction[] z = new Fraction[] {x,y}; //Console.WriteLine("x = {0}, y = {1}",x,y); return z; } public static double[] simultD(int[] c, int[] d) { double x,y; //int[] c = new int[3]; //int[] d = new int[3]; if(c.Length != 3 && d.Length!=3) throw new ArgumentException("array should be int[3]"); y = (double) (c[0]*d[2]-d[0]*c[2] ) / (c[0]*d[1]-d[0]*c[1]); x = (double) (c[2]-c[1]*y)/c[0]; double[] z = new double[] {x,y}; //Console.WriteLine("x = {0}, y = {1}",x,y); return z; } public static void simultQ() { int[] c = new int[6]; int count = 0; List<string> questions = new List<string>(); int[] numArray = new int[] {-9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9}; while (questions.Count()<100 || count <100 ) { for (int i = 0; i<c.Length; i++) { c[i] = numArray[Rand.Next(1,17)]; } if (c[0]*c[4]!=c[3]*c[1]) { Fraction[] result = simultF(new int[] {c[0], c[1], c[2]}, new int[] {c[3], c[4], c[5]}); Fraction parse; // //if (Math.Abs(result[0]*result[1])<200 && result[0]%1==0 && result[1]%1==0 && result[0]+result[1]!=0 && result[0]*result[1]!=0) { if (Math.Abs((result[0]*result[1]).toDeci())<200 && result[0].Num+result[1].Num!=0 && result[0].Num*result[1].Num!=0 && Math.Abs(result[0].num)<10 && Math.Abs(result[0].denom)<10 && Math.Abs(result[1].num)<10 && Math.Abs(result[1].denom)<10) { count++; if (c[1]<0 && c[4]>0) { // if x is a fraction but y is not if (Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+result[1].Simplify()+"$"); } // if x is not a fraction but y is else if (!Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } // if x and y are fractions else if (Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } else if (!Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } //questions.Add(c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]); //questions.Add(c[3]+"x + "+ c[4]+"y &= "+c[5]); //questions.Add("\\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } else if (c[1]>0 && c[4]<0) { // if x is a fraction but y is not if (Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+result[1].Simplify()+"$"); } // if x is not a fraction but y is else if (!Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } // if x and y are fractions else if (Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } else if (!Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } //questions.Add(c[0]+"x + "+ c[1]+"y &= "+c[2]); //questions.Add(c[3]+"x - "+ Math.Abs(c[4])+"y &= "+c[5]); //questions.Add("\\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } else if (c[1]<0 && c[4]<0) { // if x is a fraction but y is not if (Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+ Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+result[1].Simplify()+"$"); } // if x is not a fraction but y is else if (!Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+ Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } // if x and y are fractions else if (Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+ Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } else if (!Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]+" \\\\ "+c[3]+"x - "+ Math.Abs(c[4])+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } //questions.Add(c[0]+"x - "+ Math.Abs(c[1])+"y &= "+c[2]); //questions.Add(c[3]+"x - "+ Math.Abs(c[4])+"y &= "+c[5]); //questions.Add("\\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } else { // if x is a fraction but y is not if (Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+result[1].Simplify()+"$"); } // if x is not a fraction but y is else if (!Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } // if x and y are fractions else if (Fraction.TryParse(result[0].ToString(), out parse) && Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = \\frac{"+result[0].Simplify().Num+"}{"+result[0].Simplify().Denom+"}, y = "+"\\frac{"+result[1].Simplify().Num+"}{"+result[1].Simplify().Denom+"}$"); } else if (!Fraction.TryParse(result[0].ToString(), out parse) && !Fraction.TryParse(result[1].ToString(), out parse)) { questions.Add(" \\item \\(\\begin{array}{rl}"+c[0]+"x + "+ c[1]+"y &= "+c[2]+" \\\\ "+c[3]+"x + "+ c[4]+"y &= "+c[5] + "\\end{array}\\) \\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } //questions.Add(c[0]+"x + "+ c[1]+"y &= "+c[2]); //questions.Add(c[3]+"x + "+ c[4]+"y &= "+c[5]); //questions.Add("\\\\@$x = "+result[0].Simplify()+", y = "+result[1].Simplify()+"$"); } } } } questions.Shuffle(); string title = "Simultaneous Equations"; string exerciseTitle = "Solve for $x$ and $y$"; Print(questions, title, exerciseTitle, 20); } /***************************************************** /////////////////////LATEX CODES////////////////////// *****************************************************/ public static void PrintArithmetic<T>(List<T> list, string title) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{16pt}{25pt}\\selectfont", " \\setlength\\itemsep{10pt}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); //Console.WriteLine("\\subsection{Exercise "+(i/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*), align=center,leftmargin=40pt]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine("\\end{center}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-33mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine("\\subsection{Exercise "+((i+30)/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*), align=center,leftmargin=40pt]"); Console.WriteLine(latex[1]); } } } public static void PrintArithmetic<T>(List<T> list, string title, string subtitle) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{16pt}{25pt}\\selectfont", " \\setlength\\itemsep{10pt}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\"); Console.WriteLine(" \\small ("+subtitle+")"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); //Console.WriteLine("\\subsection{Exercise "+(i/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*), align=center,leftmargin=40pt]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine("\\end{center}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-33mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\"); Console.WriteLine(" \\small ("+subtitle+")"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine("\\subsection{Exercise "+((i+30)/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*), align=center,leftmargin=40pt]"); Console.WriteLine(latex[1]); } } } public static void PrintArithmetic<T>(List<T> list, string title, int questions) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{16pt}{25pt}\\selectfont", " \\setlength\\itemsep{10pt}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); //Console.WriteLine("\\subsection{Exercise "+(i/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*), align=center,leftmargin=40pt]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%questions==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine("\\end{center}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-33mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine("\\subsection{Exercise "+((i+questions)/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*), align=center,leftmargin=40pt]"); Console.WriteLine(latex[1]); } } } public static void Print<T>(List<T> list, string title, string exerciseTitle) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+(i/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine("\\end{center}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\end{center}"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+((i+30)/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{center}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static void PrintAnswerKey<T>(List<T> list, string title, int questions) { int p = 5; // number of pages before new page Console.WriteLine(); Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\newgeometry{"); Console.WriteLine(" a4paper,"); Console.WriteLine(" total={170mm,257mm},"); Console.WriteLine(" left=15mm,"); // 10mm for fractions Console.WriteLine(" top=20mm,"); Console.WriteLine(" bottom=20mm,"); Console.WriteLine(" right=15mm"); //10mm for fractions Console.WriteLine(" }"); Console.WriteLine("\\fontsize{10pt}{10pt}\\selectfont"); Console.WriteLine(); Console.WriteLine("\\section{"+title+" Answer Key}"); for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\textbf{p"+(i/questions+1)+"}"); Console.WriteLine(); Console.WriteLine("\\begin{multicols}{5}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%(questions*p)==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\textbf{p"+((i+questions)/questions+1)+"}"); Console.WriteLine(); Console.WriteLine("\\begin{multicols}{5}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } if (i!=0 && (i+1)%questions==0 && (i+1)%(questions*p)!=0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\textbf{p"+((i+questions)/questions+1)+"}"); Console.WriteLine("\\begin{multicols}{5}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } } } public static void Print<T>(List<T> list, string title, string exerciseTitle, int questions) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+(i/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%questions==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+((i+questions)/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static void PrintFraction<T>(List<T> list, string title, string exerciseTitle) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{1.8em}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine(latex[0]); Console.WriteLine("\\vspace{-5mm}\\subsection{Exercise "+(i/20+1)+". "+exerciseTitle+".}"); //Console.WriteLine("\\begin{tasks}(2)"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%20==0){ //Console.WriteLine("\\end{tasks}"); Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+((i+20)/20+1)+". "+exerciseTitle+".}"); //Console.WriteLine("\\begin{tasks}(2)"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static long GCD(long a, long b) { return b == 0 ? a : GCD(b, a % b); } public static long GCD(long a, long b, long c) { return GCD(a, GCD(b,c)); } public static void LCM(int a, int b) { int lcm; int a_r=a; int b_r=b; int d=max(a_r,b_r); while(d>1) { if (a_r%d==0 && b_r%d==0) { int a_r_temp=a_r/d; int b_r_temp=b_r/d; a_r=a_r_temp; b_r=b_r_temp; lcm=d*a_r*b_r; break; } d--; } lcm=d*a_r*b_r; Console.WriteLine("LCM({0},{1}): {2}", a,b,lcm); } public static int lcm(int a, int b) { int lcm; int a_r=a; int b_r=b; int d=max(a_r,b_r); while(d>1) { if (a_r%d==0 && b_r%d==0) { int a_r_temp=a_r/d; int b_r_temp=b_r/d; a_r=a_r_temp; b_r=b_r_temp; lcm=d*a_r*b_r; break; } d--; } return d*a_r*b_r; //Console.WriteLine("LCM({0},{1}): {2}", a,b,lcm); } public static void LCM(int a, int b, int c) { Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm(a,lcm(b,c))); } public static int lcm(int a, int b, int c) { return lcm(a,lcm(b,c)); } public static int max(int a, int b) { if (a>b){ return a; } else if (b>a){ return b; } else { return a; } } public static int max(int a, int b, int c) { return max(a,max(b,c)); } public static int min(int a, int b) { if (a>b){ return b; } else if (b>a){ return a; } else { return a; } } public static int min(int a, int b, int c) { return min(a,min(b,c)); } public static void Pyth(int lowerBound, int upperBound) { //Your code goes here for (int i=lowerBound; i<=upperBound; i++) { for (int j=lowerBound; j<=upperBound; j++){ double c = Math.Sqrt(Math.Pow(i,2)+Math.Pow(j,2)); if (c%1==0){ Console.WriteLine("(a,b,c) = (" + i + "," + j + "," + c + ")"); } } } } public static void areaTrapezoid(double top, double bottom, double height) { double area = (top+bottom)*height/2; Console.WriteLine("Area: {0}", area); } public static void volumeCylinder ( double radius, double height) { double vol = radius*radius*Math.PI*height; Console.WriteLine("Volume: {0}", vol); } public static void sAreaCylinder(double radius, double height) { double s_area = 2*calcAreaCircle(radius) + calcAreaCircle(radius)*height; Console.WriteLine("Surface Area: {0}", s_area); } public static void Circumf(int radius){ double circ = 2*radius*Math.PI; Console.WriteLine("Circumference: {0}", circ); } public static void areaCircle(double r){ double area = r*r*Math.PI; Console.WriteLine("Area: {0}", area); } public static double calcAreaCircle(double r){ return r*r*Math.PI; } public static double calcCircumCircle(double r){ return 2*r*Math.PI; } public static double sAreaCone(int r, int l) { return Math.PI*r*r+Math.PI*r*l; } public static double volumeCone(int r, int h){ return Math.PI*r*r/3; } public static void SimplifyRatio(int ratio1, int ratio2, int ratio3) { int divisor; if (ratio1>ratio2 && ratio1>ratio3) { divisor = ratio1; } else if (ratio2>ratio1 && ratio2>ratio3) { divisor = ratio2; } else divisor = ratio3; int ratio1_reduce = ratio1; int ratio2_reduce = ratio2; int ratio3_reduce = ratio3; while (divisor!=1) { if(ratio1_reduce%divisor==0 && ratio2_reduce%divisor==0 && ratio3_reduce%divisor==0){ int ratio1_reduce_temp = ratio1_reduce/divisor; int ratio2_reduce_temp = ratio2_reduce/divisor; int ratio3_reduce_temp = ratio3_reduce/divisor; ratio1_reduce = ratio1_reduce_temp; ratio2_reduce = ratio2_reduce_temp; ratio3_reduce = ratio3_reduce_temp; divisor--; } else divisor--; } Console.WriteLine(ratio1+":"+ratio2+":"+ratio3+" = "+ratio1_reduce+":"+ratio2_reduce+":"+ratio3_reduce); } public static void checkAlgebra(){ for (int x = -40; x<40; x++) { int a = 62*x-68; int b = 35; if (a%b==0){ Console.WriteLine(x); } } } public static void addLineBreak(int linesPerSection, int totalLines) { for (int i=0; i<=totalLines; i++) { if (i%linesPerSection==0) { Console.WriteLine("Break"); } else Console.WriteLine("No"); } } public static void circleX(double x, double radius) { Console.WriteLine("("+x+", "+Math.Round(Math.Sqrt(radius*radius-Math.Pow(x,2)),3)+")"); } public static void circleY(double y, double radius) { Console.WriteLine("("+y+", "+Math.Round(Math.Sqrt(radius*radius-Math.Pow(y,2)),3)+")"); } public static void angle(double x1, double y1, double x2, double y2, double x3, double y3) { double l12 = Math.Pow((x1-x2),2) +Math.Pow((y1-y2),2); double l13 = Math.Pow((x3-x1),2) +Math.Pow((y3-y1),2); double l23 = Math.Pow((x3-x2),2) +Math.Pow((y3-y2),2); double lhs = (l13-l12-l23)/(-2*Math.Sqrt(l12)*Math.Sqrt(l23)); double angle2 = Math.Acos(lhs); //double angle2 = Math.Round(Math.Acos()*100,3); //Console.WriteLine(angle2 + " degrees C"); Console.WriteLine(l12 + " " + l23 + " " + l13); Console.WriteLine(lhs); Console.WriteLine(angle2*360/(2*Math.PI)+" degrees"); } public static bool UniqueInList(string n, List<string> t) { int count = 0; for (int i=0; i<t.Count(); i++) { if (!n.Equals(t[i])) count++; } if (count.Equals(t.Count())) return true; else return false; } public static bool UniqueInListInt(int n, List<int> t) { int count = 0; for (int i=0; i<t.Count(); i++) { if (!n.Equals(t[i])) count++; } if (count.Equals(t.Count())) return true; else return false; } public static bool Unique(List<string> t){ int count = 0; for (int i=0; i<t.Count()-1; i++){ for (int j=i+1; j<t.Count(); j++) { //Console.WriteLine(i + " " + j); if (!t[i].Equals(t[j])){ count++; } } } if (count.Equals(nCr(t.Count(),2))) { return true; } else return false; } public static int nCr(int n, int r) { return (Factorial(n)/Factorial(r))/Factorial(n-r); } public static int Factorial(int n) { if (n>0) { for (int i=n-1; i>1; i--) { n = n*i; } return n; } else if (n<0) throw new ArgumentOutOfRangeException("n","n should be non-zero"); else return 1; } } public static class Rand { /// <summary> /// Random number generator used to generate seeds, /// which are then used to create new random number /// generators on a per-thread basis. /// </summary> private static readonly Random globalRandom = new Random(); private static readonly object globalLock = new object(); /// <summary> /// Random number generator /// </summary> private static readonly ThreadLocal<Random> threadRandom = new ThreadLocal<Random>(NewRandom); /// <summary> /// Creates a new instance of Random. The seed is derived /// from a global (static) instance of Random, rather /// than time. /// </summary> public static Random NewRandom() { lock (globalLock) { return new Random(globalRandom.Next()); } } /// <summary> /// Returns an instance of Random which can be used freely /// within the current thread. /// </summary> public static Random Instance { get { return threadRandom.Value; } } /// <summary>See <see cref="Random.Next()" /></summary> public static int Next() { return Instance.Next(); } /// <summary>See <see cref="Random.Next(int)" /></summary> public static int Next(int maxValue) { return Instance.Next(maxValue); } /// <summary>See <see cref="Random.Next(int, int)" /></summary> public static int Next(int minValue, int maxValue) { return Instance.Next(minValue, maxValue); } public static int NextPM(int minValue, int maxValue) { // positive if (Rand.Next(0,2)==0) { return Instance.Next(minValue, maxValue); } else return -Instance.Next(minValue, maxValue); } /// <summary>See <see cref="Random.NextDouble()" /></summary> public static double NextDouble() { return Instance.NextDouble(); } /// <summary>See <see cref="Random.NextBytes(byte[])" /></summary> public static void NextBytes(byte[] buffer) { Instance.NextBytes(buffer); } public static double NextD(double minValue, double maxValue) { return Instance.NextDouble()*(maxValue-minValue)+minValue; } } } namespace ShuffleExtension { public static class ShuffleExtend { //private static readonly Random rnd = new Random(); public static void Shuffle<T>(this IList<T> list) { int n = list.Count; while (n > 1) { int k = (Rextester.Rand.Next(0, n) % n); n--; T value = list[k]; list[k] = list[n]; list[n] = value; } } } } namespace CountExtension { public static class CountExtension { public static int Count(this int n) { //return (Value == 0 ? 1 : ((int)Math.Floor(Math.Log10(Math.Abs(Value))) + 1)); return (n == 0 ? 1 : (int)Math.Log10(Math.Abs(n)) + 1); } } } namespace MathSpace { public struct Fraction { public long num; public long denom; public long integer; public long Num { get { return num; } set { num = value; } } public long Denom { get { return denom; } set { denom = value; } } public long Integer { get { return integer; } set { integer = value; } } public Fraction(int num, int denom) { // num + denom - if (num > 0 && denom < 0) { this.num = -num; this.denom = Math.Abs(denom); this.integer = 0; } // num - denom + else if (num < 0 && denom > 0 ) { this.num = -Math.Abs(num); this.denom = Math.Abs(denom); this.integer = 0; } // both positive or negative or zero else { this.num = Math.Abs(num); this.denom = Math.Abs(denom); this.integer = 0; } } public Fraction(long num, long denom) { // num + denom - if (num > 0 && denom < 0) { this.num = -num; this.denom = Math.Abs(denom); this.integer = 0; } // num - denom + else if (num < 0 && denom > 0 ) { this.num = num; this.denom = Math.Abs(denom); this.integer = 0; } // both positive or negative or zero else { this.num = Math.Abs(num); this.denom = Math.Abs(denom); this.integer = 0; } } public Fraction(int integer, int num, int denom) { if (num*denom<0) throw new ArgumentException("Numerator and Denominator must be positive."); // all + or only two + if (integer * num * denom > 0 ) { this.integer = Math.Abs(integer); this.num = Math.Abs(num); this.denom = Math.Abs(denom); } // if an odd - else { this.integer = -integer; this.num = Math.Abs(num); this.denom = Math.Abs(denom); } } public Fraction(long integer, long num, long denom) { if (num*denom<0) throw new ArgumentException("Numerator and Denominator must be positive."); // all + or only two + if (integer * num * denom > 0 ) { this.integer = Math.Abs(integer); this.num = Math.Abs(num); this.denom = Math.Abs(denom); } // if an odd - else { this.integer = -integer; this.num = Math.Abs(num); this.denom = Math.Abs(denom); } } public Fraction (Fraction left, int right) { Fraction result = left/right; this.num = result.num; this.denom = result.denom; this.integer = 0; } public Fraction (int left, Fraction right) { Fraction result = left/right; this.num = result.num; this.denom = result.denom; this.integer = 0; } public Fraction (Fraction left, Fraction right) { Fraction result = left/right; this.num = result.num; this.denom = result.denom; this.integer = 0; } public Fraction toMixed() { if (this.integer == 0 && (this.num < 0 || this.denom < 0)) { return new Fraction(this.num / this.denom, Math.Abs(this.num % this.denom), Math.Abs(this.denom)); } else if (this.integer == 0 && (this.num * this.denom > 0)) { return new Fraction(this.num / this.denom, this.num % this.denom, this.denom); } else return new Fraction(this.integer + this.num / this.denom, this.num % this.denom, this.denom); } public Fraction toImproper() { if (this.integer!=0 && this.integer<0) { return new Fraction (-(Math.Abs(this.integer)*Math.Abs(this.denom)+Math.Abs(this.num)),Math.Abs(this.denom)); } else if (this.integer!=0 && this.integer>0) { return new Fraction (Math.Abs(this.integer)*Math.Abs(this.denom)+Math.Abs(this.num),Math.Abs(this.denom)); } else return new Fraction (this.num,this.denom); } public override string ToString() { if (this.denom == 0) { return "Div by 0"; } // if fraction is proper or improper fraction if (this.denom != 1 && this.integer == 0 && this.num%this.denom!=0) { // if fraction is negative (either num or denom negative but not both) if ((this.num < 0 || this.denom < 0 ) && !(this.num<0 && this.denom<0) ) { this.denom = Math.Abs(this.denom); return this.num + "/" + this.denom; } // if fraction is positive else return num + "/" + denom; // + ", " + num/denom + " " + num%denom + "/" + denom; } //if fraction is mixed number else if (this.denom != 1 && this.integer != 0 && this.num%this.denom!=0) { var new_integer = Math.Abs(this.integer) + this.num/this.denom; var new_num = this.num % this.denom; this.integer = new_integer; this.num = new_num; // if fraction is negative (either num or denom negative but not both) if (this.integer < 0) { return this.integer + " " + this.num + "/" + this.denom; } // if fraction is positive else return this.integer + " " + this.num + "/" + this.denom; } // if denom not 1 and numerator is a multiple of the denominator (ie. 4/2 ==> 2) and not mixed number (result is integer) else if (this.num % this.denom == 0 && this.integer==0) { return (this.num / this.denom).ToString(); } // if denom not 1 and numerator is a multiple of the denominator (ie. 4/2 ==> 2) and mixed number (result is integer) else if (this.num % this.denom == 0 && this.integer!=0) { return (this.integer+(this.num / this.denom)).ToString(); } // if denominator is 1, ie., whole number and not mixed number else if (this.integer!=0) { return (integer+num).ToString(); } else return num.ToString(); } public Fraction Simplify() { int divisor = Convert.ToInt32(GCD(this.num, this.denom)); if (this.denom != 0 && this.integer==0 && this.num >0) { return new Fraction(this.num / divisor, this.denom / divisor); } else if (this.denom != 0 && this.integer==0 && this.num <0) { return new Fraction(-Math.Abs(this.num / divisor), Math.Abs(this.denom / divisor)); } else if (this.denom != 0 && this.integer!=0) { return new Fraction(this.integer, this.num / divisor, this.denom / divisor); } else return new Fraction (this.num, this.denom); } public static long GCD(long a, long b) { return b == 0 ? a : GCD(b, a % b); } public Fraction Reciprocal() { return new Fraction(this.Denom, this.Num); } public static Fraction operator +(Fraction left, Fraction right) { Fraction result; if (left.integer==0 &&right.integer==0){ result = new Fraction(left.num * right.denom + right.num * left.denom, left.denom * right.denom); } else { //result = new Fraction((left.integer*left.denom+left.num)*right.denom+(right.integer*right.denom+right.num)*left.denom, left.denom * right.denom); result = (new Fraction(left.integer+right.integer, left.num * right.denom + right.num * left.denom, left.denom * right.denom)).toMixed(); } return result.toMixed().Simplify(); } public static Fraction operator +(int left, Fraction right) { Fraction result; if (right.integer==0) { result = new Fraction(left * right.denom + right.num, right.denom); } else { result = (new Fraction(left+right.integer, right.num, right.denom)).toMixed(); } return result.Simplify(); } public static Fraction operator +(Fraction left, int right) { Fraction result; if (left.integer==0) { result = new Fraction(left.num + left.denom * right, left.denom); } else { result = (new Fraction(left.integer+right, left.denom)).toMixed(); } return result.Simplify(); } public static Fraction operator -(Fraction frac) { if (frac.integer==0) { return new Fraction(-frac.num,frac.denom); } else return (new Fraction (-frac.integer,frac.num,frac.denom)).toMixed(); } public static Fraction operator -(Fraction left, Fraction right) { Fraction result; if (left.integer==0 && right.integer==0) { result = (new Fraction(left.num * right.denom - right.num * left.denom, left.denom * right.denom)).toMixed(); } else { if (((left.integer*left.denom+left.num)/left.denom)>=((right.integer*right.denom+right.num)/right.denom)) { result = (left.toImproper()-right.toImproper()).toMixed(); } else result = (left.toImproper()-right.toImproper()).toMixed(); } return result.Simplify(); } public static Fraction operator -(int left, Fraction right) { Fraction result; if (right.integer==0) { result = new Fraction(left * right.denom - right.num, right.denom); } else result = (new Fraction(left * right.denom - right.toImproper().num, right.denom)).toMixed(); return result.Simplify(); } public static Fraction operator -(Fraction left, int right) { Fraction result; if (left.integer==0) { result = new Fraction(left.num - left.denom * right, left.denom); } // if mixed numbers else result = (new Fraction(left.toImproper().num - left.denom * right, left.denom)).toMixed(); return result.Simplify(); } public static Fraction operator *(Fraction left, Fraction right) { Fraction result; if (left.integer==0 && right.integer==0){ result = new Fraction(left.num * right.num, Math.Abs(left.denom * right.denom)); } // if mixed numbers else result = (left.toImproper()*right.toImproper()).toMixed(); return result.Simplify(); } public static Fraction operator *(int left, Fraction right) { Fraction result; if (right.integer==0){ result = new Fraction(left * right.num, right.denom); } else result = (new Fraction(right.toImproper().num * left, right.denom)).toMixed(); return result.Simplify(); } public static Fraction operator *(Fraction left, int right) { Fraction result; // if improper fraction if (left.integer==0){ result = new Fraction(left.num * right, left.denom); } // if mixed numbers else result = (new Fraction(left.toImproper().num * right, left.denom)).toMixed(); return result.Simplify(); } public static Fraction operator /(Fraction left, Fraction right) { Fraction result; if (left.integer==0 &&right.integer==0){ result = left * right.Reciprocal(); } else result = (left.toImproper() * right.toImproper().Reciprocal()).toMixed(); return result.Simplify(); } public static Fraction operator /(int left, Fraction right) { Fraction result; if (right.integer==0) { result = left * right.Reciprocal(); } else result = left * right.toImproper().Reciprocal(); return result.Simplify(); } public static Fraction operator /(Fraction left, int right) { Fraction rightRecip = new Fraction(1,right); Fraction result; if (left.integer==0) { result = left * rightRecip; } else { result = left.toImproper() * rightRecip; } return result.Simplify(); } public static int LCM(int a, int b) { int lcm; int a_r = a; int b_r = b; int d = max(a_r, b_r); while (d > 1) { if (a_r % d == 0 && b_r % d == 0) { int a_r_temp = a_r / d; int b_r_temp = b_r / d; a_r = a_r_temp; b_r = b_r_temp; lcm = d * a_r * b_r; break; } d--; } lcm = d * a_r * b_r; return lcm; } public static int LCM(long a, long b) { int lcm; long a_r = a; long b_r = b; int d = Convert.ToInt32(max(a_r, b_r)); while (d > 1) { if (a_r % d == 0 && b_r % d == 0) { long a_r_temp = a_r / d; long b_r_temp = b_r / d; a_r = a_r_temp; b_r = b_r_temp; lcm = Convert.ToInt32(d * a_r * b_r); break; } d--; } lcm = Convert.ToInt32(d * a_r * b_r); return lcm; } public static int max(int a, int b) { if (a > b) { return a; } else if (b > a) { return b; } else { return a; } } public static long max(long a, long b) { if (a > b) { return a; } else if (b > a) { return b; } else { return a; } } public double toDeci() { if (this.integer==0) { return (double) this.num/this.denom; } else { return (double) (this.integer*this.denom+this.num)/this.denom; } } public static Fraction toFrac(double deci) { /*List<double> d = new List<double>(); List<double> z = new List<double>(); List<double> n = new List<double>();*/ double[] d = new double[6]; double[] z = new double[6]; double[] n = new double[6]; z[1] = deci; //X d[0] = 0; d[1] = 1; for (int i = 1; i < 5; i++) { z[i + 1] = 1 / (z[i] - Math.Floor(z[i])); d[i + 1] = d[i] * Math.Floor(z[i + 1]) + d[i - 1]; n[i + 1] = Math.Round(z[1] * d[i + 1]); } int num, denom; num = (int)n[5]; denom = (int)d[5]; return new Fraction(num, denom); } /* public static Fraction RealToFraction(double value, double error) { if (error <= 0.0 || error >= 1.0) { throw new ArgumentOutOfRangeException("error", "Must be between 0 and 1 (exclusive)."); } int sign = Math.Sign(value); if (sign == -1) { value = Math.Abs(value); } if (sign != 0) { // error is the maximum relative error; convert to absolute error *= value; } int n = (int)Math.Floor(value); value -= n; if (value < error) { return new Fraction(sign * n, 1); } if (1 - error < value) { return new Fraction(sign * (n + 1), 1); } // The lower fraction is 0/1 int lower_n = 0; int lower_d = 1; // The upper fraction is 1/1 int upper_n = 1; int upper_d = 1; while (true) { // The middle fraction is (lower_n + upper_n) / (lower_d + upper_d) int middle_n = lower_n + upper_n; int middle_d = lower_d + upper_d; if (middle_d * (value + error) < middle_n) { // real + error < middle : middle is our new upper upper_n = middle_n; upper_d = middle_d; } else if (middle_n < (value - error) * middle_d) { // middle < real - error : middle is our new lower lower_n = middle_n; lower_d = middle_d; } else { // Middle is our best fraction return new Fraction((n * middle_d + middle_n) * sign, middle_d); } } }*/ public static Fraction Parse(string input) { if (String.IsNullOrWhiteSpace(input)) { throw new ArgumentNullException(); } //var instance = new Fraction(); // checks if there is more than one "/" if (input.IndexOf("/") != input.LastIndexOf("/")) { throw new ArgumentException(); } //return instance; int v; // if (input.IndexOf("/") != -1) { if (int.TryParse(input.Substring(0, input.IndexOf("/")), out v) && int.TryParse(input.Substring(input.IndexOf("/") + 1), out v)) { int num1 = int.Parse(input.Substring(0, input.IndexOf("/"))); int denom1 = int.Parse(input.Substring(input.IndexOf("/") + 1)); var frac = new Fraction(num1, denom1); return frac; } else throw new IndexOutOfRangeException(); } else // if { if (int.TryParse(input, out v)) { return new Fraction(int.Parse(input), 1); } else throw new IndexOutOfRangeException(); } } public static bool TryParse(string input, out Fraction frac) { if (string.IsNullOrWhiteSpace(input)) { frac = new Fraction(0, 0); return false; } if (input.IndexOf("/") == -1 || input.IndexOf("/") != input.LastIndexOf("/")) { frac = new Fraction(0, 0); return false; } long v; if (long.TryParse(input.Substring(0, input.IndexOf("/")), out v) && long.TryParse(input.Substring(input.IndexOf("/") + 1), out v)) { frac = new MathSpace.Fraction(1, 1); v = 1; return true; } else frac = new Fraction(0, 0); return false; } public static Fraction ConvertFrom(object obj) { Fraction frac = new MathSpace.Fraction(0, 0); if (obj.GetType() == frac.GetType()) { frac = (Fraction) obj; return frac; } else throw new NotSupportedException(); } public static double ConvertToDecimal(Fraction frac) { return Convert.ToDouble(frac.Num) / Convert.ToDouble(frac.Denom); } public static double operator +(Fraction left, double right) { double result = ConvertToDecimal(left) + right; return result; } public static double operator +(double left, Fraction right) { double result = left + ConvertToDecimal(right); return result; } public static double operator -(Fraction left, double right) { double result = ConvertToDecimal(left) - right; return result; } public static double operator -(double left, Fraction right) { double result = left - ConvertToDecimal(right); return result; } public static double operator *(Fraction left, double right) { double result = ConvertToDecimal(left) * right; return result; } public static double operator *(double left, Fraction right) { double result = left * ConvertToDecimal(right); return result; } public static double operator /(Fraction left, double right) { double result = ConvertToDecimal(left) / right; return result; } public static double operator /(double left, Fraction right) { double result = left / ConvertToDecimal(right); return result; } public static Fraction Pow(Fraction frac, int n) { long num_new = (long) Math.Pow(frac.Num, n); long denom_new = (long) Math.Pow(frac.Denom, n); return new MathSpace.Fraction(num_new, denom_new); } } }
run
|
edit
|
history
|
help
0
conter 1 in binnary number
Planet-D ver. 0.5
ElaineBrown**
QuickSort
Dependencia de datos
Ortalama Hesaplayici
Lottofacil
factorial ncr
Composition
C# - String Parsing