Main
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using ShuffleExtension;
using System.Threading;
namespace Rextester
{
public class Program {
private static readonly Random rand = new Random();
public int ratio1;
public int ratio2;
public int ratio3;
public int num1, num2, num3;
public static void Main(String[] args){
makeSubQ2by2(10,100,10,100);
}
public static void makeSubQ2by2(int firstLowerBound, int firstUpperBound, int secondLowerBound, int secondUpperBound){
string title = "Subtraction ()";
string exerciseTitle = "Calculate.";
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 =")=\\)";
List<string> questions = new List<string>();
for (int i=10; i<100;i++){
for (int j=10; j<100;j++){
if (i!=j && i+j<100){questions.Add(" \\task \\(\\mathmakebox[1.45cm][r]{"+i+"-"+j+"}=\\underline{\\hspace{2cm}}\\)");}
}
}
questions.Shuffle();
Print(questions);
}
public static void makeAlg(){
Random rand =new Random();
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=1; i<100;i++){
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}}\\)");}
}
}
questions.Shuffle();
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("\\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("\\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"};
int n=-1;
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[2] {"(", ")("};
string end =")=\\)";
for (int i=1; i<=i_final; i++) {
int num2=rand.Next(0,3);
int num = rand.Next(2,5);
int consts=rand.Next(1,6);
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("\\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){
Console.Write(" \\item \\(");
}
if (n==0){
Console.Write(consts+vari[num2+3*incre]+op[0]);
}
else if (n>0 && n<num){
Console.Write(consts+vari[num2+3*incre]+op[1]);
}
n++;
if (n==num){
m++;
Console.Write(consts+vari[num2+3*incre]);
Console.Write(end);
Console.WriteLine();
if (m%30==0) {
incre=rand.Next(0,8);
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("\\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,8);
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("\\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;
}
}
}
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(){
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 MixedNum() {
Random rand =new Random();
int[] n = new int[10];
List<string> questions = new List<string> ();
List<string> lines = new List<string>();
lines.Add("\\begin{figure}[ht!]");
lines.Add("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}");
lines.Add("\\end{figure}");
lines.Add("");
lines.Add("\\begin{addmargin}[21em]{0em}");
lines.Add("\\vspace{-26mm}Name: \\underline{\\hspace{5cm}} \\\\[0.5em]");
lines.Add("\\end{addmargin}\\vspace{5mm}");
lines.Add("");
lines.Add("\\vspace{-10mm}\\begingroup");
lines.Add("\\centering");
lines.Add("\\LARGE Revision \\\\[0.5em]");
lines.Add("\\endgroup");
lines.Add("");
lines.Add("\\section{What numbers (from 2 to 9) can these numbers be divisible by?}");
lines.Add("\\begin{tasks}(2)");
while (questions.Count()<300) {
n[0]=rand.Next(3,8);
n[1]=rand.Next();
for (int i =0; i<n.Length; i++){
n[i] = rand.Next(1,13);
n[1] = rand.Next(2,13);
n[3] = rand.Next(2,13);
n[4] = rand.Next(2,10);
n[5] = rand.Next(2,10);
}
string[] op = new string[] {"+","-"};
int x = rand.Next(0,op.Count());
int y = rand.Next(0,2);
int z = rand.Next(0,2);
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];
if (op[x].Equals("-")){
if(n[4]>n[5]) {
questions.Add(" \\task \\("+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+op[x]+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}=\\underline{\\hspace{2cm}}\\)\\\\");
}
else if (n[4]==n[5] && ((double)n[0]/(double)n[1])>((double)n[2]/(double)n[3])){
questions.Add(" \\task \\("+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+op[x]+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}=\\underline{\\hspace{2cm}}\\)\\\\");
}
}
else {
questions.Add(" \\task \\("+n[4]+"\\dfrac{"+n[0]+"}{"+n[1]+"}"+op[x]+n[5]+"\\dfrac{"+n[2]+"}{"+n[3]+"}=\\underline{\\hspace{2cm}}\\)\\\\");
}
}
}
int counter=0;
int increment=29;
for (int i=0; i<questions.Count(); i++) {
if ((i)%30==0){
Console.WriteLine("Begin");
}
Console.WriteLine(questions[i]);
if( i==increment) {
Console.WriteLine("End");
}
increment = increment + counter*30;
counter = counter+1;
}
}
public static void Print<T>(List<T> list) {
string title = "Title ()";
string exerciseTitle = "Instructions.";
string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"};
string[] op = new string[2] {"(", ")("};
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("\\textbf{Exercise "+(i/30+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)%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("\\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 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 void LCM(int a, int b, int c) {
int lcm;
if (a==0) {
Console.Write("LCM("+a+","+b+","+c+") = ");
LCM(b,c);
}
else if (b==0) {
Console.Write("LCM("+a+","+b+","+c+") = ");
LCM(a,c);
}
else if(c==0) {
Console.Write("LCM("+a+","+b+","+c+") = ");
LCM(a,b);
}
else if (a==b && b==c) {
Console.WriteLine("LCM: "+a);
}
else if (a==b && a!=c) {
if (a>c) {
for (int i=a; a>1; i--) {
if (a%i==0 && c%i==0) {
int a_reduced=a/i;
int c_reduced=c/i;
lcm = i*a_reduced*c_reduced;
Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm);
break;
}
}
}
else {
for (int i=c; c>1; i--) {
if (a%i==0 && c%i==0) {
int a_reduced=a/i;
int c_reduced=c/i;
lcm = i*a_reduced*c_reduced;
Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm);
break;
}
}
}
}
else if (b==c && a!=b) {
if (a>b) {
for (int i=a; a>1; i--) {
if (a%i==0 && b%i==0) {
int a_reduced=a/i;
int b_reduced=b/i;
lcm = i*a_reduced*b_reduced;
Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm);
break;
}
}
}
else {
for (int i=b; b>1; i--) {
if (a%i==0 && b%i==0) {
int a_reduced=a/i;
int b_reduced=b/i;
lcm = i*a_reduced*b_reduced;
Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm);
break;
}
}
}
}
else if (a==c && a!=b) {
if (a>b) {
for (int i=a; a>1; i--) {
if (a%i==0 && b%i==0) {
int a_reduced=a/i;
int b_reduced=b/i;
lcm = i*a_reduced*b_reduced;
Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm);
break;
}
}
}
else {
for (int i=b; b>1; i--) {
if (a%i==0 && b%i==0) {
int a_reduced=a/i;
int b_reduced=b/i;
lcm = i*a_reduced*b_reduced;
Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm);
break;
}
}
}
}
else {
int a_r = a;
int b_r = b;
int c_r = c;
int d = max (a_r,b_r,c_r);
while (d>1) {
if (a_r%d==0 && b_r%d==0 && c_r%d==0) {
int a_r_temp=a_r/d;
int b_r_temp=b_r/d;
int c_r_temp=c_r/d;
a_r = a_r_temp;
b_r = b_r_temp;
c_r = c_r_temp;
break;
}
else 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;
break;
}
else if (a_r%d==0 && c_r%d==0) {
int a_r_temp=a_r/d;
int c_r_temp=c_r/d;
a_r = a_r_temp;
c_r = c_r_temp;
break;
}
else if (b_r%d==0 && c_r%d==0) {
int b_r_temp=b_r/d;
int c_r_temp=c_r/d;
b_r = b_r_temp;
c_r = c_r_temp;
break;
}
else {
}
d--;
}
lcm=d*a_r*b_r*c_r;
Console.WriteLine("LCM({0},{1},{2}): {3}",a,b,c,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 int max(int a, int b, int c) {
if (a>=b && a>=c) {
return a;
}
else if (b>=a && b>=c) {
return b;
}
else {
return c;
}
}
public static void Pyth(int lowerBound, int upperBound) {
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 calcCircumCirlce(double r){
return 2*r*Math.PI;
}
public static void sAreaCone(int r, int l) {}
public static void volumeCone(int r, int h){}
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);
Console.WriteLine(l12 + " " + l23 + " " + l13);
Console.WriteLine(lhs);
Console.WriteLine(angle2*360/(2*Math.PI)+" degrees");
}
}
public static class Random2
{
private static readonly Random globalRandom = new Random();
private static readonly object globalLock = new object();
private static readonly ThreadLocal<Random> threadRandom = new ThreadLocal<Random>(NewRandom);
public static Random NewRandom()
{
lock (globalLock)
{
return new Random(globalRandom.Next());
}
}
public static Random Instance { get { return threadRandom.Value; } }
public static int Next()
{
return Instance.Next();
}
public static int Next(int maxValue)
{
return Instance.Next(maxValue);
}
public static int Next(int minValue, int maxValue)
{
return Instance.Next(minValue, maxValue);
}
public static double NextDouble()
{
return Instance.NextDouble();
}
public static void NextBytes(byte[] buffer)
{
Instance.NextBytes(buffer);
}
}
}
namespace ShuffleExtension {
public static class ShuffleExtend {
public static void Shuffle<T>(this IList<T> list) {
int n = list.Count;
while (n > 1) {
int k = (Rextester.Random2.Next(0, n) % n);
n--;
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}
}
|
run
| edit
| history
| help
|
0
|
|
|