Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- init();
- }
- private static void init()
- {
- int n = int.Parse(Console.ReadLine());
- // promenqsh bounda do koe chislo max da tursi
- int bound = 300;
- run(n,bound);
- }
- private static void run(int n, int bound)
- {
- int count = 0;
- List<List<int>> foundPairs = new List<List<int>>();
- while (count<n)
- {
- Random rnd = new Random();
- int a = rnd.Next(1, bound);
- int b = rnd.Next(1, bound);
- int c = rnd.Next(1, bound);
- int d = rnd.Next(1, bound);
- if (equation(a,b,c,d) && notFound(foundPairs, a, b, c, d))
- {
- List<int> pair = new List<int>();
- pair.Add(a);
- pair.Add(b);
- pair.Add(c);
- pair.Add(d);
- foundPairs.Add(pair);
- count++;
- Console.WriteLine($"{a}^2 + {b}^2 + {c}^2 = {d}^2");
- }
- }
- }
- private static Boolean equation(int a, int b, int c, int d)
- {
- return a * a + b * b + c * c == d * d;
- }
- private static Boolean notFound(List<List<int>> pairs, int a, int b, int c,int d)
- {
- List<int> currentPair = new List<int>();
- currentPair.Add(a);
- currentPair.Add(b);
- currentPair.Add(c);
- currentPair.Add(d);
- currentPair.Sort();
- foreach ( List<int> pair in pairs)
- {
- pair.Sort();
- if ((currentPair[0].Equals(pair[0])) && (currentPair[1].Equals(pair[1])) &&
- (currentPair[2].Equals(pair[2])) && (currentPair[3].Equals(pair[3])))
- {
- return false;
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement