Class MagicSquares
Utility methods for working with magic squares, i.e. the sums of the values in each of their rows, columns, and (optionally) their diagonals add up to the same value.
These all require the possible values in the magic square to be unique.
Inheritance
Inherited Members
Namespace: SudokuSpice
Assembly: SudokuSpice.dll
Syntax
public static class MagicSquares
Methods
| Improve this Doc View SourceComputeSets(ReadOnlySpan<Int32>)
Computes each unique set of values of length SquareRoot(values.Length) that can be formed from the given values.
Declaration
public static HashSet<BitVector> ComputeSets(ReadOnlySpan<int> values)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Int32> | values | All the possible values for the magic square. Each value must be unique. |
Returns
Type | Description |
---|---|
System.Collections.Generic.HashSet<BitVector> |
ComputeSets(ReadOnlySpan<Int32>, Int32, BitVector)
Computes each unique set of values of length boxSize
that can be
formed from the given values.
Declaration
public static HashSet<BitVector> ComputeSets(ReadOnlySpan<int> values, int boxSize, BitVector allPossibleValues)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Int32> | values | All the possible values for the magic square. Each value must be unique. Values must
have length |
System.Int32 | boxSize | |
BitVector | allPossibleValues | The |
Returns
Type | Description |
---|---|
System.Collections.Generic.HashSet<BitVector> |
ComputeSum(ReadOnlySpan<Int32>)
Computes the "sum" that each row/column/diagonal must add up to.
Declaration
public static int ComputeSum(ReadOnlySpan<int> values)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Int32> | values | All the possible values for the magic square. Each value must be unique. |
Returns
Type | Description |
---|---|
System.Int32 |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if no sum is possible. |