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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:46:17+00:00 2026-05-31T16:46:17+00:00

Say you’re trying to visit an array in a checkerboard pattern: 0 1 2

  • 0

Say you’re trying to visit an array in a checkerboard pattern:

  0 1 2 3 4 5 6 7
0 o • o • o • o •
1 • o • o • o • o
2 o • o • o • o •
3 • o • o • o • o
4 o • o • o • o •
5 • o • o • o • o
6 o • o • o • o •
7 • o • o • o • o

So, say you’re visiting the black elements here, and adding in all 4 white neighbours.

You can’t do this at the edges or corners, because there are only 3 and 2 white neighbours there respectively. So you’d end up adding all 3 whites on the edges and 0 for out of bounds accesses.

The inefficient way to do this is to do something like

at each element
    if element to the right is not out of bounds ...

But I don’t want to be doing checks like this.

So what I did was cut the loop into strips, so:

at each element ON LEFT EDGE
    add 3 elements i know are in bounds (right, up, down)

Then a special case for the very corners

at top left corner..
    add 2 elements i know are in bounds (right, down)

So this ended up with a very long bit of code that works, but has no constraint checking. I’m looking for a way to cut down on the length of the code block though, and make it more maintainable.

Any tricks?

  • 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-31T16:46:19+00:00Added an answer on May 31, 2026 at 4:46 pm

    One possible solution would be to pad your data instead. That is, add a boundary with some neutral values. I have illustrated this below with the x-es.

        0 1 2 3 4 5 6 7
      x x x x x x x x x x
    0 x o • o • o • o • x
    1 x • o • o • o • o x
    2 x o • o • o • o • x
    3 x • o • o • o • o x
    4 x o • o • o • o • x
    5 x • o • o • o • o x
    6 x o • o • o • o • x
    7 x • o • o • o • o x
      x x x x x x x x x x
    

    The actual “thickness” of the boundary obviously depends on how far away you look for each element (your window/kernel width/height). In the case of looking at a direct neighbor, there is only need for a boundary of size one.

    Yes, this does mean you’ll be dealing with an increased amount of data. But the advantage is that, although you’ll have to take some care of the addressing, there are no longer any special checks needed for corner/boundary cases.

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

Sidebar

Related Questions

Say I've got this array: MyArray(0)=aaa MyArray(1)=bbb MyArray(2)=aaa Is there a .net function which
Say a development team includes (or makes use of) graphic artists who create all
Say I have a container with various elements inside. In turn, any element could
Say I have a byte array with 100,000 bytes in it. I want to
Say I have two columns of names. All names in the first column are
Say, the field of Race in my table has values like W,A (white and
Say I have all these files in a folder: something(34324).php something(34).php something(3433454546).php something(65565).php something(9887).php
Say I have an array: $before = array(1,2,3,3,4,4,4,5) How would I remove just one
Say i have this old manuscript ..What am trying to do is making the
Say we have the following method: private MyObject foo = new MyObject(); // and

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.