/// <summary> /// Computes each unique set of values of length SquareRoot(values.Length) that can be /// formed from the given values. /// </summary> /// <param name="values"> /// All the possible values for the magic square. Each value must be unique. /// </param> public static HashSet <BitVector> ComputeSets(ReadOnlySpan <int> values) { int boxSize = Boxes.IntSquareRoot(values.Length); BitVector allPossibleValues = new BitVector(); for (int i = 0; i < values.Length; ++i) { if (allPossibleValues.IsBitSet(values[i])) { throw new ArgumentException("Values must be unique."); } allPossibleValues.SetBit(values[i]); } return(ComputeSets(values, boxSize, allPossibleValues)); }
/// <summary> /// Computes the "sum" that each row/column/diagonal must add up to. /// </summary> /// <param name="values"> /// All the possible values for the magic square. Each value must be unique. /// </param>. /// <exception cref="ArgumentException"> /// Thrown if no sum is possible. /// </exception> public static int ComputeSum(ReadOnlySpan <int> values) { int boxSize = Boxes.IntSquareRoot(values.Length); return(_ComputeSum(values, boxSize)); }