StringPerm.cs 780 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. namespace ShaderControl {
  4. public class StringPerm {
  5. public static List<List<string>> GetCombinations(List<string> items) {
  6. List<List<string>> variants = new List<List<string>>();
  7. int bitCount = items.Count;
  8. int mask = (int)Mathf.Pow(2, bitCount);
  9. for (int k = 1; k < mask; k++) {
  10. List<string> variant = new List<string>();
  11. int bit = 1;
  12. for (int j = 0; j < bitCount; j++, bit <<= 1) {
  13. if ((k & bit) != 0) {
  14. variant.Add(items[j]);
  15. }
  16. }
  17. variants.Add(variant);
  18. }
  19. return variants;
  20. }
  21. }
  22. }