Advertisement
Guest User

Untitled

a guest
Jun 12th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program
  6. {
  7. public static void Main(string[] args)
  8. {
  9. string shortestString = FindShortestString();
  10. Console.WriteLine(shortestString.Length);
  11. }
  12.  
  13. public static string FindShortestString()
  14. {
  15. HashSet<string> combinationsSet = GenerateCombinationsSet();
  16. string shortestString = string.Empty;
  17.  
  18. foreach (string combination in combinationsSet)
  19. {
  20. if (!shortestString.Contains(combination))
  21. {
  22. shortestString += combination;
  23. }
  24. }
  25.  
  26. return shortestString;
  27. }
  28.  
  29. public static HashSet<string> GenerateCombinationsSet()
  30. {
  31. HashSet<string> combinationsSet = new HashSet<string>();
  32.  
  33. for (int i = 0; i <= 9999; i++)
  34. {
  35. string combination = i.ToString("D4");
  36. combinationsSet.Add(combination);
  37. }
  38.  
  39. return combinationsSet;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement