Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int loopy(int[] aa)
- {
- var min = aa.Min();
- var max = aa.Max();
- var expectedReps = max - min + 1; // <--- this is how many reps will be required
- int rep = 0;
- int i;
- HashSet<int> hash = new HashSet<int>();
- List<int> a = aa.Distinct().ToList();
- while (a.Count != 0)
- {
- foreach (int x in a)
- {
- foreach (int y in a)
- {
- if (x != y) hash.Add(Math.Abs(x - y));
- }
- }
- a = hash.ToList();
- hash.Clear();
- Console.WriteLine("a.Count = " + a.Count);
- /*
- for (i = 0; i < a.Count; ++i)
- {
- Console.Write(" " + a[i]);
- }
- Console.WriteLine();*/
- ++rep;
- }
- if (rep == 0) rep = -1;
- Debug.Assert(expectedReps == rep); // hasn't failed on me yet
- return rep;
- }
- static async Task Main(string[] args)
- {
- while (true)
- {
- var r = new Random();
- var xs = new int[242];
- for (int i = 0; i < xs.Length; i++)
- {
- xs[i] = r.Next(1, 1163);
- }
- loopy(xs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement