Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. static int loopy(int[] aa)
  2. {
  3. var min = aa.Min();
  4. var max = aa.Max();
  5. var expectedReps = max - min + 1; // <--- this is how many reps will be required
  6.  
  7. int rep = 0;
  8. int i;
  9. HashSet<int> hash = new HashSet<int>();
  10.  
  11. List<int> a = aa.Distinct().ToList();
  12. while (a.Count != 0)
  13. {
  14. foreach (int x in a)
  15. {
  16. foreach (int y in a)
  17. {
  18. if (x != y) hash.Add(Math.Abs(x - y));
  19. }
  20. }
  21. a = hash.ToList();
  22. hash.Clear();
  23. Console.WriteLine("a.Count = " + a.Count);
  24. /*
  25. for (i = 0; i < a.Count; ++i)
  26. {
  27. Console.Write(" " + a[i]);
  28. }
  29. Console.WriteLine();*/
  30. ++rep;
  31. }
  32. if (rep == 0) rep = -1;
  33.  
  34. Debug.Assert(expectedReps == rep); // hasn't failed on me yet
  35.  
  36. return rep;
  37. }
  38.  
  39. static async Task Main(string[] args)
  40. {
  41. while (true)
  42. {
  43. var r = new Random();
  44. var xs = new int[242];
  45.  
  46. for (int i = 0; i < xs.Length; i++)
  47. {
  48. xs[i] = r.Next(1, 1163);
  49. }
  50.  
  51. loopy(xs);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement