Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using System;
- using System.Threading;
- namespace serialize
- {
- class Generator
- {
- public (int, int, int, int) GetMod(int diff)
- {
- int mod1 = 1;// +-
- int mod2 = 1;// +-
- int mod3 = 1;// */
- int mod4 = 1;// */
- if (diff == 0)//только сумма
- {
- mod1 = 9;
- mod2 = 9;
- }
- if (diff == 1)// сумма & разность
- {
- mod1 = 11;
- mod2 = 11;
- }
- if (diff == 2)// сумма & разность & произведение
- {
- mod1 = 10;// +-
- mod2 = 10;// +-
- mod3 = 9;// */
- mod4 = 9;// */
- }
- if (diff == 3)// сумма & разность & произведение
- {
- mod1 = 19;// +-
- mod2 = 19;// +-
- mod3 = 9;// */
- mod4 = 9;// */
- }
- if (diff > 3)
- {
- mod1 = 20 + (diff - 2) * (diff - 2);
- mod2 = 20 + (diff - 2) * (diff - 2);
- mod3 = 10 + (diff - 2) * 2;
- mod4 = 10 + (diff - 2) * 2;
- }
- return (mod1, mod2, mod3, mod4);
- }
- public static char GetSign(int diff = 0)
- {
- Random rnd = new Random();
- int l = rnd.Next();
- Thread.Sleep(5);
- int r = rnd.Next();
- int tmp = rnd.Next(Math.Min(l, r), Math.Max(l, r)) % 4;
- char result = '.';
- if (diff == 0)
- {
- tmp = 0;
- }
- if (diff == 1)
- {
- while (tmp > 1)
- { tmp = rnd.Next() % 4; }
- }
- if (diff == 2)
- {
- while (tmp > 2)
- { tmp = rnd.Next() % 4; }
- }
- switch (tmp)
- {
- case (0):
- result = '+';
- break;
- case (1):
- result = '-';
- break;
- case (2):
- result = '*';
- break;
- case (3):
- result = '/';
- break;
- default:
- break;
- }
- return result;
- }
- public (int, int) GetPair(int mod1, int mod2)
- {
- Random rnd = new Random();
- int res1, res2;
- res1 = (rnd.Next() % mod1) + 1;
- Thread.Sleep(10);
- res2 = (rnd.Next() % mod2) + 1;
- return (res1, res2);
- }
- public (string, char, string, int) Build(char Sign, int diff)
- // first sign second result
- {
- (string, char, string, int) result;
- result.Item1 = "";
- result.Item2 = '.';
- result.Item3 = "";
- result.Item4 = 0;
- var MOD = GetMod(diff);
- if (Sign == '+')
- {
- do
- {
- (int, int) Expression = GetPair(MOD.Item1, MOD.Item2);
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 + Expression.Item2;
- } while (diff > 2 && result.Item4 < (diff - 1) * 10);
- }
- else
- if (Sign == '-')
- {
- (int, int) Expression;
- do
- {
- Expression = GetPair(MOD.Item1, MOD.Item2);
- if (Expression.Item1 < Expression.Item2)
- {
- int a = Expression.Item1;
- Expression.Item1 = Expression.Item2;
- Expression.Item2 = a;
- }
- } while (diff > 1 && Expression.Item1 < 3 * (diff));
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 - Expression.Item2;
- }
- else
- if (Sign == '/')
- {
- (int, int) Expression = GetPair(MOD.Item3, MOD.Item4);
- Expression.Item1 = Expression.Item2 * Expression.Item1;
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 / Expression.Item2;
- }
- else
- {
- (int, int) Expression = GetPair(MOD.Item3, MOD.Item4);
- if (Expression.Item1 == 1)
- Expression.Item1++;
- if (Expression.Item2 == 1)
- Expression.Item2++;
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 * Expression.Item2;
- }
- return result;
- }
- static void Main(string[] args)
- {
- int diff = 8;
- Generator abs = new Generator();
- //for (diff = 0; diff < 10; ++diff)
- {
- Console.WriteLine();
- Console.WriteLine();
- for (int i = 0; i < 10; ++i)
- {
- var a = abs.Build(GetSign(diff), diff);
- Thread.Sleep(100);
- Console.WriteLine(a);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement