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 8930463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:53:56+00:00 2026-06-15T08:53:56+00:00

To clarify I only wanted one or two for loops to help me on

  • 0

To clarify I only wanted one or two for loops to help me on my way, preferably in the same style as I had used in the vertical 🙂

I’m making a game using a 2D array, and I need a check that tests if at the current position (indicated by a green square) the character there is part of a diagonal sequence of “l” more of the character.

  • 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-06-15T08:53:57+00:00Added an answer on June 15, 2026 at 8:53 am
    public static boolean diagonals(char[][] b, int row, int col, int l) {
    
                int counter = 1; // because we start from the current position
                char charAtPosition = b[row][col];
                int numRows = b.length;
                int numCols = b[0].length;
                int topleft = 0;
                int topright = 0;
                int bottomleft = 0;
                int bottomright = 0;
                for (int i=row-1,j=col-1;i>=0 && j>=0;i--,j--) {
                    if (b[i][j]==charAtPosition) {
                        topleft++;
                    } else {
                        break;
                    }
                }
                for (int i=row-1,j=col+1;i>=0 && j<=numCols;i--,j++) {
                    if (b[i][j]==charAtPosition) {
                        topright++;
                    } else {
                        break;
                    }
                }
                for (int i=row+1,j=col-1;i<=numRows && j>=0;i++,j--) {
                    if (b[i][j]==charAtPosition) {
                        bottomleft++;
                    } else {
                        break;
                    }
                }
                for (int i=row+1,j=col+1;i<=numRows && j<=numCols;i++,j++) {
                    if (b[i][j]==charAtPosition) {
                        bottomright++;
                    } else {
                        break;
                    }
                }
                return topleft + bottomright + 1 >= l || topright + bottomleft + 1 >= l; //in this case l is 5
        }
    

    The idea is that we walk in four directions and count the steps. This may not be the most efficient implementation, but at least it looks neat and easy to understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

to clarify: there's only one rails command, which gets installed from the latest Rails
Please clarify my queries regarding Singleton and Multithreading: What is the best way to
Can some one clarify the space complexity of Node Relationship and property in the
I would like to clarify this issue. I had installed Cocos2d 1.01 rc on
I just wanted to clarify how to accomplish a certain effect using UIScrollView. I
I know this is very stupid question, but I wanted to clarify this. Let's
Can someone clarify that the role of a ClassLoader is not only to load
Trying to detect a user's browser with PHP only, is $_SERVER['HTTP_USER_AGENT'] a reliable way?
Can anyone please clarify what the differences are between the two? The Javadoc is
I am trying to come up with the best way to get only certain

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.