Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3962540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:06:31+00:00 2026-05-20T03:06:31+00:00

*Note i refer to thing as a matrix but it is not, it is

  • 0

*Note i refer to thing as a matrix but it is not, it is just a collection of 1’s and zeros

Suppose you have a matrix that is always square (n x n). Is it possible to determine if there exists a single column/row/diagonal such that each item is a 1.

Take the matrix below for instance (True):

1 0 0
1 1 0
0 0 1

Another example (True):

1 1 1
0 0 0
0 1 0

And finally one without a solution (False):

0 1 1
1 0 0
0 0 0

Notice how there is a diagonal filled with 1’s. The rule is there is either there is a solution or there is no solution. There can be any number of 1’s or zeros within the matrix. All i really need to do is, if you have (n x n) then there should be a row/column/diagonal with n elements the same.

If this is not possible with recursions, please let me know what is the best and most efficient method. Thanks a lot, i have been stuck on this for hours so any help is appreciated (if you could post samples that would be great).

EDIT
This is one solution that i came up with but it gets really complex after a while.

Take the first example i gave and string all the rows together so you get:

1 0 0, 1 1 0, 0 0 1
Then add zeros between the rows to get:
1 0 0 0, 1 1 0 0, 0 0 1 0

Now if you look closely, you will see that the distances between the 1’s that form a solution are equal. I dont know how this can be implemented though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:06:32+00:00Added an answer on May 20, 2026 at 3:06 am

    In search for an elegant solution I came up with this:

    class LineOfOnesChecker(object):
    
        _DIAG_INDICES = (lambda i: i, lambda i: -i - 1)
    
        def __init__(self, matrix):
            self._matrix = matrix
            self._len_range = range(len(self._matrix))
    
        def has_any(self):
            return self.has_row() or self.has_col() or self.has_diag()
    
        def has_row(self):
            return any(all(elem == 1 for elem in row)
                       for row in self._matrix)
    
        def has_col(self):
            return any(all(self._matrix[i][j] == 1 for i in self._len_range)
                       for j in self._len_range)
    
        def has_diag(self):
            return any(all(self._matrix[transf(i)][i] == 1 for i in self._len_range)
                       for transf in self._DIAG_INDICES)
    

    Usage:

    print LineOfOnesChecker(matrix).has_any()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note, this is not a duplicate of .prop() vs .attr() ; that question refers
NOTE: This is a followup to my question here. I have a program that
I have a foreign key that has to refer primary keys of two different
Is it worth using Comet for events that are not needed in realtime, but
Note: In this question I'm using the term autocomplete (or iterative search) to refer
(Note: This is not a question about what is the best way with code
Note: I am not asking how to use Google Code's SVN repo as a
Note: Not sure if this is the right stack, please tell if I should
NOTE: I have read Routing From the Inside Out AND the Engine Yard blog
First off, I'm using Access 2000 and DAO. I have code that executes a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.