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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:15:59+00:00 2026-06-18T05:15:59+00:00

In my program I need to generate array with powers’ (from 0 to 5)

  • 0

In my program I need to generate array with powers’ (from 0 to 5) sum of numbers from 1 to 100,000.

So I tried to compile this code:

const enum size_t MAX_ARRAY_SIZE = 100_000 + 1;
const enum size_t MAX_POWER_SIZE = 5 + 1;
const enum power_sum = calc_power_sum();

// some unimportant code here

pure ulong[MAX_POWER_SIZE][MAX_ARRAY_SIZE] calc_power_sum() {
    ulong[MAX_POWER_SIZE][MAX_ARRAY_SIZE] power_sum;

    power_sum[0][] = 1;

    foreach (x, ref element; power_sum[1]) {
        element = x;
    }

    foreach (n; 2 .. MAX_POWER_SIZE) {
        foreach (x, ref element; power_sum[n]) {
            element = power_sum[n - 1][x] * power_sum[1][x];
        }
    }


    foreach (ref power; power_sum) {
        foreach (x; 1 .. MAX_ARRAY_SIZE) {
            power[x] += power[x - 1]; // error appears here
        }
    }

    return power_sum;
}

But compiler says:

$ dmd problem.d
problem.d(130): Error: array index 6 is out of bounds [1LU, 2LU, 3LU, 4LU, 5LU, 6LU][0 .. 6]
problem.d(15): called from here: calc_power_sum()

What am I doing wrong?

  • 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-18T05:16:00+00:00Added an answer on June 18, 2026 at 5:16 am

    At first glance looks like you have simply misunderstood array dimension order. You have

    ulong[MAX_POWER_SIZE][MAX_ARRAY_SIZE]
    

    and your code assumes directly opposite

    ulong[MAX_ARRAY_SIZE][MAX_POWER_SIZE]
    

    Also I am afraid 100 000 may be a bit too much, after above mentioned fix I get an internal compiler error. Works for smaller MAX_ARRAY_SIZE values though.

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

Sidebar

Related Questions

In a Python program, I need to generate normally-distributed random numbers with a specific,
Does anyone knows how to generate QR code using Java program? I need to
For my program I need to generate valid infix expressions with customizable complexity. The
I need to generate multiple databases to SQL, so I need script/program to automatically
I need a program that reads from multiple files and displays a report based
I've written some code to generate an array of structures. The id variable is
I am working on a code which I need to send sms messages from
I need to generate a program that generates the Fibonacci Sequence Here is what
I am developing a program in which I need to generate a random number
I need a Solution, how to read an Array from another Project in Visual

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.