我希望我能更多地关注大学的数学课。:)
如何为裸三元组实现这个数学公式?
裸体三人组
三元组
取三个单元格 C = {c1, c2, c3},它们共享一个单位 U。取三个数字 N = {n1, n2, n3}。如果 C 中的每个单元格都有候选 ci ⊆ N,那么我们可以从 U 中的其他单元格中删除所有 ni ∈ N。**
我有一个将单元(例如,框、行或列)作为参数的方法。该单元包含 9 个单元格,因此我需要从盒子中一次比较 3 个单元格的所有组合,也许将它们放入堆栈或集合中以进行进一步计算。
下一步将逐一采用这些 3 单元组合,并将它们的候选者与 3 个数字进行比较。同样,这 3 个数字可以是从 1 到 9 的任何可能组合。这就是我所需要的。
但我该怎么做呢?我会得到多少种组合?我是否得到 3 x 9 = 27 个单元格组合,然后得到相同的数字 (N)?
你将如何在经典的 C# 循环中解决这个问题?请不要使用 Lambda 表达式,我已经很困惑了 :)
代码: 为了在这里代表它们,我不得不缩短类。
public class Cell : INotifyPropertyChanged
{
public ObservableCollection<ObservableCollection<Candidate>> CandidateActual {...}
public int Id { ... }
//Position of the Cell inside a box if applicable
public int CellBoxPositionX { get; private set; }
public int CellBoxPositionY { get; private set; }
//Position of the Cell inside the game board
public int CellBoardPositionX { get; private set; }
public int CellBoardPositionY { get; private set; }
//Position of the Box inside the game board
public int BoxPositionX { get; private set; }
public int BoxPositionY { get; private set; }
public int CountCandidates { ... }
public int? Value { ...}
public Candidate this[int number]
{
get
{
if (number < 1 || number > PossibleValues.Count)
{
throw new ArgumentOutOfRangeException("number", number, "Invalid Number Index");
}
switch (number)
{
case 1:
return CandidateActual[0][0];
case 2:
return CandidateActual[0][1];
case 3:
return CandidateActual[0][2];
case 4:
return CandidateActual[1][0];
case 5:
return CandidateActual[1][1];
case 6:
return CandidateActual[1][2];
case 7:
return CandidateActual[2][0];
case 8:
return CandidateActual[2][1];
case 9:
return CandidateActual[2][2];
default:
return null;
}
}
}
}
候选人
public class Candidate : INotifyPropertyChanged
{
private int? _value;
public int? Value { ... }
}
盒子:
public class Box : INotifyPropertyChanged
{
public ObservableCollection<ObservableCollection<Cell>> BoxActual { ... }
public Cell this[int row, int column]
{
get
{
if(row < 0 || row >= BoxActual.Count)
{
throw new ArgumentOutOfRangeException("row", row, "Invalid Row Index");
}
if(column < 0 || column >= BoxActual.Count)
{
throw new ArgumentOutOfRangeException("column", column, "Invalid Column Index");
}
return BoxActual[row][column];
}
}
}
木板
public class Board : INotifyPropertyChanged
{
public ObservableCollection<ObservableCollection<Box>> GameBoard {...}
public Cell this[int boardRowPosition, int boardColumnPosition]
{
get
{
int totalSize = GameBoard.Count*GameBoard.Count();
if (boardRowPosition < 0 || boardRowPosition >= totalSize)
throw new ArgumentOutOfRangeException("boardRowPosition", boardRowPosition, "Invalid boardRowPosition index");
if (boardColumnPosition < 0 || boardColumnPosition >= totalSize)
throw new ArgumentOutOfRangeException("boardColumnPosition", boardColumnPosition, "Invalid boardColumnPosition index");
return
GameBoard[boardRowPosition/GameBoard.Count][boardColumnPosition/GameBoard.Count][
boardRowPosition%GameBoard.Count, boardColumnPosition%GameBoard.Count];
}
}
public Box this[int boardRowPosition, int boardColumnPosition, bool b]
{
get
{
int totalSize = GameBoard.Count * GameBoard.Count();
if (boardRowPosition < 0 || boardRowPosition >= totalSize)
throw new ArgumentOutOfRangeException("boardRowPosition", boardRowPosition, "Invalid boardRowPosition index");
if (boardColumnPosition < 0 || boardColumnPosition >= totalSize)
throw new ArgumentOutOfRangeException("boardColumnPosition", boardColumnPosition, "Invalid boardColumnPosition index");
return
GameBoard[boardRowPosition / GameBoard.Count][boardColumnPosition / GameBoard.Count];
}
}
}
非常感谢您的帮助,