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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:54+00:00 2026-05-25T12:42:54+00:00

Hello and thank you for taking the time to read my question, I have

  • 0

Hello and thank you for taking the time to read my question,

I have a matrix of randomly generated boolean values, what I want to do is compare each individual cell of the matrix to its surroundings, by surroundings I mean the cells to the immediate left, right, top, bottom, and all 4 diagonals. If a surrounding cell is true I need it to return a “1”, if false, a “0”, so that I may add the number of true and false cells surrounding an individual cell, so an output would be something like “1 + 1 + 1 + 0 etc”. Im very sorry if I have explained this poorly, if more information in needed please let me know.

  • 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-25T12:42:54+00:00Added an answer on May 25, 2026 at 12:42 pm

    The simplest way to implement this is to nest two for loops, one for x and one for y, with an array of the values [-1, 0, 1]. Make sure to account for boundaries of the matrix, and don’t add the value of the current cell.

    One note: this would be a good place to split your code into two methods, one doing the looping and calling the other with coordinates, while the other performs edge-case checking and returns the result.

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

Sidebar

Related Questions

Hello everyone and as usual, thank you to anyone taking the time to read
Hello and thank you for taking the time to help me solve my problem.
Hello everybody and thanks for taking the time to read this ; I was
Hello everybody and thanks for taking the time to read this . Iam working
Hello and thanks in advance for taking a look at this. I have discovered
So i have a problem with taking an array and looping through the values
Hello fellow programmers. I have a SQL Server 2005 query that is taking a
thank you for taking time to look at this. I am trying to code
Hello all, While taking my time in the bath I though of something interesting.
I have implemented a working solutions, please see my comment below Hello, and thank

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.