Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class FiveDigits
  6. {
  7. HashSet<int> hash = new HashSet<int>();
  8. Random rng = new Random();
  9.  
  10. public void play(){
  11. int magicNumber = 12345;
  12. int counter = 0;
  13.  
  14. while (!hash.Contains( magicNumber))
  15. {
  16. getNewNumber();
  17. Console.WriteLine("Iteration #{0,4} with combination = {1}", counter+1, hash.ElementAt(counter).ToString("D5"));
  18. counter++;
  19. if (counter % 10 == 0) pause();
  20. }
  21. Console.ReadKey();
  22. }
  23. public void pause()
  24. {
  25. Console.WriteLine("Press any key to continue . . .");
  26. Console.ReadKey(true);
  27. }
  28. public void getNewNumber()
  29. {
  30. while ( !hash.Add(rng.Next(0, 99999))) ;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement