比较列表中的所有值
我有点卡在这里,无法进一步思考。
public struct CandidateDetail
{
public int CellX { get; set; }
public int CellY { get; set; }
public int CellId { get; set; }
}
var dic = new Dictionary<int, List<CandidateDetail>>();
如何以最有效的方式将每个 CandidateDetail 项目与同一字典中的其他 CandidateDetail 项目进行比较?
示例:字典有三个键:5、6 和 1。因此我们有三个条目。现在这些关键条目中的每一个都会有一个与之关联的列表。在这种情况下,假设这三个数字中的每一个在与每个键关联的列表中恰好有两个 CandidateDetails 项。换句话说,这意味着我们在不同或相同的单元格中有两个 5、两个 6 和两个 1。我想知道:
if[5].1stItem.CellId == [6].1stItem.CellId =>我们受到了打击。这意味着我们在同一个 Cell 中有一个 5 和一个 6 if[5].2ndItem.CellId == [6].2ndItem.CellId =>;完美的。我们发现另外5个和6个 一起在不同的牢房内。 if[1].1stItem.CellId == ...
现在我还需要对照其他 5 和 6 检查 1,看看该 1 是否存在于前两个相同的单元格中。
Linq 表达式也许有帮助吗?我被困在这里了... 我不知道......也许我采取了错误的方法。我正在尝试解决数独游戏的“隐藏对”。 :)
http://www.sudokusolver.eu/ExplainSolveMethodD.aspx
非常感谢, 卡韦
I am a bit stuck here and can't think further.
public struct CandidateDetail
{
public int CellX { get; set; }
public int CellY { get; set; }
public int CellId { get; set; }
}
var dic = new Dictionary<int, List<CandidateDetail>>();
How can I compare each CandidateDetail item against other CandidateDetail items within the same dictionary in the most efficient way?
Example: There are three keys for the dictionary: 5, 6 and 1. Therefore we have three entries. now each of these key entries would have a List associated with. In this case let say each of these three numbers has exactly two CandidateDetails items within the list associated to each key. This means in other words we have two 5, two 6 and two 1 in different or in the same cells. I would like to know:
if[5].1stItem.CellId == [6].1stItem.CellId => we got a hit. That means we have a 5 and a 6 within the same Cell
if[5].2ndItem.CellId == [6].2ndItem.CellId => perfect. We found out that the other 5 and 6
are together within a different cell.
if[1].1stItem.CellId == ...
Now I need to check the 1 also against the other 5 and 6 to see if the one exists within the previous same two cells or not.
Could a Linq expression help perhaps? I am quite stuck here...
I don't know...Maybe I am taking the wrong approach. I am trying to solve the "Hidden pair" of the game Sudoku. :)
http://www.sudokusolver.eu/ExplainSolveMethodD.aspx
Many Thanks,
Kave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理序列中的每一对展示了如何处理每个列表中的配对
Process every pair in a sequence shows how you can process every pair within a list
您可能需要修改
select
子句以仅获取所需的信息,或者如果您只想匹配来自不同键的候选者,则添加另一个where
子句。You may want to modify the
select
clause for only the information you want or add anotherwhere
clause if you want only matching candidates from different keys.