Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2022
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 55.77 KB | None | 0 0
  1. /**
  2.  * Author: Kacper Blachut
  3.  * Purpose: Counts the number of unique states of nodes in a D-dimensional cube with side length N and C colors using bruteforce.
  4.  *
  5.  * Program used in "O pewnym problemie przeliczania unikalnych przeksztalcen na zbiorach skonczonych" for Malopolski Konkurs Prac Matematycznych 2022.
  6.  * Doesn't have a UI
  7.  */
  8.  
  9. using System;
  10. using System.Diagnostics;
  11.  
  12. namespace RotatingHypercubes
  13. {
  14.     class BruteforceApproach
  15.     {
  16.         class Cube
  17.         {
  18.             public readonly int Dimension;
  19.             public int Size;
  20.  
  21.             public readonly int[] Axes;
  22.             public readonly bool[] StartingPoint;
  23.  
  24.             public readonly int TotalPoints;
  25.             public int[] Values;
  26.  
  27.             public Cube(int Dimension, int Size, bool ClearValues = true)
  28.             {
  29.                 this.Dimension = Dimension;
  30.                 this.Size = Size;
  31.                 this.Axes = new int[this.Dimension];
  32.                 this.StartingPoint = new bool[this.Dimension];
  33.                 this.TotalPoints = (int) MathF.Pow(Size, Dimension);
  34.  
  35.                 for(int i = 0; i < this.Dimension; i++)
  36.                 {
  37.                     Axes[i] = i + 1;
  38.                     StartingPoint[i] = false;
  39.                 }
  40.  
  41.                 this.Values = new int[TotalPoints];
  42.  
  43.                 if(ClearValues)
  44.                 {
  45.                     for (int i = 0; i < this.TotalPoints; i++)
  46.                     {
  47.                         Values[i] = 0;
  48.                     }
  49.                 }
  50.             }
  51.  
  52.             public int[] Rotate(int[] NewAxes, bool[] NewStartingPoint)
  53.             {
  54.                 if(NewAxes.Length == Dimension && NewStartingPoint.Length == Dimension)
  55.                 {
  56.                     if(AreAxesValid(NewAxes))
  57.                     {
  58.                         int[] StepSize = new int[Dimension];
  59.                        
  60.                         for(int i = 0; i < Dimension; i++)
  61.                         {
  62.                             StepSize[i] = (int) MathF.Pow(Size, NewAxes[i] - 1);
  63.                         }
  64.  
  65.  
  66.                         int StartingPointIndex = 0;
  67.  
  68.                         for(int i = 0; i < Dimension; i++)
  69.                         {
  70.                             if(NewStartingPoint[i])
  71.                             {
  72.                                 StartingPointIndex += (Size - 1) * (int) MathF.Pow(Size, NewAxes[i] - 1);
  73.                             }
  74.                         }
  75.  
  76.  
  77.                         int[] NewValues = new int[TotalPoints];
  78.  
  79.                         for(int i = 0; i < TotalPoints; i++)
  80.                         {
  81.                             int TotalStep = 0;
  82.                             int[] StepValues = new int[Dimension];
  83.                             int PointsRemaining = i;
  84.  
  85.                             for (int j = 0; j < Dimension; j++)
  86.                             {
  87.                                 StepValues[j] = PointsRemaining % Size;
  88.                                 PointsRemaining -= StepValues[j];
  89.                                 PointsRemaining /= Size;
  90.  
  91.                                 if (NewStartingPoint[j])
  92.                                 {
  93.                                     TotalStep -= StepValues[j] * StepSize[j];
  94.                                 }
  95.                                 else
  96.                                 {
  97.                                     TotalStep += StepValues[j] * StepSize[j];
  98.                                 }
  99.                             }
  100.                            
  101.                             NewValues[i] = Values[StartingPointIndex + TotalStep];
  102.                         }
  103.  
  104.  
  105.                         return NewValues;
  106.                     }
  107.                     else
  108.                     {
  109.                         Console.Error.Write("\n/!\\ Rotating Hypercubes Error: \nRotate() - axes specified in the input are not valid.\n");
  110.                     }
  111.                 }
  112.                 else
  113.                 {
  114.                     Console.Error.Write("\n/!\\ Rotating Hypercubes Error: \nRotate() - number of dimensions in the specified input (" + NewAxes.Length + " and " + NewStartingPoint.Length + ") does not match that of the cube object (" + this.Dimension + ").\n");
  115.                 }
  116.  
  117.                 return new int[] {};
  118.             }
  119.             public bool AreAxesValid(int[] NewAxes)
  120.             {
  121.                 bool[] Validation = new bool[NewAxes.Length];
  122.                
  123.                 for(int i = 0; i < NewAxes.Length; i++)
  124.                 {
  125.                     Validation[i] = false;
  126.                 }
  127.  
  128.                 for(int i = 0; i < NewAxes.Length; i++)
  129.                 {
  130.                     if(NewAxes[i] - 1 < 0 || NewAxes[i] - 1 > NewAxes.Length - 1)
  131.                     {
  132.                         return false;
  133.                     }
  134.                     else
  135.                     {
  136.                         if(Validation[NewAxes[i] - 1])
  137.                         {
  138.                             return false;
  139.                         }
  140.                         else
  141.                         {
  142.                             Validation[NewAxes[i] - 1] = true;
  143.                         }
  144.                     }
  145.                 }
  146.                 return true;
  147.             }
  148.             public void SetValues(int[] NewValues)
  149.             {
  150.                 if(NewValues.Length == TotalPoints)
  151.                 {
  152.                     Values = NewValues;
  153.                 }
  154.                 else
  155.                 {
  156.                     Console.Error.Write("\n/!\\ Rotating Hypercubes Error: \nSetValues() - values specified in the input are not valid.\n");
  157.                 }
  158.             }
  159.             public void PrintValues(int[] Values)
  160.             {
  161.                 Console.Write(Values[0]);
  162.                 for(int i = 1; i < Values.Length; i++)
  163.                 {
  164.                     Console.Write(", " + Values[i]);
  165.                 }
  166.             }
  167.         }
  168.         class RawCube
  169.         {
  170.             public readonly int Dimension;
  171.             public int Size;
  172.  
  173.             public readonly int[] Axes;
  174.             public readonly bool[] StartingPoint;
  175.  
  176.             public readonly int TotalPoints;
  177.             public int[] Values;
  178.  
  179.             public RawCube(int Dimension, int Size, bool ClearValues = true)
  180.             {
  181.                 this.Dimension = Dimension;
  182.                 this.Size = Size;
  183.                 this.Axes = new int[this.Dimension];
  184.                 this.StartingPoint = new bool[this.Dimension];
  185.                 this.TotalPoints = (int)MathF.Pow(Size, Dimension);
  186.  
  187.                 for (int i = 0; i < this.Dimension; i++)
  188.                 {
  189.                     Axes[i] = i + 1;
  190.                     StartingPoint[i] = false;
  191.                 }
  192.  
  193.                 this.Values = new int[TotalPoints];
  194.  
  195.                 if (ClearValues)
  196.                 {
  197.                     for (int i = 0; i < this.TotalPoints; i++)
  198.                     {
  199.                         Values[i] = 0;
  200.                     }
  201.                 }
  202.             }
  203.  
  204.             public int[] Rotate(int[] NewAxes, bool[] NewStartingPoint)
  205.             {
  206.                 int[] StepSize = new int[Dimension];
  207.  
  208.                 for (int i = 0; i < Dimension; i++)
  209.                 {
  210.                     StepSize[i] = (int)MathF.Pow(Size, NewAxes[i] - 1);
  211.                 }
  212.  
  213.  
  214.                 int StartingPointIndex = 0;
  215.  
  216.                 for (int i = 0; i < Dimension; i++)
  217.                 {
  218.                     if (NewStartingPoint[i])
  219.                     {
  220.                         StartingPointIndex += (Size - 1) * (int)MathF.Pow(Size, NewAxes[i] - 1);
  221.                     }
  222.                 }
  223.  
  224.  
  225.                 int[] NewValues = new int[TotalPoints];
  226.  
  227.                 for (int i = 0; i < TotalPoints; i++)
  228.                 {
  229.                     int TotalStep = 0;
  230.                     int[] StepValues = new int[Dimension];
  231.                     int PointsRemaining = i;
  232.  
  233.                     for (int j = 0; j < Dimension; j++)
  234.                     {
  235.                         StepValues[j] = PointsRemaining % Size;
  236.                         PointsRemaining -= StepValues[j];
  237.                         PointsRemaining /= Size;
  238.  
  239.                         if (NewStartingPoint[j])
  240.                         {
  241.                             TotalStep -= StepValues[j] * StepSize[j];
  242.                         }
  243.                         else
  244.                         {
  245.                             TotalStep += StepValues[j] * StepSize[j];
  246.                         }
  247.                     }
  248.  
  249.                     NewValues[i] = Values[StartingPointIndex + TotalStep];
  250.                 }
  251.  
  252.  
  253.                 return NewValues;
  254.             }
  255.             public void PrintValues(int[] Values)
  256.             {
  257.                 Console.Write(Values[0]);
  258.                 for (int i = 1; i < Values.Length; i++)
  259.                 {
  260.                     Console.Write(", " + Values[i]);
  261.                 }
  262.                 Console.WriteLine();
  263.             }
  264.             public void PrintValuesRaw(int[] Values)
  265.             {
  266.                 for (int i = 0; i < Values.Length; i++)
  267.                 {
  268.                     Console.Write(Values[i]);
  269.                 }
  270.             }
  271.             public void PrintValuesRaw(bool[] Values)
  272.             {
  273.                 for (int i = 0; i < Values.Length; i++)
  274.                 {
  275.                     if(Values[i])
  276.                     {
  277.                         Console.Write("1");
  278.                     }
  279.                     else
  280.                     {
  281.                         Console.Write("0");
  282.                     }
  283.                 }
  284.             }
  285.         }
  286.         class CountStates
  287.         {
  288.             public readonly int Dimension;
  289.             public readonly int Size;
  290.             public readonly int Colors;
  291.  
  292.             public CountStates(int Dimension, int Size, int Colors)
  293.             {
  294.                 this.Dimension = Dimension;
  295.                 this.Size = Size;
  296.                 this.Colors = Colors;
  297.             }
  298.  
  299.             public void Count()
  300.             {
  301.                 int[] UnitValues = new int[(int) MathF.Pow(Size, Dimension)];
  302.                 int[] CurrentColors = new int[UnitValues.Length];
  303.                 for (int i = 0; i < UnitValues.Length; i++)
  304.                 {
  305.                     UnitValues[i] = i;
  306.                 }
  307.  
  308.  
  309.                 int StartPointSymmetryNum = (int) MathF.Pow(2, Dimension);
  310.                 int AxesSymmetryNum = 1;
  311.                 for (int i = 2; i <= Dimension; i++)
  312.                 {
  313.                     AxesSymmetryNum *= i;
  314.                 }
  315.  
  316.  
  317.                 int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
  318.                 RawCube Cube = new RawCube(Dimension, Size);
  319.                 Cube.Values = UnitValues;
  320.                 int[] CurrentAxes = Cube.Axes;
  321.                 bool[] CurrentStartingPoint = Cube.StartingPoint;
  322.                 for(int i = 0; i < StartPointSymmetryNum; i++)
  323.                 {
  324.                     for(int j = 0; j < AxesSymmetryNum; j++)
  325.                     {
  326.                         int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
  327.  
  328.                         for(int k = 0; k < UnitValues.Length; k++)
  329.                         {
  330.                             AllSymmetriesUnitValues[i, j, k] = Temp[k];
  331.                         }
  332.  
  333.                         CurrentAxes = IncrementAxes(CurrentAxes);
  334.                     }
  335.  
  336.                     CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
  337.                 }
  338.  
  339.  
  340.  
  341.                 int MaxStates = (int) MathF.Pow(Colors, MathF.Pow(Size, Dimension));
  342.                 int[] TypesOfAllStates = new int[MaxStates];
  343.                 int CurrentType = 1;
  344.                 int[] VariatedColors = new int[UnitValues.Length];
  345.                 int[] TempColors;
  346.  
  347.                 for(int i = 0; i < MaxStates; i++)
  348.                 {
  349.                     if(TypesOfAllStates[i] == 0)
  350.                     {
  351.                         for (int j = 0; j < StartPointSymmetryNum; j++)
  352.                         {
  353.                             for (int k = 0; k < AxesSymmetryNum; k++)
  354.                             {
  355.                                 for (int l = 0; l < UnitValues.Length; l++)
  356.                                 {
  357.                                     TempColors = CurrentColors;
  358.                                     VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
  359.                                 }
  360.  
  361.                                 TypesOfAllStates[ColorsToIndex(VariatedColors)] = CurrentType;
  362.                             }
  363.                         }
  364.                         Console.Write(i + ", " + CurrentType + ": ");
  365.                         Cube.PrintValues(CurrentColors);
  366.                         CurrentType++;
  367.                     }
  368.  
  369.                     CurrentColors = IncrementColors(CurrentColors);
  370.                 }
  371.  
  372.                 Console.WriteLine("\nTotal Types: " + (CurrentType - 1));
  373.             }
  374.             public bool[] IncrementStartingPoint(bool[] StartingPoint)
  375.             {
  376.                 for(int i = 0; i < StartingPoint.Length; i++)
  377.                 {
  378.                     if(!StartingPoint[i])
  379.                     {
  380.                         StartingPoint[i] = true;
  381.  
  382.                         return StartingPoint;
  383.                     }
  384.                     else
  385.                     {
  386.                         StartingPoint[i] = false;
  387.                     }
  388.                 }
  389.  
  390.                 return StartingPoint;
  391.             }
  392.             public int[] IncrementAxes(int[] Axes)
  393.             {
  394.                 int A = Axes[Axes.Length - 1];
  395.                 int IndexA;
  396.                 int IndexB;
  397.                 int Temp;
  398.  
  399.                 for(int i = Axes.Length - 2; i >= 0; i--)
  400.                 {
  401.                     if(Axes[i] < A)
  402.                     {
  403.                         A = Axes[i];
  404.                         IndexA = i;
  405.  
  406.                         for(int j = Axes.Length - 1; j >= 0; j--)
  407.                         {
  408.                             if(Axes[j] > A)
  409.                             {
  410.                                 IndexB = j;
  411.                                 Temp = Axes[IndexA];
  412.                                 Axes[IndexA] = Axes[IndexB];
  413.                                 Axes[IndexB] = Temp;
  414.  
  415.                                 int l = Axes.Length - 1;
  416.  
  417.                                 for (int k = IndexA + 1; k < l; k++, l--)
  418.                                 {
  419.                                     Temp = Axes[k];
  420.                                     Axes[k] = Axes[l];
  421.                                     Axes[l] = Temp;
  422.                                 }
  423.                                 return Axes;
  424.                             }
  425.                         }
  426.                     }
  427.                     else
  428.                     {
  429.                         A = Axes[i];
  430.                     }
  431.                 }
  432.  
  433.                 Cube Identity = new Cube(Dimension, Size);
  434.                 return Identity.Axes;
  435.             }
  436.             public int[] IncrementColors(int[] Values)
  437.             {
  438.                 for (int i = 0; i < Values.Length; i++)
  439.                 {
  440.                     if (Values[i] != Colors - 1)
  441.                     {
  442.                         Values[i]++;
  443.                        
  444.                         return Values;
  445.                     }
  446.                     else
  447.                     {
  448.                         Values[i] = 0;
  449.                     }
  450.                 }
  451.  
  452.                 return Values;
  453.             }
  454.             public int ColorsToIndex(int[] Values)
  455.             {
  456.                 int Total = 0;
  457.                 for(int i = 0; i < Values.Length; i++)
  458.                 {
  459.                     Total += Values[i] * (int) MathF.Pow(Colors, i);
  460.                 }
  461.  
  462.                 return Total;
  463.             }
  464.         }
  465.         class OptCountStates
  466.         {
  467.             public int Dimension;
  468.             public int Size;
  469.             public int Colors;
  470.  
  471.             public OptCountStates(int Dimension, int Size, int Colors)
  472.             {
  473.                 this.Dimension = Dimension;
  474.                 this.Size = Size;
  475.                 this.Colors = Colors;
  476.             }
  477.  
  478.             public void Count()
  479.             {
  480.                 int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
  481.                 int[] CurrentColors = new int[UnitValues.Length];
  482.                 for (int i = 0; i < UnitValues.Length; i++)
  483.                 {
  484.                     UnitValues[i] = i;
  485.                 }
  486.  
  487.  
  488.                 int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
  489.                 int AxesSymmetryNum = 1;
  490.                 for (int i = 2; i <= Dimension; i++)
  491.                 {
  492.                     AxesSymmetryNum *= i;
  493.                 }
  494.  
  495.  
  496.                 int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
  497.                 RawCube Cube = new RawCube(Dimension, Size);
  498.                 Cube.Values = UnitValues;
  499.                 int[] CurrentAxes = Cube.Axes;
  500.                 bool[] CurrentStartingPoint = Cube.StartingPoint;
  501.                 for (int i = 0; i < StartPointSymmetryNum; i++)
  502.                 {
  503.                     for (int j = 0; j < AxesSymmetryNum; j++)
  504.                     {
  505.                         int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
  506.  
  507.                         for (int k = 0; k < UnitValues.Length; k++)
  508.                         {
  509.                             AllSymmetriesUnitValues[i, j, k] = Temp[k];
  510.                         }
  511.  
  512.                         CurrentAxes = IncrementAxes(CurrentAxes);
  513.                     }
  514.  
  515.                     CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
  516.                 }
  517.  
  518.  
  519.  
  520.                 int MaxStates = (int)MathF.Pow(Colors, MathF.Pow(Size, Dimension));
  521.                 bool[] TypesOfAllStates = new bool[MaxStates];
  522.                 int CurrentType = 1;
  523.                 int[] VariatedColors = new int[UnitValues.Length];
  524.                 int[] TempColors;
  525.  
  526.                 for (int i = 0; i < MaxStates; i++)
  527.                 {
  528.                     if (TypesOfAllStates[i] == false)
  529.                     {
  530.                         for (int j = 0; j < StartPointSymmetryNum; j++)
  531.                         {
  532.                             for (int k = 0; k < AxesSymmetryNum; k++)
  533.                             {
  534.                                 for (int l = 0; l < UnitValues.Length; l++)
  535.                                 {
  536.                                     TempColors = CurrentColors;
  537.                                     VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
  538.                                 }
  539.  
  540.                                 TypesOfAllStates[ColorsToIndex(VariatedColors)] = true;
  541.                             }
  542.                         }
  543.                         CurrentType++;
  544.                     }
  545.  
  546.                     CurrentColors = IncrementColors(CurrentColors);
  547.                 }
  548.  
  549.                 Console.WriteLine(CurrentType - 1);
  550.             }
  551.             public bool[] IncrementStartingPoint(bool[] StartingPoint)
  552.             {
  553.                 for (int i = 0; i < StartingPoint.Length; i++)
  554.                 {
  555.                     if (!StartingPoint[i])
  556.                     {
  557.                         StartingPoint[i] = true;
  558.  
  559.                         return StartingPoint;
  560.                     }
  561.                     else
  562.                     {
  563.                         StartingPoint[i] = false;
  564.                     }
  565.                 }
  566.  
  567.                 return StartingPoint;
  568.             }
  569.             public int[] IncrementAxes(int[] Axes)
  570.             {
  571.                 int A = Axes[Axes.Length - 1];
  572.                 int IndexA;
  573.                 int IndexB;
  574.                 int Temp;
  575.  
  576.                 for (int i = Axes.Length - 2; i >= 0; i--)
  577.                 {
  578.                     if (Axes[i] < A)
  579.                     {
  580.                         A = Axes[i];
  581.                         IndexA = i;
  582.  
  583.                         for (int j = Axes.Length - 1; j >= 0; j--)
  584.                         {
  585.                             if (Axes[j] > A)
  586.                             {
  587.                                 IndexB = j;
  588.                                 Temp = Axes[IndexA];
  589.                                 Axes[IndexA] = Axes[IndexB];
  590.                                 Axes[IndexB] = Temp;
  591.  
  592.                                 int l = Axes.Length - 1;
  593.  
  594.                                 for (int k = IndexA + 1; k < l; k++, l--)
  595.                                 {
  596.                                     Temp = Axes[k];
  597.                                     Axes[k] = Axes[l];
  598.                                     Axes[l] = Temp;
  599.                                 }
  600.                                 return Axes;
  601.                             }
  602.                         }
  603.                     }
  604.                     else
  605.                     {
  606.                         A = Axes[i];
  607.                     }
  608.                 }
  609.  
  610.                 Cube Identity = new Cube(Dimension, Size);
  611.                 return Identity.Axes;
  612.             }
  613.             public int[] IncrementColors(int[] Values)
  614.             {
  615.                 for (int i = 0; i < Values.Length; i++)
  616.                 {
  617.                     if (Values[i] != Colors - 1)
  618.                     {
  619.                         Values[i]++;
  620.  
  621.                         return Values;
  622.                     }
  623.                     else
  624.                     {
  625.                         Values[i] = 0;
  626.                     }
  627.                 }
  628.  
  629.                 return Values;
  630.             }
  631.             public int ColorsToIndex(int[] Values)
  632.             {
  633.                 int Total = 0;
  634.                 for (int i = 0; i < Values.Length; i++)
  635.                 {
  636.                     Total += Values[i] * (int)MathF.Pow(Colors, i);
  637.                 }
  638.  
  639.                 return Total;
  640.             }
  641.         }
  642.         class CountColoredStates
  643.         {
  644.             public readonly int Dimension;
  645.             public readonly int Size;
  646.             public readonly int Colors;
  647.  
  648.             public CountColoredStates(int Dimension, int Size, int Colors)
  649.             {
  650.                 this.Dimension = Dimension;
  651.                 this.Size = Size;
  652.                 this.Colors = Colors;
  653.             }
  654.  
  655.             public void Count()
  656.             {
  657.                 int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
  658.                 int[] CurrentColors = new int[UnitValues.Length];
  659.                 for (int i = 0; i < UnitValues.Length; i++)
  660.                 {
  661.                     UnitValues[i] = i;
  662.                 }
  663.  
  664.  
  665.                 int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
  666.                 int AxesSymmetryNum = 1;
  667.                 int ColorAxesSymmetryNum = 1;
  668.                 for (int i = 2; i <= Dimension; i++)
  669.                 {
  670.                     AxesSymmetryNum *= i;
  671.                 }
  672.                 for (int i = 2; i <= Colors; i++)
  673.                 {
  674.                     ColorAxesSymmetryNum *= i;
  675.                 }
  676.  
  677.                 int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
  678.                 RawCube Cube = new RawCube(Dimension, Size);
  679.                 Cube.Values = UnitValues;
  680.                 int[] CurrentAxes = Cube.Axes;
  681.                 bool[] CurrentStartingPoint = Cube.StartingPoint;
  682.                 for (int i = 0; i < StartPointSymmetryNum; i++)
  683.                 {
  684.                     for (int j = 0; j < AxesSymmetryNum; j++)
  685.                     {
  686.                         int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
  687.  
  688.                         for (int k = 0; k < UnitValues.Length; k++)
  689.                         {
  690.                             AllSymmetriesUnitValues[i, j, k] = Temp[k];
  691.                         }
  692.  
  693.                         CurrentAxes = IncrementAxes(CurrentAxes);
  694.                     }
  695.  
  696.                     CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
  697.                 }
  698.  
  699.  
  700.                 int[] CurrentColorAxes = new int[Colors];
  701.                 for(int i = 0; i < Colors; i++)
  702.                 {
  703.                     CurrentColorAxes[i] = i;
  704.                 }
  705.  
  706.  
  707.                 int MaxStates = (int)MathF.Pow(Colors, MathF.Pow(Size, Dimension));
  708.                 int[] TypesOfAllStates = new int[MaxStates];
  709.                 int CurrentType = 1;
  710.                 int[] VariatedColors = new int[UnitValues.Length];
  711.                 int[] TempColors;
  712.                 int[] TempColors2;
  713.                 int[] ColoredTempColors = new int[UnitValues.Length];
  714.  
  715.                 for (int i = 0; i < MaxStates; i++)
  716.                 {
  717.                     if (TypesOfAllStates[i] == 0)
  718.                     {
  719.                         for (int j = 0; j < StartPointSymmetryNum; j++)
  720.                         {
  721.                             for (int k = 0; k < AxesSymmetryNum; k++)
  722.                             {
  723.                                 TempColors = CurrentColors;
  724.                                 for (int l = 0; l < UnitValues.Length; l++)
  725.                                 {
  726.                                     VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
  727.                                 }
  728.  
  729.                                 TempColors2 = VariatedColors;
  730.                                 for (int l = 0; l < ColorAxesSymmetryNum; l++)
  731.                                 {
  732.                                     for(int m = 0; m < UnitValues.Length; m++)
  733.                                     {
  734.                                         ColoredTempColors[m] = CurrentColorAxes[TempColors2[m]];
  735.                                     }
  736.                                     TypesOfAllStates[ColorsToIndex(ColoredTempColors)] = CurrentType;
  737.                                     CurrentColorAxes = IncrementColorAxes(CurrentColorAxes);
  738.                                 }
  739.                             }
  740.                         }
  741.                         Console.Write(i + ", " + CurrentType + ": ");
  742.                         Cube.PrintValues(CurrentColors);
  743.                         CurrentType++;
  744.                     }
  745.  
  746.                     CurrentColors = IncrementColors(CurrentColors);
  747.                 }
  748.  
  749.                 Console.WriteLine("\nTotal Types: " + (CurrentType - 1));
  750.                 //Cube.PrintValues(TypesOfAllStates);
  751.             }
  752.             public bool[] IncrementStartingPoint(bool[] StartingPoint)
  753.             {
  754.                 for (int i = 0; i < StartingPoint.Length; i++)
  755.                 {
  756.                     if (!StartingPoint[i])
  757.                     {
  758.                         StartingPoint[i] = true;
  759.  
  760.                         return StartingPoint;
  761.                     }
  762.                     else
  763.                     {
  764.                         StartingPoint[i] = false;
  765.                     }
  766.                 }
  767.  
  768.                 return StartingPoint;
  769.             }
  770.             public int[] IncrementAxes(int[] Axes)
  771.             {
  772.                 int A = Axes[Axes.Length - 1];
  773.                 int IndexA;
  774.                 int IndexB;
  775.                 int Temp;
  776.  
  777.                 for (int i = Axes.Length - 2; i >= 0; i--)
  778.                 {
  779.                     if (Axes[i] < A)
  780.                     {
  781.                         A = Axes[i];
  782.                         IndexA = i;
  783.  
  784.                         for (int j = Axes.Length - 1; j >= 0; j--)
  785.                         {
  786.                             if (Axes[j] > A)
  787.                             {
  788.                                 IndexB = j;
  789.                                 Temp = Axes[IndexA];
  790.                                 Axes[IndexA] = Axes[IndexB];
  791.                                 Axes[IndexB] = Temp;
  792.  
  793.                                 int l = Axes.Length - 1;
  794.  
  795.                                 for (int k = IndexA + 1; k < l; k++, l--)
  796.                                 {
  797.                                     Temp = Axes[k];
  798.                                     Axes[k] = Axes[l];
  799.                                     Axes[l] = Temp;
  800.                                 }
  801.                                 return Axes;
  802.                             }
  803.                         }
  804.                     }
  805.                     else
  806.                     {
  807.                         A = Axes[i];
  808.                     }
  809.                 }
  810.  
  811.                 Cube Identity = new Cube(Axes.Length, 1);
  812.                 return Identity.Axes;
  813.             }
  814.             public int[] IncrementColorAxes(int[] Axes)
  815.             {
  816.                 int A = Axes[Axes.Length - 1];
  817.                 int IndexA;
  818.                 int IndexB;
  819.                 int Temp;
  820.  
  821.                 for (int i = Axes.Length - 2; i >= 0; i--)
  822.                 {
  823.                     if (Axes[i] < A)
  824.                     {
  825.                         A = Axes[i];
  826.                         IndexA = i;
  827.  
  828.                         for (int j = Axes.Length - 1; j >= 0; j--)
  829.                         {
  830.                             if (Axes[j] > A)
  831.                             {
  832.                                 IndexB = j;
  833.                                 Temp = Axes[IndexA];
  834.                                 Axes[IndexA] = Axes[IndexB];
  835.                                 Axes[IndexB] = Temp;
  836.  
  837.                                 int l = Axes.Length - 1;
  838.  
  839.                                 for (int k = IndexA + 1; k < l; k++, l--)
  840.                                 {
  841.                                     Temp = Axes[k];
  842.                                     Axes[k] = Axes[l];
  843.                                     Axes[l] = Temp;
  844.                                 }
  845.                                 return Axes;
  846.                             }
  847.                         }
  848.                     }
  849.                     else
  850.                     {
  851.                         A = Axes[i];
  852.                     }
  853.                 }
  854.  
  855.                 for(int i = 0; i < Axes.Length; i++)
  856.                 {
  857.                     Axes[i] = i;
  858.                 }
  859.                 return Axes;
  860.             }
  861.  
  862.             public int[] IncrementColors(int[] Values)
  863.             {
  864.                 for (int i = 0; i < Values.Length; i++)
  865.                 {
  866.                     if (Values[i] != Colors - 1)
  867.                     {
  868.                         Values[i]++;
  869.  
  870.                         return Values;
  871.                     }
  872.                     else
  873.                     {
  874.                         Values[i] = 0;
  875.                     }
  876.                 }
  877.  
  878.                 return Values;
  879.             }
  880.             public int ColorsToIndex(int[] Values)
  881.             {
  882.                 int Total = 0;
  883.                 for (int i = 0; i < Values.Length; i++)
  884.                 {
  885.                     Total += Values[i] * (int)MathF.Pow(Colors, i);
  886.                 }
  887.  
  888.                 return Total;
  889.             }
  890.         }
  891.         class OptCountColoredStates
  892.         {
  893.             public int Dimension;
  894.             public int Size;
  895.             public int Colors;
  896.  
  897.             public OptCountColoredStates(int Dimension, int Size, int Colors)
  898.             {
  899.                 this.Dimension = Dimension;
  900.                 this.Size = Size;
  901.                 this.Colors = Colors;
  902.             }
  903.  
  904.             public void Count()
  905.             {
  906.                 int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
  907.                 int[] CurrentColors = new int[UnitValues.Length];
  908.                 for (int i = 0; i < UnitValues.Length; i++)
  909.                 {
  910.                     UnitValues[i] = i;
  911.                 }
  912.  
  913.  
  914.                 int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
  915.                 int AxesSymmetryNum = 1;
  916.                 int ColorAxesSymmetryNum = 1;
  917.                 for (int i = 2; i <= Dimension; i++)
  918.                 {
  919.                     AxesSymmetryNum *= i;
  920.                 }
  921.                 for (int i = 2; i <= Colors; i++)
  922.                 {
  923.                     ColorAxesSymmetryNum *= i;
  924.                 }
  925.  
  926.                 int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
  927.                 RawCube Cube = new RawCube(Dimension, Size);
  928.                 Cube.Values = UnitValues;
  929.                 int[] CurrentAxes = Cube.Axes;
  930.                 bool[] CurrentStartingPoint = Cube.StartingPoint;
  931.                 for (int i = 0; i < StartPointSymmetryNum; i++)
  932.                 {
  933.                     for (int j = 0; j < AxesSymmetryNum; j++)
  934.                     {
  935.                         int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
  936.  
  937.                         for (int k = 0; k < UnitValues.Length; k++)
  938.                         {
  939.                             AllSymmetriesUnitValues[i, j, k] = Temp[k];
  940.                         }
  941.  
  942.                         CurrentAxes = IncrementAxes(CurrentAxes);
  943.                     }
  944.  
  945.                     CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
  946.                 }
  947.  
  948.  
  949.                 int[] CurrentColorAxes = new int[Colors];
  950.                 for (int i = 0; i < Colors; i++)
  951.                 {
  952.                     CurrentColorAxes[i] = i;
  953.                 }
  954.  
  955.  
  956.                 int MaxStates = (int)MathF.Pow(Colors, MathF.Pow(Size, Dimension));
  957.                 int[] TypesOfAllStates = new int[MaxStates];
  958.                 int CurrentType = 1;
  959.                 int[] VariatedColors = new int[UnitValues.Length];
  960.                 int[] TempColors;
  961.                 int[] TempColors2;
  962.                 int[] ColoredTempColors = new int[UnitValues.Length];
  963.  
  964.                 for (int i = 0; i < MaxStates; i++)
  965.                 {
  966.                     if (TypesOfAllStates[i] == 0)
  967.                     {
  968.                         for (int j = 0; j < StartPointSymmetryNum; j++)
  969.                         {
  970.                             for (int k = 0; k < AxesSymmetryNum; k++)
  971.                             {
  972.                                 TempColors = CurrentColors;
  973.                                 for (int l = 0; l < UnitValues.Length; l++)
  974.                                 {
  975.                                     VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
  976.                                 }
  977.  
  978.                                 TempColors2 = VariatedColors;
  979.                                 for (int l = 0; l < ColorAxesSymmetryNum; l++)
  980.                                 {
  981.                                     for (int m = 0; m < UnitValues.Length; m++)
  982.                                     {
  983.                                         ColoredTempColors[m] = CurrentColorAxes[TempColors2[m]];
  984.                                     }
  985.                                     TypesOfAllStates[ColorsToIndex(ColoredTempColors)] = CurrentType;
  986.                                     CurrentColorAxes = IncrementColorAxes(CurrentColorAxes);
  987.                                 }
  988.                             }
  989.                         }
  990.                         CurrentType++;
  991.                     }
  992.  
  993.                     CurrentColors = IncrementColors(CurrentColors);
  994.                 }
  995.  
  996.                 Console.WriteLine(CurrentType - 1);
  997.             }
  998.             public bool[] IncrementStartingPoint(bool[] StartingPoint)
  999.             {
  1000.                 for (int i = 0; i < StartingPoint.Length; i++)
  1001.                 {
  1002.                     if (!StartingPoint[i])
  1003.                     {
  1004.                         StartingPoint[i] = true;
  1005.  
  1006.                         return StartingPoint;
  1007.                     }
  1008.                     else
  1009.                     {
  1010.                         StartingPoint[i] = false;
  1011.                     }
  1012.                 }
  1013.  
  1014.                 return StartingPoint;
  1015.             }
  1016.             public int[] IncrementAxes(int[] Axes)
  1017.             {
  1018.                 int A = Axes[Axes.Length - 1];
  1019.                 int IndexA;
  1020.                 int IndexB;
  1021.                 int Temp;
  1022.  
  1023.                 for (int i = Axes.Length - 2; i >= 0; i--)
  1024.                 {
  1025.                     if (Axes[i] < A)
  1026.                     {
  1027.                         A = Axes[i];
  1028.                         IndexA = i;
  1029.  
  1030.                         for (int j = Axes.Length - 1; j >= 0; j--)
  1031.                         {
  1032.                             if (Axes[j] > A)
  1033.                             {
  1034.                                 IndexB = j;
  1035.                                 Temp = Axes[IndexA];
  1036.                                 Axes[IndexA] = Axes[IndexB];
  1037.                                 Axes[IndexB] = Temp;
  1038.  
  1039.                                 int l = Axes.Length - 1;
  1040.  
  1041.                                 for (int k = IndexA + 1; k < l; k++, l--)
  1042.                                 {
  1043.                                     Temp = Axes[k];
  1044.                                     Axes[k] = Axes[l];
  1045.                                     Axes[l] = Temp;
  1046.                                 }
  1047.                                 return Axes;
  1048.                             }
  1049.                         }
  1050.                     }
  1051.                     else
  1052.                     {
  1053.                         A = Axes[i];
  1054.                     }
  1055.                 }
  1056.  
  1057.                 Cube Identity = new Cube(Axes.Length, 1);
  1058.                 return Identity.Axes;
  1059.             }
  1060.             public int[] IncrementColorAxes(int[] Axes)
  1061.             {
  1062.                 int A = Axes[Axes.Length - 1];
  1063.                 int IndexA;
  1064.                 int IndexB;
  1065.                 int Temp;
  1066.  
  1067.                 for (int i = Axes.Length - 2; i >= 0; i--)
  1068.                 {
  1069.                     if (Axes[i] < A)
  1070.                     {
  1071.                         A = Axes[i];
  1072.                         IndexA = i;
  1073.  
  1074.                         for (int j = Axes.Length - 1; j >= 0; j--)
  1075.                         {
  1076.                             if (Axes[j] > A)
  1077.                             {
  1078.                                 IndexB = j;
  1079.                                 Temp = Axes[IndexA];
  1080.                                 Axes[IndexA] = Axes[IndexB];
  1081.                                 Axes[IndexB] = Temp;
  1082.  
  1083.                                 int l = Axes.Length - 1;
  1084.  
  1085.                                 for (int k = IndexA + 1; k < l; k++, l--)
  1086.                                 {
  1087.                                     Temp = Axes[k];
  1088.                                     Axes[k] = Axes[l];
  1089.                                     Axes[l] = Temp;
  1090.                                 }
  1091.                                 return Axes;
  1092.                             }
  1093.                         }
  1094.                     }
  1095.                     else
  1096.                     {
  1097.                         A = Axes[i];
  1098.                     }
  1099.                 }
  1100.  
  1101.                 for (int i = 0; i < Axes.Length; i++)
  1102.                 {
  1103.                     Axes[i] = i;
  1104.                 }
  1105.                 return Axes;
  1106.             }
  1107.  
  1108.             public int[] IncrementColors(int[] Values)
  1109.             {
  1110.                 for (int i = 0; i < Values.Length; i++)
  1111.                 {
  1112.                     if (Values[i] != Colors - 1)
  1113.                     {
  1114.                         Values[i]++;
  1115.  
  1116.                         return Values;
  1117.                     }
  1118.                     else
  1119.                     {
  1120.                         Values[i] = 0;
  1121.                     }
  1122.                 }
  1123.  
  1124.                 return Values;
  1125.             }
  1126.             public int ColorsToIndex(int[] Values)
  1127.             {
  1128.                 int Total = 0;
  1129.                 for (int i = 0; i < Values.Length; i++)
  1130.                 {
  1131.                     Total += Values[i] * (int)MathF.Pow(Colors, i);
  1132.                 }
  1133.  
  1134.                 return Total;
  1135.             }
  1136.         }
  1137.         class Opt2CountColoredStates
  1138.         {
  1139.             public int Dimension;
  1140.             public int Size;
  1141.             public int Colors;
  1142.  
  1143.             public int ShrinkFactor = 3;
  1144.  
  1145.             public Opt2CountColoredStates(int Dimension, int Size, int Colors)
  1146.             {
  1147.                 this.Dimension = Dimension;
  1148.                 this.Size = Size;
  1149.                 this.Colors = Colors;
  1150.             }
  1151.  
  1152.             public void Count()
  1153.             {
  1154.                 int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
  1155.                 int[] CurrentColors = new int[UnitValues.Length];
  1156.                 for (int i = 0; i < UnitValues.Length; i++)
  1157.                 {
  1158.                     UnitValues[i] = i;
  1159.                 }
  1160.  
  1161.  
  1162.                 int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
  1163.                 int AxesSymmetryNum = 1;
  1164.                 int ColorAxesSymmetryNum = 1;
  1165.                 for (int i = 2; i <= Dimension; i++)
  1166.                 {
  1167.                     AxesSymmetryNum *= i;
  1168.                 }
  1169.                 for (int i = 2; i <= Colors; i++)
  1170.                 {
  1171.                     ColorAxesSymmetryNum *= i;
  1172.                 }
  1173.  
  1174.                 int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
  1175.                 RawCube Cube = new RawCube(Dimension, Size);
  1176.                 Cube.Values = UnitValues;
  1177.                 int[] CurrentAxes = Cube.Axes;
  1178.                 bool[] CurrentStartingPoint = Cube.StartingPoint;
  1179.                 for (int i = 0; i < StartPointSymmetryNum; i++)
  1180.                 {
  1181.                     for (int j = 0; j < AxesSymmetryNum; j++)
  1182.                     {
  1183.                         int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
  1184.  
  1185.                         for (int k = 0; k < UnitValues.Length; k++)
  1186.                         {
  1187.                             AllSymmetriesUnitValues[i, j, k] = Temp[k];
  1188.                         }
  1189.  
  1190.                         CurrentAxes = IncrementAxes(CurrentAxes);
  1191.                     }
  1192.  
  1193.                     CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
  1194.                 }
  1195.  
  1196.  
  1197.                 int[] CurrentColorAxes = new int[Colors];
  1198.                 for (int i = 0; i < Colors; i++)
  1199.                 {
  1200.                     CurrentColorAxes[i] = i;
  1201.                 }
  1202.  
  1203.  
  1204.                 ulong MaxStates = (ulong) Math.Pow(Colors, Math.Pow(Size, Dimension));
  1205.                 Array Data = Array.CreateInstance(typeof(ulong), (long) ((double) MaxStates / (double) ShrinkFactor) + 1);
  1206.                 int CurrentType = 1;
  1207.                 int[] VariatedColors = new int[UnitValues.Length];
  1208.                 int[] TempColors;
  1209.                 int[] TempColors2;
  1210.                 int[] ColoredTempColors = new int[UnitValues.Length];
  1211.                 bool Print = true;
  1212.  
  1213.                 for (ulong i = 0; i < MaxStates; i++)
  1214.                 {
  1215.                     if (!GetData(i, Data))
  1216.                     {
  1217.                         for (int j = 0; j < StartPointSymmetryNum; j++)
  1218.                         {
  1219.                             for (int k = 0; k < AxesSymmetryNum; k++)
  1220.                             {
  1221.                                 TempColors = CurrentColors;
  1222.                                 for (int l = 0; l < UnitValues.Length; l++)
  1223.                                 {
  1224.                                     VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
  1225.                                 }
  1226.                                 if(Print)
  1227.                                 {
  1228.                                     Console.Write(i + ", " + CurrentType + ": ");
  1229.                                     Cube.PrintValues(VariatedColors);
  1230.                                     Print = false;
  1231.                                 }
  1232.                                 TempColors2 = VariatedColors;
  1233.                                 for (int l = 0; l < ColorAxesSymmetryNum; l++)
  1234.                                 {
  1235.                                     for (int m = 0; m < UnitValues.Length; m++)
  1236.                                     {
  1237.                                         ColoredTempColors[m] = CurrentColorAxes[TempColors2[m]];
  1238.                                     }
  1239.                                     SetDataTrue(ColorsToIndex(ColoredTempColors), ref Data);
  1240.                                     CurrentColorAxes = IncrementColorAxes(CurrentColorAxes);
  1241.                                 }
  1242.                             }
  1243.                         }
  1244.                         Print = true;
  1245.                         CurrentType++;
  1246.                     }
  1247.  
  1248.                     CurrentColors = IncrementColors(CurrentColors);
  1249.                 }
  1250.  
  1251.                 Console.WriteLine(CurrentType - 1);
  1252.             }
  1253.             public bool[] IncrementStartingPoint(bool[] StartingPoint)
  1254.             {
  1255.                 for (int i = 0; i < StartingPoint.Length; i++)
  1256.                 {
  1257.                     if (!StartingPoint[i])
  1258.                     {
  1259.                         StartingPoint[i] = true;
  1260.  
  1261.                         return StartingPoint;
  1262.                     }
  1263.                     else
  1264.                     {
  1265.                         StartingPoint[i] = false;
  1266.                     }
  1267.                 }
  1268.  
  1269.                 return StartingPoint;
  1270.             }
  1271.             public int[] IncrementAxes(int[] Axes)
  1272.             {
  1273.                 int A = Axes[Axes.Length - 1];
  1274.                 int IndexA;
  1275.                 int IndexB;
  1276.                 int Temp;
  1277.  
  1278.                 for (int i = Axes.Length - 2; i >= 0; i--)
  1279.                 {
  1280.                     if (Axes[i] < A)
  1281.                     {
  1282.                         A = Axes[i];
  1283.                         IndexA = i;
  1284.  
  1285.                         for (int j = Axes.Length - 1; j >= 0; j--)
  1286.                         {
  1287.                             if (Axes[j] > A)
  1288.                             {
  1289.                                 IndexB = j;
  1290.                                 Temp = Axes[IndexA];
  1291.                                 Axes[IndexA] = Axes[IndexB];
  1292.                                 Axes[IndexB] = Temp;
  1293.  
  1294.                                 int l = Axes.Length - 1;
  1295.  
  1296.                                 for (int k = IndexA + 1; k < l; k++, l--)
  1297.                                 {
  1298.                                     Temp = Axes[k];
  1299.                                     Axes[k] = Axes[l];
  1300.                                     Axes[l] = Temp;
  1301.                                 }
  1302.                                 return Axes;
  1303.                             }
  1304.                         }
  1305.                     }
  1306.                     else
  1307.                     {
  1308.                         A = Axes[i];
  1309.                     }
  1310.                 }
  1311.  
  1312.                 Cube Identity = new Cube(Axes.Length, 1);
  1313.                 return Identity.Axes;
  1314.             }
  1315.             public int[] IncrementColorAxes(int[] Axes)
  1316.             {
  1317.                 int A = Axes[Axes.Length - 1];
  1318.                 int IndexA;
  1319.                 int IndexB;
  1320.                 int Temp;
  1321.  
  1322.                 for (int i = Axes.Length - 2; i >= 0; i--)
  1323.                 {
  1324.                     if (Axes[i] < A)
  1325.                     {
  1326.                         A = Axes[i];
  1327.                         IndexA = i;
  1328.  
  1329.                         for (int j = Axes.Length - 1; j >= 0; j--)
  1330.                         {
  1331.                             if (Axes[j] > A)
  1332.                             {
  1333.                                 IndexB = j;
  1334.                                 Temp = Axes[IndexA];
  1335.                                 Axes[IndexA] = Axes[IndexB];
  1336.                                 Axes[IndexB] = Temp;
  1337.  
  1338.                                 int l = Axes.Length - 1;
  1339.  
  1340.                                 for (int k = IndexA + 1; k < l; k++, l--)
  1341.                                 {
  1342.                                     Temp = Axes[k];
  1343.                                     Axes[k] = Axes[l];
  1344.                                     Axes[l] = Temp;
  1345.                                 }
  1346.                                 return Axes;
  1347.                             }
  1348.                         }
  1349.                     }
  1350.                     else
  1351.                     {
  1352.                         A = Axes[i];
  1353.                     }
  1354.                 }
  1355.  
  1356.                 for (int i = 0; i < Axes.Length; i++)
  1357.                 {
  1358.                     Axes[i] = i;
  1359.                 }
  1360.                 return Axes;
  1361.             }
  1362.             public int[] IncrementColors(int[] Values)
  1363.             {
  1364.                 for (int i = 0; i < Values.Length; i++)
  1365.                 {
  1366.                     if (Values[i] != Colors - 1)
  1367.                     {
  1368.                         Values[i]++;
  1369.  
  1370.                         return Values;
  1371.                     }
  1372.                     else
  1373.                     {
  1374.                         Values[i] = 0;
  1375.                     }
  1376.                 }
  1377.  
  1378.                 return Values;
  1379.             }
  1380.             public ulong ColorsToIndex(int[] Values)
  1381.             {
  1382.                 ulong Total = 0;
  1383.                 for (int i = 0; i < Values.Length; i++)
  1384.                 {
  1385.                     Total += (ulong) (Values[i] * MathF.Pow(Colors, i));
  1386.                 }
  1387.  
  1388.                 return Total;
  1389.             }
  1390.             public bool GetData(ulong Index, Array Data)
  1391.             {
  1392.                 ulong TempI1 = Index / (ulong) ShrinkFactor;
  1393.                 int TempI2 = (int) (Index % (ulong) ShrinkFactor);
  1394.                 return ((ulong) Data.GetValue((long)TempI1) & (ulong)MathF.Pow(2, TempI2)) != 0;
  1395.             }
  1396.             public void SetDataTrue(ulong Index, ref Array Data)
  1397.             {
  1398.                 ulong TempI1 = Index / (ulong) ShrinkFactor;
  1399.                 int TempI2 = (int) (Index % (ulong) ShrinkFactor);
  1400.                 Data.SetValue((ulong) Data.GetValue((long) TempI1) | (ulong)MathF.Pow(2, TempI2), (long) TempI1);
  1401.             }
  1402.         }
  1403.         class CountStaticPoints
  1404.         {
  1405.             public int Dimension;
  1406.             public int Size;
  1407.  
  1408.             public CountStaticPoints(int Dimension, int Size)
  1409.             {
  1410.                 this.Dimension = Dimension;
  1411.                 this.Size = Size;
  1412.             }
  1413.  
  1414.             public void Count()
  1415.             {
  1416.                 int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
  1417.                 for (int i = 0; i < UnitValues.Length; i++)
  1418.                 {
  1419.                     UnitValues[i] = i;
  1420.                 }
  1421.  
  1422.  
  1423.                 int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
  1424.                 int AxesSymmetryNum = 1;
  1425.                 for (int i = 2; i <= Dimension; i++)
  1426.                 {
  1427.                     AxesSymmetryNum *= i;
  1428.                 }
  1429.  
  1430.  
  1431.                 int[] CurrentSymmetryUnitValues = new int[UnitValues.Length];
  1432.                 RawCube Cube = new RawCube(Dimension, Size);
  1433.                 Cube.Values = UnitValues;
  1434.                 int[] CurrentAxes = Cube.Axes;
  1435.                 bool[] CurrentStartingPoint = Cube.StartingPoint;
  1436.                 int CurrentCountTotal = 0;
  1437.                 for (int i = 0; i < StartPointSymmetryNum; i++)
  1438.                 {
  1439.                     for (int j = 0; j < AxesSymmetryNum; j++)
  1440.                     {
  1441.                         int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
  1442.  
  1443.                         for (int k = 0; k < UnitValues.Length; k++)
  1444.                         {
  1445.                             CurrentSymmetryUnitValues[k] = Temp[k];
  1446.                         }
  1447.  
  1448.  
  1449.  
  1450.                         int CurrentCount = 1;
  1451.                         int[] AllTypes = new int[UnitValues.Length];
  1452.                         int CheckIndex = 0;
  1453.                         int[] AllCycleLengthAmounts = new int[2 * Dimension];
  1454.  
  1455.                         for (int k = 0; k < UnitValues.Length; k++)
  1456.                         {
  1457.                             int CurrentIndex = CheckIndex;
  1458.                             int TempValue = 0;
  1459.  
  1460.                             while (AllTypes[CurrentIndex] == 0)
  1461.                             {
  1462.                                 AllTypes[CurrentIndex] = CurrentCount;
  1463.                                 CurrentIndex = CurrentSymmetryUnitValues[CurrentIndex];
  1464.                                 TempValue++;
  1465.                             }
  1466.  
  1467.                             CheckIndex++;
  1468.                             if (TempValue != 0)
  1469.                             {
  1470.                                 CurrentCount++;
  1471.                                 AllCycleLengthAmounts[TempValue - 1] += TempValue;
  1472.                             }
  1473.                         }
  1474.  
  1475.                         Cube.PrintValuesRaw(CurrentStartingPoint);
  1476.                         Console.Write(", ");
  1477.                         Cube.PrintValuesRaw(CurrentAxes);
  1478.                         Console.Write(": ");
  1479.                         Cube.PrintValues(AllCycleLengthAmounts);
  1480.  
  1481.                         CurrentCountTotal += CurrentCount - 1;
  1482.  
  1483.  
  1484.                         CurrentAxes = IncrementAxes(CurrentAxes);
  1485.                     }
  1486.  
  1487.                     CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
  1488.                 }
  1489.             }
  1490.  
  1491.             public bool[] IncrementStartingPoint(bool[] StartingPoint)
  1492.             {
  1493.                 for (int i = 0; i < StartingPoint.Length; i++)
  1494.                 {
  1495.                     if (!StartingPoint[i])
  1496.                     {
  1497.                         StartingPoint[i] = true;
  1498.  
  1499.                         return StartingPoint;
  1500.                     }
  1501.                     else
  1502.                     {
  1503.                         StartingPoint[i] = false;
  1504.                     }
  1505.                 }
  1506.  
  1507.                 return StartingPoint;
  1508.             }
  1509.             public int[] IncrementAxes(int[] Axes)
  1510.             {
  1511.                 int A = Axes[Axes.Length - 1];
  1512.                 int IndexA;
  1513.                 int IndexB;
  1514.                 int Temp;
  1515.  
  1516.                 for (int i = Axes.Length - 2; i >= 0; i--)
  1517.                 {
  1518.                     if (Axes[i] < A)
  1519.                     {
  1520.                         A = Axes[i];
  1521.                         IndexA = i;
  1522.  
  1523.                         for (int j = Axes.Length - 1; j >= 0; j--)
  1524.                         {
  1525.                             if (Axes[j] > A)
  1526.                             {
  1527.                                 IndexB = j;
  1528.                                 Temp = Axes[IndexA];
  1529.                                 Axes[IndexA] = Axes[IndexB];
  1530.                                 Axes[IndexB] = Temp;
  1531.  
  1532.                                 int l = Axes.Length - 1;
  1533.  
  1534.                                 for (int k = IndexA + 1; k < l; k++, l--)
  1535.                                 {
  1536.                                     Temp = Axes[k];
  1537.                                     Axes[k] = Axes[l];
  1538.                                     Axes[l] = Temp;
  1539.                                 }
  1540.                                 return Axes;
  1541.                             }
  1542.                         }
  1543.                     }
  1544.                     else
  1545.                     {
  1546.                         A = Axes[i];
  1547.                     }
  1548.                 }
  1549.  
  1550.                 Cube Identity = new Cube(Dimension, Size);
  1551.                 return Identity.Axes;
  1552.             }
  1553.         }
  1554.  
  1555.  
  1556.        
  1557.         static void Main(string[] args)
  1558.         {
  1559.             Stopwatch Timer = new Stopwatch();
  1560.             Timer.Start();
  1561.  
  1562.             CountStaticPoints Cube = new CountStaticPoints(4, 10);
  1563.             Cube.Count();
  1564.  
  1565.             Timer.Stop();
  1566.             Console.WriteLine("\n\nOperation Took: " + Timer.ElapsedMilliseconds / 1000f + "s");
  1567.         }
  1568.        
  1569.     }
  1570.  
  1571.     /*
  1572.        while (true)
  1573.             {
  1574.                
  1575.                 Console.WriteLine("Dimensions: ");
  1576.                 int Dimension = Convert.ToInt32(Console.ReadLine());
  1577.                 Console.WriteLine("Size: ");
  1578.                 int Size = Convert.ToInt32(Console.ReadLine());
  1579.                 Console.WriteLine("Colors: ");
  1580.                 int Color = Convert.ToInt32(Console.ReadLine());
  1581.  
  1582.                 Stopwatch Timer = new Stopwatch();
  1583.                 Timer.Start();
  1584.                 CountColoredStates States = new CountColoredStates(Dimension, Size, Color);
  1585.                 States.Count();
  1586.                 Timer.Stop();
  1587.                 Console.WriteLine("Operation Took: " + Timer.ElapsedMilliseconds / 1000f + "s");
  1588.             }
  1589.      */
  1590. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement