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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:49:01+00:00 2026-06-06T06:49:01+00:00

Say, we have an N-dimensional grid and some point X in it with coordinates

  • 0

Say, we have an N-dimensional grid and some point X in it with coordinates (x1, x2, …, xN).
For simplicity we can assume that the grid is unbounded.

Let there be a radius R and a sphere of this radius with center in X, that is the set of all points in grid such that their manhattan distance from X is equal to R.

I suspect that their will be 2*N*R such points.

My question is: how do I enumerate them in efficient and simple way? By “enumerate” I mean the algorithm, which, given N, X and R will produce the list of points which form this sphere (where point is the list of it’s coordinates).

UPDATE: Initially I called the metric I used “Hamming distance” by mistake. My apologies to all who answered the question. Thanks to Steve Jessop for pointing this out.

  • 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-06T06:49:03+00:00Added an answer on June 6, 2026 at 6:49 am

    Consider the minimal axis-aligned hypercube that bounds the hypersphere and write a procedure to enumerate the grid points inside the hypercube.

    Then you only need a simple filter function that allows you to discard the points that are on the cube but not in the hypersphere.

    This is a simple and efficient solution for small dimensions. For instance, for 2D, 20% of the points enumerated for the bounding square are discarded; for 6D, almost 90% of the hypercube points are discarded.

    For higher dimensions, you will have to use a more complex approach: loop over every dimension (you may need to use a recursive function if the number of dimensions is variable). For every loop you will have to adjust the minimal and maximal values depending on the values of the already calculated grid components. Well, try doing it for 2D, enumerating the points of a circle and once you understand it, generalizing the procedure to higher dimensions would be pretty simple.

    update: errh, wait a minute, you want to use the Manhattan distance. Calling the cross polytope “sphere” may be correct but I found it quite confusing! In any case you can use the same approach.

    If you only want to enumerate the points on the hyper-surface of the cross polytope, well, the solution is also very similar, you have to loop over every dimension with appropriate limits. For instance:

    for (i = 0; i <= n; i++)
      for (j = 0; j + i <= n; j++)
        ...
           for (l = 0; l + ...+ j + i <= n; l++) {
             m = n - l - ... - j - i;
             printf(pat, i, j, ..., l, m);
           }
    

    For every point generated that way, then you will have to consider all the variations resulting of negating any of the components to cover all the faces and then displace them with the vector X.

    update

    Perl implementation for the case where X = 0:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    sub enumerate {
        my ($d, $r) = @_;
    
        if ($d == 1) {
            return ($r ? ([-$r], [$r]) : [0])
        }
        else {
            my @r;
            for my $i (0..$r) {
                for my $s (enumerate($d - 1, $r - $i)) {
                    for my $j ($i ? (-$i, $i) : 0) {
                        push @r, [@$s, $j]
                    }
                }
            }
            return @r;
        }
    }
    
    @ARGV == 2 or die "Usage:\n  $0 dimension radius\n\n";
    my ($d, $r) = @ARGV;
    my @r = enumerate($d, $r);
    print "[", join(',', @$_), "]\n" for @r;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2-dimensional list of named tuples (let's say that each tuple has
I have a large 2 dimensional grid, let us say 10000 X 10000. From
Let's say I have the following multi-dimensional array: $fruits['apple']['name'] = 'macintosh'; Is there any
Let say I have a multi-dimensional array like int a[10][10] int b[10][10] void arrayCopy(int*
Let's say I have 2 2-dimensional arrays: int a1[][2] = { {1,2}, {3,4}, {5,6}
Say you have the following ANSI C code that initializes a multi-dimensional array :
Let's say I have the following empty two dimensional array in Python: q =
Let's say I have the following dataset bodysize=rnorm(20,30,2) bodysize=sort(bodysize) survive=c(0,0,0,0,0,1,0,1,0,0,1,1,0,1,1,1,0,1,1,1) dat=as.data.frame(cbind(bodysize,survive)) I'm aware that
Let's say we have a two dimensional arrays, arr[N][N] , where N is a
Let's say you have a two dimensional plane with 2 points (called a 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.