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

  • Home
  • SEARCH
  • 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 4055790
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:44:43+00:00 2026-05-20T14:44:43+00:00

It is a bit hard to describe what a i want so i start

  • 0

It is a bit hard to describe what a i want so i start with and example:

Index   ArrayPos
1       0,0
2       1,0
3       0,1
4       1,1
5       2,0
6       2,1
7       2,2
8       0,2
9       1,2
10      1,2
11      3,0
12      3,1

and so on. Basically i want to fill the array not row by row or column by column but always the closest free place to 0,0 .

Would be great if duration of the algo would always be the same no matter wether if i want to get the array position for index 3 or 4237882348.

I tried some stuff with modulo but never got it.

  • 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-20T14:44:44+00:00Added an answer on May 20, 2026 at 2:44 pm

    If you don’t care about the order of x, y and y, x, then this should work for you:

    let x = ceiling(sqrt(Index)) - 1
    let y = ceiling((Index - x^2)/2) - 1
    if Index is odd, swap x and y
    

    With this, though 4,4 comes before 5,0, so it depends on the order you want when getting into the larger numbers you don’t have in your example…

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

Sidebar

Related Questions

Sorry, the title is a bit hard to understand but I'm not 100% sure
This is a bit hard for me to articulate, but in PHP you can
This is a bit hard to explain but I'll give it a go. Lets
I'll admit the title is a bit confusing but it was hard to come
This is a bit hard to explain, but I seem to be occasionally unable
A bit hard to explain, so I've set up a jsFiddle here . Basically,
It's a litle bit hard to explain, but i'll try.. There is my app,
It's a bit hard to explain, but if you go here: http://ewsprojects.com/~lyons , click
A bit hard to find a proper title... I have an object which basically
Okay, this will be a bit hard to explain, but I'll try my best.

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.