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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:01:34+00:00 2026-05-24T23:01:34+00:00

Argh! I know I will get this eventually but at this point I’m almost

  • 0

Argh! I know I will get this eventually but at this point I’m almost 2 hours into it and still stuck.

I need to resolve the individual indexes for each “level” of a jagged array for a specific location. It’s hard to explain, but if you imagine a 3 level jagged array with [2,3,4] lengths. If you then were to flatten that out into a single array it would have a size of 24. Now, let’s say you needed to find the the indexes (one for each level of the jagged array) that would be equal to the single array index 22. It would be 1,2,1. It’s not hard to figure out a single scenario, but I’m trying to figure out what the algorithm is to resolve these values for a variable depth jagged array.

Here is a simple code sample of my current attempt:

using System;

class Program
{
    static void Main(string[] args)
    {
        //  Build up the data and info about level depth
        int[] levelDepth = new[] { 2, 3, 4 };
        int[][][] data = new int[][][]
        {
            new int[][] { new int[4], new int[4], new int[4] },
            new int[][] { new int[4], new int[4], new int[4] }
        };

        int requestedValue = 22;
        float temp = requestedValue;

        //  Store the index of each level array to get to the index 
        //  for the requested value
        int[] levelIndexes = new int[3] { 0, 0, 0 };

        //  The following does not work!
        int i = levelDepth.Length;
        while (i > 0)
        {
            temp = temp / levelDepth[i - 1];
            levelIndexes[i - 1] = (int)Math.Round(temp);

            i--;
        }
    }
}

It doesn’t work correctly, although it ALMOST gets me what I need but I think that just may be luck. I suspect this is a common problem that has been solved before, I just don’t have the experience to figure it out. 🙁

Also, before anyone tells me that using arrays like this is terrible or “why don’t you store your data like this” – The above description and code is simulating the layout of some decoder chips on our hardware and I need to work out a way to resolve a path to a specific graph of cascading chips; the above example exactly matches the layout of the chips. I’m stuck with 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-24T23:01:35+00:00Added an answer on May 24, 2026 at 11:01 pm

    You shouldn’t use floats here.

    int[] levelDepth = new[] { 2, 3, 4 };
    int requestedValue = 22;
    int[] levelIndexes = new int[levelDepth.Length];
    
    
    for (int i = 0; i < levelDepth.Length; i++)
    {
      // need to go from { 2, 3, 4 } -> { 3*4, 4, 1 }
      int f = 1;
      for (int j = i+1; j < levelDepth.Length; j++)      
         f *= levelDepth[j];
    
      levelIndexes[i] = requestedValue / f;  // integer divide
      requestedValue = requestedValue % f;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So yeah, I'm gettin' into this testing thing! But I don't know what to
I know, this is just so common. However, I am not able to get
This is probably an easy one, but I can't figure it out. argh... C#
argh, this should be an easy one. How can I set the directory that
ARGH! What's wrong with this?? $(document).ready(function() { var monkeyTrouble = $('#monkeyTrouble').attr('rel'); if (monkeyTrouble =
This seems non-trivial (it gets asked quite a lot on various forums), but I
I added this code to my web page: <input id='argh' type='text' onfocus='this.value=7'> Unless the
case i of 0..99 : Function-call('bobo') ; 100..209 : function-smell('Hobo'); 210..300 : function-yikes('argh'); end;
public class PatternTest { public static void main(String[] args) { System.out.println(117_117_0009v0_172_5738_5740.matches(^([0-9_]+v._.))); } } This
I just buit a website that works good on any browser even ipad but

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.