Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. void Main()
  2. {
  3. string conjunto = "123";
  4.  
  5. HashSet<string> conjuntoPotencia = GenerarPermutacionParcial(conjunto);
  6.  
  7. // Por cada permutación generar los subconjuntos posibles:
  8. Enumerable.Range(0, conjunto.Length)
  9. .ToList()
  10. .ForEach(x =>
  11. {
  12. Enumerable.Range(0, conjunto.Length)
  13. .ToList()
  14. .ForEach(y =>
  15. {
  16. // Genera subconjuntos por medio de la partición de la permutación:
  17. conjuntoPotencia.Add(conjuntoPotencia.ElementAt(x).Substring(0, y));
  18. conjuntoPotencia.Add(conjuntoPotencia.ElementAt(x).Substring(y + 1));
  19. }
  20. );
  21. });
  22.  
  23. conjuntoPotencia.Select(sub => new String(sub.ToCharArray()
  24. .OrderBy(elemento => elemento)
  25. .ToArray()))
  26. .Distinct()
  27. .OrderBy(sub => sub.Length)
  28. .Dump("Conjunto Potencia de {1, 2, 3}");
  29. }
  30.  
  31. private HashSet<string> GenerarPermutacionParcial(string word)
  32. {
  33. return new HashSet<string>(
  34. Enumerable.Range(0, word.Length)
  35. .Select(i => word.Remove(i, 1).Insert(0, word[i].ToString())));
  36. } // 123, 213, 312
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement