Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Author: Kacper Blachut
- * Purpose: Counts the number of unique states of nodes in a D-dimensional cube with side length N and C colors using bruteforce.
- *
- * Program used in "O pewnym problemie przeliczania unikalnych przeksztalcen na zbiorach skonczonych" for Malopolski Konkurs Prac Matematycznych 2022.
- * Doesn't have a UI
- */
- using System;
- using System.Diagnostics;
- namespace RotatingHypercubes
- {
- class BruteforceApproach
- {
- class Cube
- {
- public readonly int Dimension;
- public int Size;
- public readonly int[] Axes;
- public readonly bool[] StartingPoint;
- public readonly int TotalPoints;
- public int[] Values;
- public Cube(int Dimension, int Size, bool ClearValues = true)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- this.Axes = new int[this.Dimension];
- this.StartingPoint = new bool[this.Dimension];
- this.TotalPoints = (int) MathF.Pow(Size, Dimension);
- for(int i = 0; i < this.Dimension; i++)
- {
- Axes[i] = i + 1;
- StartingPoint[i] = false;
- }
- this.Values = new int[TotalPoints];
- if(ClearValues)
- {
- for (int i = 0; i < this.TotalPoints; i++)
- {
- Values[i] = 0;
- }
- }
- }
- public int[] Rotate(int[] NewAxes, bool[] NewStartingPoint)
- {
- if(NewAxes.Length == Dimension && NewStartingPoint.Length == Dimension)
- {
- if(AreAxesValid(NewAxes))
- {
- int[] StepSize = new int[Dimension];
- for(int i = 0; i < Dimension; i++)
- {
- StepSize[i] = (int) MathF.Pow(Size, NewAxes[i] - 1);
- }
- int StartingPointIndex = 0;
- for(int i = 0; i < Dimension; i++)
- {
- if(NewStartingPoint[i])
- {
- StartingPointIndex += (Size - 1) * (int) MathF.Pow(Size, NewAxes[i] - 1);
- }
- }
- int[] NewValues = new int[TotalPoints];
- for(int i = 0; i < TotalPoints; i++)
- {
- int TotalStep = 0;
- int[] StepValues = new int[Dimension];
- int PointsRemaining = i;
- for (int j = 0; j < Dimension; j++)
- {
- StepValues[j] = PointsRemaining % Size;
- PointsRemaining -= StepValues[j];
- PointsRemaining /= Size;
- if (NewStartingPoint[j])
- {
- TotalStep -= StepValues[j] * StepSize[j];
- }
- else
- {
- TotalStep += StepValues[j] * StepSize[j];
- }
- }
- NewValues[i] = Values[StartingPointIndex + TotalStep];
- }
- return NewValues;
- }
- else
- {
- Console.Error.Write("\n/!\\ Rotating Hypercubes Error: \nRotate() - axes specified in the input are not valid.\n");
- }
- }
- else
- {
- 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");
- }
- return new int[] {};
- }
- public bool AreAxesValid(int[] NewAxes)
- {
- bool[] Validation = new bool[NewAxes.Length];
- for(int i = 0; i < NewAxes.Length; i++)
- {
- Validation[i] = false;
- }
- for(int i = 0; i < NewAxes.Length; i++)
- {
- if(NewAxes[i] - 1 < 0 || NewAxes[i] - 1 > NewAxes.Length - 1)
- {
- return false;
- }
- else
- {
- if(Validation[NewAxes[i] - 1])
- {
- return false;
- }
- else
- {
- Validation[NewAxes[i] - 1] = true;
- }
- }
- }
- return true;
- }
- public void SetValues(int[] NewValues)
- {
- if(NewValues.Length == TotalPoints)
- {
- Values = NewValues;
- }
- else
- {
- Console.Error.Write("\n/!\\ Rotating Hypercubes Error: \nSetValues() - values specified in the input are not valid.\n");
- }
- }
- public void PrintValues(int[] Values)
- {
- Console.Write(Values[0]);
- for(int i = 1; i < Values.Length; i++)
- {
- Console.Write(", " + Values[i]);
- }
- }
- }
- class RawCube
- {
- public readonly int Dimension;
- public int Size;
- public readonly int[] Axes;
- public readonly bool[] StartingPoint;
- public readonly int TotalPoints;
- public int[] Values;
- public RawCube(int Dimension, int Size, bool ClearValues = true)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- this.Axes = new int[this.Dimension];
- this.StartingPoint = new bool[this.Dimension];
- this.TotalPoints = (int)MathF.Pow(Size, Dimension);
- for (int i = 0; i < this.Dimension; i++)
- {
- Axes[i] = i + 1;
- StartingPoint[i] = false;
- }
- this.Values = new int[TotalPoints];
- if (ClearValues)
- {
- for (int i = 0; i < this.TotalPoints; i++)
- {
- Values[i] = 0;
- }
- }
- }
- public int[] Rotate(int[] NewAxes, bool[] NewStartingPoint)
- {
- int[] StepSize = new int[Dimension];
- for (int i = 0; i < Dimension; i++)
- {
- StepSize[i] = (int)MathF.Pow(Size, NewAxes[i] - 1);
- }
- int StartingPointIndex = 0;
- for (int i = 0; i < Dimension; i++)
- {
- if (NewStartingPoint[i])
- {
- StartingPointIndex += (Size - 1) * (int)MathF.Pow(Size, NewAxes[i] - 1);
- }
- }
- int[] NewValues = new int[TotalPoints];
- for (int i = 0; i < TotalPoints; i++)
- {
- int TotalStep = 0;
- int[] StepValues = new int[Dimension];
- int PointsRemaining = i;
- for (int j = 0; j < Dimension; j++)
- {
- StepValues[j] = PointsRemaining % Size;
- PointsRemaining -= StepValues[j];
- PointsRemaining /= Size;
- if (NewStartingPoint[j])
- {
- TotalStep -= StepValues[j] * StepSize[j];
- }
- else
- {
- TotalStep += StepValues[j] * StepSize[j];
- }
- }
- NewValues[i] = Values[StartingPointIndex + TotalStep];
- }
- return NewValues;
- }
- public void PrintValues(int[] Values)
- {
- Console.Write(Values[0]);
- for (int i = 1; i < Values.Length; i++)
- {
- Console.Write(", " + Values[i]);
- }
- Console.WriteLine();
- }
- public void PrintValuesRaw(int[] Values)
- {
- for (int i = 0; i < Values.Length; i++)
- {
- Console.Write(Values[i]);
- }
- }
- public void PrintValuesRaw(bool[] Values)
- {
- for (int i = 0; i < Values.Length; i++)
- {
- if(Values[i])
- {
- Console.Write("1");
- }
- else
- {
- Console.Write("0");
- }
- }
- }
- }
- class CountStates
- {
- public readonly int Dimension;
- public readonly int Size;
- public readonly int Colors;
- public CountStates(int Dimension, int Size, int Colors)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- this.Colors = Colors;
- }
- public void Count()
- {
- int[] UnitValues = new int[(int) MathF.Pow(Size, Dimension)];
- int[] CurrentColors = new int[UnitValues.Length];
- for (int i = 0; i < UnitValues.Length; i++)
- {
- UnitValues[i] = i;
- }
- int StartPointSymmetryNum = (int) MathF.Pow(2, Dimension);
- int AxesSymmetryNum = 1;
- for (int i = 2; i <= Dimension; i++)
- {
- AxesSymmetryNum *= i;
- }
- int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
- RawCube Cube = new RawCube(Dimension, Size);
- Cube.Values = UnitValues;
- int[] CurrentAxes = Cube.Axes;
- bool[] CurrentStartingPoint = Cube.StartingPoint;
- for(int i = 0; i < StartPointSymmetryNum; i++)
- {
- for(int j = 0; j < AxesSymmetryNum; j++)
- {
- int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
- for(int k = 0; k < UnitValues.Length; k++)
- {
- AllSymmetriesUnitValues[i, j, k] = Temp[k];
- }
- CurrentAxes = IncrementAxes(CurrentAxes);
- }
- CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
- }
- int MaxStates = (int) MathF.Pow(Colors, MathF.Pow(Size, Dimension));
- int[] TypesOfAllStates = new int[MaxStates];
- int CurrentType = 1;
- int[] VariatedColors = new int[UnitValues.Length];
- int[] TempColors;
- for(int i = 0; i < MaxStates; i++)
- {
- if(TypesOfAllStates[i] == 0)
- {
- for (int j = 0; j < StartPointSymmetryNum; j++)
- {
- for (int k = 0; k < AxesSymmetryNum; k++)
- {
- for (int l = 0; l < UnitValues.Length; l++)
- {
- TempColors = CurrentColors;
- VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
- }
- TypesOfAllStates[ColorsToIndex(VariatedColors)] = CurrentType;
- }
- }
- Console.Write(i + ", " + CurrentType + ": ");
- Cube.PrintValues(CurrentColors);
- CurrentType++;
- }
- CurrentColors = IncrementColors(CurrentColors);
- }
- Console.WriteLine("\nTotal Types: " + (CurrentType - 1));
- }
- public bool[] IncrementStartingPoint(bool[] StartingPoint)
- {
- for(int i = 0; i < StartingPoint.Length; i++)
- {
- if(!StartingPoint[i])
- {
- StartingPoint[i] = true;
- return StartingPoint;
- }
- else
- {
- StartingPoint[i] = false;
- }
- }
- return StartingPoint;
- }
- public int[] IncrementAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for(int i = Axes.Length - 2; i >= 0; i--)
- {
- if(Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for(int j = Axes.Length - 1; j >= 0; j--)
- {
- if(Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- Cube Identity = new Cube(Dimension, Size);
- return Identity.Axes;
- }
- public int[] IncrementColors(int[] Values)
- {
- for (int i = 0; i < Values.Length; i++)
- {
- if (Values[i] != Colors - 1)
- {
- Values[i]++;
- return Values;
- }
- else
- {
- Values[i] = 0;
- }
- }
- return Values;
- }
- public int ColorsToIndex(int[] Values)
- {
- int Total = 0;
- for(int i = 0; i < Values.Length; i++)
- {
- Total += Values[i] * (int) MathF.Pow(Colors, i);
- }
- return Total;
- }
- }
- class OptCountStates
- {
- public int Dimension;
- public int Size;
- public int Colors;
- public OptCountStates(int Dimension, int Size, int Colors)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- this.Colors = Colors;
- }
- public void Count()
- {
- int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
- int[] CurrentColors = new int[UnitValues.Length];
- for (int i = 0; i < UnitValues.Length; i++)
- {
- UnitValues[i] = i;
- }
- int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
- int AxesSymmetryNum = 1;
- for (int i = 2; i <= Dimension; i++)
- {
- AxesSymmetryNum *= i;
- }
- int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
- RawCube Cube = new RawCube(Dimension, Size);
- Cube.Values = UnitValues;
- int[] CurrentAxes = Cube.Axes;
- bool[] CurrentStartingPoint = Cube.StartingPoint;
- for (int i = 0; i < StartPointSymmetryNum; i++)
- {
- for (int j = 0; j < AxesSymmetryNum; j++)
- {
- int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
- for (int k = 0; k < UnitValues.Length; k++)
- {
- AllSymmetriesUnitValues[i, j, k] = Temp[k];
- }
- CurrentAxes = IncrementAxes(CurrentAxes);
- }
- CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
- }
- int MaxStates = (int)MathF.Pow(Colors, MathF.Pow(Size, Dimension));
- bool[] TypesOfAllStates = new bool[MaxStates];
- int CurrentType = 1;
- int[] VariatedColors = new int[UnitValues.Length];
- int[] TempColors;
- for (int i = 0; i < MaxStates; i++)
- {
- if (TypesOfAllStates[i] == false)
- {
- for (int j = 0; j < StartPointSymmetryNum; j++)
- {
- for (int k = 0; k < AxesSymmetryNum; k++)
- {
- for (int l = 0; l < UnitValues.Length; l++)
- {
- TempColors = CurrentColors;
- VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
- }
- TypesOfAllStates[ColorsToIndex(VariatedColors)] = true;
- }
- }
- CurrentType++;
- }
- CurrentColors = IncrementColors(CurrentColors);
- }
- Console.WriteLine(CurrentType - 1);
- }
- public bool[] IncrementStartingPoint(bool[] StartingPoint)
- {
- for (int i = 0; i < StartingPoint.Length; i++)
- {
- if (!StartingPoint[i])
- {
- StartingPoint[i] = true;
- return StartingPoint;
- }
- else
- {
- StartingPoint[i] = false;
- }
- }
- return StartingPoint;
- }
- public int[] IncrementAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- Cube Identity = new Cube(Dimension, Size);
- return Identity.Axes;
- }
- public int[] IncrementColors(int[] Values)
- {
- for (int i = 0; i < Values.Length; i++)
- {
- if (Values[i] != Colors - 1)
- {
- Values[i]++;
- return Values;
- }
- else
- {
- Values[i] = 0;
- }
- }
- return Values;
- }
- public int ColorsToIndex(int[] Values)
- {
- int Total = 0;
- for (int i = 0; i < Values.Length; i++)
- {
- Total += Values[i] * (int)MathF.Pow(Colors, i);
- }
- return Total;
- }
- }
- class CountColoredStates
- {
- public readonly int Dimension;
- public readonly int Size;
- public readonly int Colors;
- public CountColoredStates(int Dimension, int Size, int Colors)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- this.Colors = Colors;
- }
- public void Count()
- {
- int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
- int[] CurrentColors = new int[UnitValues.Length];
- for (int i = 0; i < UnitValues.Length; i++)
- {
- UnitValues[i] = i;
- }
- int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
- int AxesSymmetryNum = 1;
- int ColorAxesSymmetryNum = 1;
- for (int i = 2; i <= Dimension; i++)
- {
- AxesSymmetryNum *= i;
- }
- for (int i = 2; i <= Colors; i++)
- {
- ColorAxesSymmetryNum *= i;
- }
- int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
- RawCube Cube = new RawCube(Dimension, Size);
- Cube.Values = UnitValues;
- int[] CurrentAxes = Cube.Axes;
- bool[] CurrentStartingPoint = Cube.StartingPoint;
- for (int i = 0; i < StartPointSymmetryNum; i++)
- {
- for (int j = 0; j < AxesSymmetryNum; j++)
- {
- int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
- for (int k = 0; k < UnitValues.Length; k++)
- {
- AllSymmetriesUnitValues[i, j, k] = Temp[k];
- }
- CurrentAxes = IncrementAxes(CurrentAxes);
- }
- CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
- }
- int[] CurrentColorAxes = new int[Colors];
- for(int i = 0; i < Colors; i++)
- {
- CurrentColorAxes[i] = i;
- }
- int MaxStates = (int)MathF.Pow(Colors, MathF.Pow(Size, Dimension));
- int[] TypesOfAllStates = new int[MaxStates];
- int CurrentType = 1;
- int[] VariatedColors = new int[UnitValues.Length];
- int[] TempColors;
- int[] TempColors2;
- int[] ColoredTempColors = new int[UnitValues.Length];
- for (int i = 0; i < MaxStates; i++)
- {
- if (TypesOfAllStates[i] == 0)
- {
- for (int j = 0; j < StartPointSymmetryNum; j++)
- {
- for (int k = 0; k < AxesSymmetryNum; k++)
- {
- TempColors = CurrentColors;
- for (int l = 0; l < UnitValues.Length; l++)
- {
- VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
- }
- TempColors2 = VariatedColors;
- for (int l = 0; l < ColorAxesSymmetryNum; l++)
- {
- for(int m = 0; m < UnitValues.Length; m++)
- {
- ColoredTempColors[m] = CurrentColorAxes[TempColors2[m]];
- }
- TypesOfAllStates[ColorsToIndex(ColoredTempColors)] = CurrentType;
- CurrentColorAxes = IncrementColorAxes(CurrentColorAxes);
- }
- }
- }
- Console.Write(i + ", " + CurrentType + ": ");
- Cube.PrintValues(CurrentColors);
- CurrentType++;
- }
- CurrentColors = IncrementColors(CurrentColors);
- }
- Console.WriteLine("\nTotal Types: " + (CurrentType - 1));
- //Cube.PrintValues(TypesOfAllStates);
- }
- public bool[] IncrementStartingPoint(bool[] StartingPoint)
- {
- for (int i = 0; i < StartingPoint.Length; i++)
- {
- if (!StartingPoint[i])
- {
- StartingPoint[i] = true;
- return StartingPoint;
- }
- else
- {
- StartingPoint[i] = false;
- }
- }
- return StartingPoint;
- }
- public int[] IncrementAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- Cube Identity = new Cube(Axes.Length, 1);
- return Identity.Axes;
- }
- public int[] IncrementColorAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- for(int i = 0; i < Axes.Length; i++)
- {
- Axes[i] = i;
- }
- return Axes;
- }
- public int[] IncrementColors(int[] Values)
- {
- for (int i = 0; i < Values.Length; i++)
- {
- if (Values[i] != Colors - 1)
- {
- Values[i]++;
- return Values;
- }
- else
- {
- Values[i] = 0;
- }
- }
- return Values;
- }
- public int ColorsToIndex(int[] Values)
- {
- int Total = 0;
- for (int i = 0; i < Values.Length; i++)
- {
- Total += Values[i] * (int)MathF.Pow(Colors, i);
- }
- return Total;
- }
- }
- class OptCountColoredStates
- {
- public int Dimension;
- public int Size;
- public int Colors;
- public OptCountColoredStates(int Dimension, int Size, int Colors)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- this.Colors = Colors;
- }
- public void Count()
- {
- int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
- int[] CurrentColors = new int[UnitValues.Length];
- for (int i = 0; i < UnitValues.Length; i++)
- {
- UnitValues[i] = i;
- }
- int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
- int AxesSymmetryNum = 1;
- int ColorAxesSymmetryNum = 1;
- for (int i = 2; i <= Dimension; i++)
- {
- AxesSymmetryNum *= i;
- }
- for (int i = 2; i <= Colors; i++)
- {
- ColorAxesSymmetryNum *= i;
- }
- int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
- RawCube Cube = new RawCube(Dimension, Size);
- Cube.Values = UnitValues;
- int[] CurrentAxes = Cube.Axes;
- bool[] CurrentStartingPoint = Cube.StartingPoint;
- for (int i = 0; i < StartPointSymmetryNum; i++)
- {
- for (int j = 0; j < AxesSymmetryNum; j++)
- {
- int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
- for (int k = 0; k < UnitValues.Length; k++)
- {
- AllSymmetriesUnitValues[i, j, k] = Temp[k];
- }
- CurrentAxes = IncrementAxes(CurrentAxes);
- }
- CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
- }
- int[] CurrentColorAxes = new int[Colors];
- for (int i = 0; i < Colors; i++)
- {
- CurrentColorAxes[i] = i;
- }
- int MaxStates = (int)MathF.Pow(Colors, MathF.Pow(Size, Dimension));
- int[] TypesOfAllStates = new int[MaxStates];
- int CurrentType = 1;
- int[] VariatedColors = new int[UnitValues.Length];
- int[] TempColors;
- int[] TempColors2;
- int[] ColoredTempColors = new int[UnitValues.Length];
- for (int i = 0; i < MaxStates; i++)
- {
- if (TypesOfAllStates[i] == 0)
- {
- for (int j = 0; j < StartPointSymmetryNum; j++)
- {
- for (int k = 0; k < AxesSymmetryNum; k++)
- {
- TempColors = CurrentColors;
- for (int l = 0; l < UnitValues.Length; l++)
- {
- VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
- }
- TempColors2 = VariatedColors;
- for (int l = 0; l < ColorAxesSymmetryNum; l++)
- {
- for (int m = 0; m < UnitValues.Length; m++)
- {
- ColoredTempColors[m] = CurrentColorAxes[TempColors2[m]];
- }
- TypesOfAllStates[ColorsToIndex(ColoredTempColors)] = CurrentType;
- CurrentColorAxes = IncrementColorAxes(CurrentColorAxes);
- }
- }
- }
- CurrentType++;
- }
- CurrentColors = IncrementColors(CurrentColors);
- }
- Console.WriteLine(CurrentType - 1);
- }
- public bool[] IncrementStartingPoint(bool[] StartingPoint)
- {
- for (int i = 0; i < StartingPoint.Length; i++)
- {
- if (!StartingPoint[i])
- {
- StartingPoint[i] = true;
- return StartingPoint;
- }
- else
- {
- StartingPoint[i] = false;
- }
- }
- return StartingPoint;
- }
- public int[] IncrementAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- Cube Identity = new Cube(Axes.Length, 1);
- return Identity.Axes;
- }
- public int[] IncrementColorAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- for (int i = 0; i < Axes.Length; i++)
- {
- Axes[i] = i;
- }
- return Axes;
- }
- public int[] IncrementColors(int[] Values)
- {
- for (int i = 0; i < Values.Length; i++)
- {
- if (Values[i] != Colors - 1)
- {
- Values[i]++;
- return Values;
- }
- else
- {
- Values[i] = 0;
- }
- }
- return Values;
- }
- public int ColorsToIndex(int[] Values)
- {
- int Total = 0;
- for (int i = 0; i < Values.Length; i++)
- {
- Total += Values[i] * (int)MathF.Pow(Colors, i);
- }
- return Total;
- }
- }
- class Opt2CountColoredStates
- {
- public int Dimension;
- public int Size;
- public int Colors;
- public int ShrinkFactor = 3;
- public Opt2CountColoredStates(int Dimension, int Size, int Colors)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- this.Colors = Colors;
- }
- public void Count()
- {
- int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
- int[] CurrentColors = new int[UnitValues.Length];
- for (int i = 0; i < UnitValues.Length; i++)
- {
- UnitValues[i] = i;
- }
- int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
- int AxesSymmetryNum = 1;
- int ColorAxesSymmetryNum = 1;
- for (int i = 2; i <= Dimension; i++)
- {
- AxesSymmetryNum *= i;
- }
- for (int i = 2; i <= Colors; i++)
- {
- ColorAxesSymmetryNum *= i;
- }
- int[,,] AllSymmetriesUnitValues = new int[StartPointSymmetryNum, AxesSymmetryNum, UnitValues.Length];
- RawCube Cube = new RawCube(Dimension, Size);
- Cube.Values = UnitValues;
- int[] CurrentAxes = Cube.Axes;
- bool[] CurrentStartingPoint = Cube.StartingPoint;
- for (int i = 0; i < StartPointSymmetryNum; i++)
- {
- for (int j = 0; j < AxesSymmetryNum; j++)
- {
- int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
- for (int k = 0; k < UnitValues.Length; k++)
- {
- AllSymmetriesUnitValues[i, j, k] = Temp[k];
- }
- CurrentAxes = IncrementAxes(CurrentAxes);
- }
- CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
- }
- int[] CurrentColorAxes = new int[Colors];
- for (int i = 0; i < Colors; i++)
- {
- CurrentColorAxes[i] = i;
- }
- ulong MaxStates = (ulong) Math.Pow(Colors, Math.Pow(Size, Dimension));
- Array Data = Array.CreateInstance(typeof(ulong), (long) ((double) MaxStates / (double) ShrinkFactor) + 1);
- int CurrentType = 1;
- int[] VariatedColors = new int[UnitValues.Length];
- int[] TempColors;
- int[] TempColors2;
- int[] ColoredTempColors = new int[UnitValues.Length];
- bool Print = true;
- for (ulong i = 0; i < MaxStates; i++)
- {
- if (!GetData(i, Data))
- {
- for (int j = 0; j < StartPointSymmetryNum; j++)
- {
- for (int k = 0; k < AxesSymmetryNum; k++)
- {
- TempColors = CurrentColors;
- for (int l = 0; l < UnitValues.Length; l++)
- {
- VariatedColors[l] = TempColors[AllSymmetriesUnitValues[j, k, l]];
- }
- if(Print)
- {
- Console.Write(i + ", " + CurrentType + ": ");
- Cube.PrintValues(VariatedColors);
- Print = false;
- }
- TempColors2 = VariatedColors;
- for (int l = 0; l < ColorAxesSymmetryNum; l++)
- {
- for (int m = 0; m < UnitValues.Length; m++)
- {
- ColoredTempColors[m] = CurrentColorAxes[TempColors2[m]];
- }
- SetDataTrue(ColorsToIndex(ColoredTempColors), ref Data);
- CurrentColorAxes = IncrementColorAxes(CurrentColorAxes);
- }
- }
- }
- Print = true;
- CurrentType++;
- }
- CurrentColors = IncrementColors(CurrentColors);
- }
- Console.WriteLine(CurrentType - 1);
- }
- public bool[] IncrementStartingPoint(bool[] StartingPoint)
- {
- for (int i = 0; i < StartingPoint.Length; i++)
- {
- if (!StartingPoint[i])
- {
- StartingPoint[i] = true;
- return StartingPoint;
- }
- else
- {
- StartingPoint[i] = false;
- }
- }
- return StartingPoint;
- }
- public int[] IncrementAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- Cube Identity = new Cube(Axes.Length, 1);
- return Identity.Axes;
- }
- public int[] IncrementColorAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- for (int i = 0; i < Axes.Length; i++)
- {
- Axes[i] = i;
- }
- return Axes;
- }
- public int[] IncrementColors(int[] Values)
- {
- for (int i = 0; i < Values.Length; i++)
- {
- if (Values[i] != Colors - 1)
- {
- Values[i]++;
- return Values;
- }
- else
- {
- Values[i] = 0;
- }
- }
- return Values;
- }
- public ulong ColorsToIndex(int[] Values)
- {
- ulong Total = 0;
- for (int i = 0; i < Values.Length; i++)
- {
- Total += (ulong) (Values[i] * MathF.Pow(Colors, i));
- }
- return Total;
- }
- public bool GetData(ulong Index, Array Data)
- {
- ulong TempI1 = Index / (ulong) ShrinkFactor;
- int TempI2 = (int) (Index % (ulong) ShrinkFactor);
- return ((ulong) Data.GetValue((long)TempI1) & (ulong)MathF.Pow(2, TempI2)) != 0;
- }
- public void SetDataTrue(ulong Index, ref Array Data)
- {
- ulong TempI1 = Index / (ulong) ShrinkFactor;
- int TempI2 = (int) (Index % (ulong) ShrinkFactor);
- Data.SetValue((ulong) Data.GetValue((long) TempI1) | (ulong)MathF.Pow(2, TempI2), (long) TempI1);
- }
- }
- class CountStaticPoints
- {
- public int Dimension;
- public int Size;
- public CountStaticPoints(int Dimension, int Size)
- {
- this.Dimension = Dimension;
- this.Size = Size;
- }
- public void Count()
- {
- int[] UnitValues = new int[(int)MathF.Pow(Size, Dimension)];
- for (int i = 0; i < UnitValues.Length; i++)
- {
- UnitValues[i] = i;
- }
- int StartPointSymmetryNum = (int)MathF.Pow(2, Dimension);
- int AxesSymmetryNum = 1;
- for (int i = 2; i <= Dimension; i++)
- {
- AxesSymmetryNum *= i;
- }
- int[] CurrentSymmetryUnitValues = new int[UnitValues.Length];
- RawCube Cube = new RawCube(Dimension, Size);
- Cube.Values = UnitValues;
- int[] CurrentAxes = Cube.Axes;
- bool[] CurrentStartingPoint = Cube.StartingPoint;
- int CurrentCountTotal = 0;
- for (int i = 0; i < StartPointSymmetryNum; i++)
- {
- for (int j = 0; j < AxesSymmetryNum; j++)
- {
- int[] Temp = Cube.Rotate(CurrentAxes, CurrentStartingPoint);
- for (int k = 0; k < UnitValues.Length; k++)
- {
- CurrentSymmetryUnitValues[k] = Temp[k];
- }
- int CurrentCount = 1;
- int[] AllTypes = new int[UnitValues.Length];
- int CheckIndex = 0;
- int[] AllCycleLengthAmounts = new int[2 * Dimension];
- for (int k = 0; k < UnitValues.Length; k++)
- {
- int CurrentIndex = CheckIndex;
- int TempValue = 0;
- while (AllTypes[CurrentIndex] == 0)
- {
- AllTypes[CurrentIndex] = CurrentCount;
- CurrentIndex = CurrentSymmetryUnitValues[CurrentIndex];
- TempValue++;
- }
- CheckIndex++;
- if (TempValue != 0)
- {
- CurrentCount++;
- AllCycleLengthAmounts[TempValue - 1] += TempValue;
- }
- }
- Cube.PrintValuesRaw(CurrentStartingPoint);
- Console.Write(", ");
- Cube.PrintValuesRaw(CurrentAxes);
- Console.Write(": ");
- Cube.PrintValues(AllCycleLengthAmounts);
- CurrentCountTotal += CurrentCount - 1;
- CurrentAxes = IncrementAxes(CurrentAxes);
- }
- CurrentStartingPoint = IncrementStartingPoint(CurrentStartingPoint);
- }
- }
- public bool[] IncrementStartingPoint(bool[] StartingPoint)
- {
- for (int i = 0; i < StartingPoint.Length; i++)
- {
- if (!StartingPoint[i])
- {
- StartingPoint[i] = true;
- return StartingPoint;
- }
- else
- {
- StartingPoint[i] = false;
- }
- }
- return StartingPoint;
- }
- public int[] IncrementAxes(int[] Axes)
- {
- int A = Axes[Axes.Length - 1];
- int IndexA;
- int IndexB;
- int Temp;
- for (int i = Axes.Length - 2; i >= 0; i--)
- {
- if (Axes[i] < A)
- {
- A = Axes[i];
- IndexA = i;
- for (int j = Axes.Length - 1; j >= 0; j--)
- {
- if (Axes[j] > A)
- {
- IndexB = j;
- Temp = Axes[IndexA];
- Axes[IndexA] = Axes[IndexB];
- Axes[IndexB] = Temp;
- int l = Axes.Length - 1;
- for (int k = IndexA + 1; k < l; k++, l--)
- {
- Temp = Axes[k];
- Axes[k] = Axes[l];
- Axes[l] = Temp;
- }
- return Axes;
- }
- }
- }
- else
- {
- A = Axes[i];
- }
- }
- Cube Identity = new Cube(Dimension, Size);
- return Identity.Axes;
- }
- }
- static void Main(string[] args)
- {
- Stopwatch Timer = new Stopwatch();
- Timer.Start();
- CountStaticPoints Cube = new CountStaticPoints(4, 10);
- Cube.Count();
- Timer.Stop();
- Console.WriteLine("\n\nOperation Took: " + Timer.ElapsedMilliseconds / 1000f + "s");
- }
- }
- /*
- while (true)
- {
- Console.WriteLine("Dimensions: ");
- int Dimension = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Size: ");
- int Size = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Colors: ");
- int Color = Convert.ToInt32(Console.ReadLine());
- Stopwatch Timer = new Stopwatch();
- Timer.Start();
- CountColoredStates States = new CountColoredStates(Dimension, Size, Color);
- States.Count();
- Timer.Stop();
- Console.WriteLine("Operation Took: " + Timer.ElapsedMilliseconds / 1000f + "s");
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement