Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
simultQ
//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 int[] a = simult(new int[] {4,2,20}, new int[] {7,-3,9}); //Console.WriteLine(simult(new int[] {4,2,20}, new int[] {7,-3,9})); //Console.WriteLine(a[0]); //Console.WriteLine(a[1]); simultQ(); //Console.WriteLine(simult(new int[] {1,2,3}, new int[] {2,5,5})[1]); } public static int[] simult(int[] c, int[] d) { int 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 = (c[0]*d[2]-d[0]*c[2] ) / (c[0]*d[1]-d[0]*c[1]); x = (c[2]-c[1]*y)/c[0]; int[] z = new int[] {x,y}; //Console.WriteLine("x = {0}, y = {1}",x,y); return z; } public static void simultQ() { int[] c = new int[6]; int count = 0; while (count <100 ) { for (int i = 0; i<c.Length; i++) { c[i] = Rand.Next(1,10); } if (c[0]*c[4]!=c[3]*c[1]) { int[] result = simult(new int[] {c[0], c[1], c[2]}, new int[] {c[3], c[4], c[5]}); if (Math.Abs(result[0]*result[1])<400 && result[0]%1==0 && result[1]%1==0 && result[0]+result[1]!=0 && result[0]*result[1]!=0) { count++; Console.WriteLine("{0}x + {1}y = {2}", c[0], c[1], c[2]); Console.WriteLine("{0}x + {1}y = {2}", c[3], c[4], c[5]); Console.WriteLine("x = {0}, y = {1}", result[0], result[1]); Console.WriteLine(); } } } Console.WriteLine(count); } } 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
Func
Fechas
Encryption & Decryption AES C#
MC
HawkSearch field naming convention
code for part 4 gogoaim
Listas JL
1
Codenew
prime