Comparing all values within a List against each other

Posted by Kave on Stack Overflow See other posts from Stack Overflow or by Kave
Published on 2010-05-21T23:13:26Z Indexed on 2010/05/22 1:30 UTC
Read the original article Hit count: 292

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about sudoku

  • Do you play Sudoku ?

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
    Did you know that 11gR2 database could solve a Sudoku puzzle with a single query and, most of the time, and this in less than a second ? The following query shows you how ! Simply pass a flattened Sudoku grid to it a get the result instantaneously ! col "Solution" format a9 … >>> More

  • Python sudoku programming

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I need your help on this. I have this program and I must finish it. It's missing 3 parts. Here is the program I'm working with: import copy def display(A): if A: for i in range(9): for j in range(9): if type(A[i][j]) == type([]): print A[i][j][0], … >>> More

  • Sudoku solver evaluation function

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hi, So I'm trying to write a simple genetic algorithm for solving a sudoku (not the most efficient way, I know, but it's just to practice evolutionary algorithms). I'm having some problems coming up with an efficient evaluation function to test if the puzzle is solved or not and how many errors there… >>> More

  • Solving Naked Triples in Sudoku

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hello, I wished I paid more attention to the math classes back in Uni. :) How do I implement this math formula for naked triples? Naked Triples Take three cells C = {c1, c2, c3} that share a unit U. Take three numbers N = {n1, n2, n3}. If each cell in C has as its candidates ci ? N then we can… >>> More

  • Sudoku Solver

    as seen on SQL Blog - Search for 'SQL Blog'
    Today I am putting up something silly, just for fun. I set myself the task a while back to write a Sudoku solver in T-SQL, but with two dumb constraints that I would never follow given a real problem: I didn’t look at any documented techniques for solving Sudoku, and I specifically avoided T-SQL solutions… >>> More