Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BreakNum2
//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 System.Threading; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here //BreakNumSub(); for (int i=0; i<100;i++) { int a = Rand.Next(111,10000); int b = Rand.Next(111,1000); int c = Rand.Next(111,1000); double a1 = (double) a/100; double b1 = (double) b/100; double c1 = (double) c/100; Console.WriteLine (a1+" "+b1+" "+c1); } } public static void BreakNum() { string title = "Adding by Breaking Numbers (2)"; List<string> question = new List<string>(); string op ="+"; for (int i = 0; i < 200; i++) { int left = Rand.Next(11,100); int right = Rand.Next(11,100); //if (left + right <100 && left%10!=0 && right%10!=0) { if (left + right <100 && left%10!=0 && right%10!=0) { if (left>=right) { question.AddRange(BreakLeft(left,right,op)); } else question.AddRange(BreakRight(left,right,op)); } } //Console.WriteLine(question.Count()); PrintBreakNum(question,title); } public static void BreakNumSub() { string title = "Subtracting by Breaking Numbers (4)"; List<string> question = new List<string>(); string op = "-"; for (int i = 0; i < 200; i++) { int left = Rand.Next(1,10); int right = Rand.Next(11,100); left = left*10; //if (left%10<right) { if (left>right) { question.AddRange(BreakRight(left,right,op)); } } //Console.WriteLine(question.Count()); PrintBreakNum(question,title); } public static void PrintBreakNum<T>(List<T> list, string title) { 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*{-33mm}\\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("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%182==0){ //13 lines per question, 14 questions => 182 lines 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*{-33mm}\\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("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } } } public static List<string> BreakRight(int left, int right, string op){ List<string> args = new List<string>(); args.Add("\\item \\leavevmode\\vadjust{\\vspace{-\\baselineskip}}\\newline"); args.Add(" \\begin{tikzpicture}[remember picture]"); args.Add(" \\node{$\\tikznode{n9}{"+left+"}"+op+"\\tikznode{n7}{"+right+"}=\\tikznode[boxed]{n16}{\\phantom{\\frac{10}{20}}}$};"); args.Add(" \\node[boxed,above left=2mm and 2mm of n7] (n1) {\\phantom{10}};"); args.Add(" \\node[boxed,above right=2mm and 2mm of n7] (n6) {\\phantom{10}};"); args.Add(" \\node[boxed,above=13mm of n7] (n10) {\\phantom{10}};"); args.Add(" \\draw[shrt] (n1) -- (n7);"); args.Add(" \\draw[shrt] (n6) -- (n7);"); args.Add(" \\draw[shrt] (n10.south east) -- (n6);"); args.Add(" \\node[ellipse,draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};"); args.Add(" \\draw[shrt] ([x-]n10.south west) -- ([x-]n1n9.north);"); args.Add(" \\draw[shrt] ([x+]n10.south west) -- ([x+]n1n9.north);"); args.Add(" \\end{tikzpicture}"); return args; } public static List<string> BreakLeft(int left, int right, string op){ List<string> args = new List<string>(); args.Add("\\item \\leavevmode\\vadjust{\\vspace{-\\baselineskip}}\\newline"); args.Add(" \\begin{tikzpicture}[remember picture]"); args.Add(" \\node{$\\tikznode{n9}{"+left+"}"+op+"\\tikznode{n7}{"+right+"}=\\tikznode[boxed]{n16}{\\phantom{\\frac{10}{20}}}$};"); args.Add(" \\node[boxed,above left=2mm and 2mm of n9] (n1) {\\phantom{10}};"); args.Add(" \\node[boxed,above right=2mm and 2mm of n9] (n6) {\\phantom{10}};"); args.Add(" \\node[boxed,above=13mm of n9] (n10) {\\phantom{10}};"); args.Add(" \\draw[shrt] (n1) -- (n9);"); args.Add(" \\draw[shrt] (n6) -- (n9);"); args.Add(" \\draw[shrt] (n10.south west) -- (n1);"); args.Add(" \\node[ellipse,draw,fit=(n6) (n7),inner sep=1pt] (n6n7) {};"); args.Add(" \\draw[shrt] ([x-]n10.south east) -- ([x-]n6n7.north);"); args.Add(" \\draw[shrt] ([x+]n10.south east) -- ([x+]n6n7.north);"); args.Add(" \\end{tikzpicture}"); return args; } 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); } /// <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; } } } }
run
|
edit
|
history
|
help
0
Xml in C#
Task List
Shalini_CSG_CodeTest
With Arguments
tablecsv
reverse a stack
comb sort
asxsd
Uri builder
123