Guest User

Untitled

a guest
Jan 13th, 2019
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Cubes
  6. {
  7. public class Program
  8. {
  9. private static int totalCubes = 1;
  10. private static string[] cubes;
  11. private static readonly HashSet<string> rotations = new HashSet<string>();
  12.  
  13. public static void Main()
  14. {
  15. cubes = Console.ReadLine().Split().OrderBy(x => x).ToArray();
  16.  
  17. Rotate();
  18. Permutate(0, cubes.Length - 1);
  19.  
  20. Console.WriteLine(totalCubes);
  21. }
  22.  
  23. private static void Rotate()
  24. {
  25. for (int z = 0; z < 4; z++)
  26. {
  27. for (int y = 0; y < 4; y++)
  28. {
  29. for (int x = 0; x < 4; x++)
  30. {
  31. var cube = string.Join("", cubes);
  32. rotations.Add(cube);
  33.  
  34. RotateX();
  35. }
  36.  
  37. RotateY();
  38. }
  39.  
  40. RotateZ();
  41. }
  42. }
  43.  
  44. private static void RotateX()
  45. {
  46. Swap(10, 0);
  47. Swap(11, 10);
  48. Swap(3, 11);
  49.  
  50. Swap(9, 4);
  51. Swap(7, 9);
  52. Swap(1, 7);
  53.  
  54. Swap(5, 2);
  55. Swap(6, 5);
  56. Swap(8, 6);
  57. }
  58.  
  59. private static void RotateY()
  60. {
  61. Swap(3, 1);
  62. Swap(7, 3);
  63. Swap(8, 7);
  64.  
  65. Swap(11, 0);
  66. Swap(6, 11);
  67. Swap(2, 6);
  68.  
  69. Swap(10, 4);
  70. Swap(9, 10);
  71. Swap(5, 9);
  72. }
  73.  
  74. private static void RotateZ()
  75. {
  76. Swap(6, 9);
  77. Swap(7, 6);
  78. Swap(11, 7);
  79.  
  80. Swap(5, 10);
  81. Swap(8, 5);
  82. Swap(3, 8);
  83.  
  84. Swap(2, 4);
  85. Swap(1, 2);
  86. Swap(0, 1);
  87. }
  88.  
  89. public static void Permutate(int start, int end)
  90. {
  91. if (!rotations.Contains(string.Join("", cubes)))
  92. {
  93. totalCubes++;
  94. Rotate();
  95. }
  96.  
  97. for (int left = end - 1; left >= start; left--)
  98. {
  99. for (int right = left + 1; right <= end; right++)
  100. {
  101. if (cubes[left] != cubes[right])
  102. {
  103. Swap(left, right);
  104. Permutate(left + 1, end);
  105. }
  106. }
  107.  
  108. var firstElement = cubes[left];
  109. for (int i = left; i <= end - 1; i++)
  110. {
  111. cubes[i] = cubes[i + 1];
  112. }
  113.  
  114. cubes[end] = firstElement;
  115. }
  116. }
  117.  
  118. private static void Swap(int first, int second)
  119. {
  120. var temp = cubes[first];
  121. cubes[first] = cubes[second];
  122. cubes[second] = temp;
  123. }
  124. }
  125. }
RAW Paste Data