CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > General Discussion > Algorithms & Data Structures
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Algorithms & Data Structures Discuss algorithms & data structures. Topics are not specific to any programming language.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 11th, 2009, 12:40 PM
    Berisades Berisades is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 18
    Berisades is an unknown quantity at this point (<10)
    Sequence of elements in a matrix

    Hi,
    I have a 3x3 matrix and I am trying to figure out whether there is a sequence of three similar elements diagonally, horizontally or vertically. For example:

    x x o
    o x o
    o o x

    Is there any algorithm dedicated on this kind of problem?
    Reply With Quote
      #2    
    Old November 12th, 2009, 12:34 AM
    Zachm's Avatar
    Zachm Zachm is offline
    Member +
     
    Join Date: Oct 2006
    Posts: 519
    Zachm  is a jewel in the rough (300+) Zachm  is a jewel in the rough (300+) Zachm  is a jewel in the rough (300+) Zachm  is a jewel in the rough (300+)
    Re: Sequence of elements in a matrix

    Algorithmically speaking, this is not such a difficult problem to handle that it would require some sort of special algorithm.

    You can do this:
    I assume that the matrix M[3][3] is accessed by indices 0..2, the 1st index is the row index and the 2nd is the column index.

    1. Check the type of element in the matrix center(M[1][1]) - let's say it's of type T (T being either x of o).
    2. Now check if one of the following is true:
    Code:
         a. (M[0][1] == T)  AND (M[2][1] == T) //center top && center bottom elements
         b. (M[1][0] == T)  AND (M[1][2] == T) //center left&& center right elements
         c. (M[0][0] == T)  AND (M[2][2] == T) //top left && bottom right 
         d. (M[0][2] == T)  AND (M[2][0] == T) //top right && bottom left
    3. If either a,b,c or d are true, then type T is the winner, otherwise, repeat the same trick using the top right element as starting point, only this time you only need to check the horizontal & vertical elements on the same row/column.

    Regards,
    Zachm
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > General Discussion > Algorithms & Data Structures


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:36 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.