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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:02:22+00:00 2026-05-31T19:02:22+00:00

I know this question is difficult to understand but I need a mathematical equation

  • 0

I know this question is difficult to understand but I need a mathematical equation for javascript.

I am having dynamic number from 0 to 7.

Now I am having 5 records:

a = from 0 to 7,
b = from 0 to 7,
c = from 0 to 7,
d = from 0 to 7,
e = from 0 to 7

Now i need an equation from which i can find possible output of a,b,c,d and e that makes average 5.

Like for average = 5:
1. a = 5, b = 5, c = 5, d = 5, e = 5
2. a = 2, b = 7, c = 6, d = 5, e = 5

User will enter desired average and i need to throw possible outputs to make filled average.

  • 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-31T19:02:23+00:00Added an answer on May 31, 2026 at 7:02 pm

    This seems to be a problem related to Integer Programming. It can be solved relatively efficiently using a Dynamic Programming strategy that maintains an invariant for smaller sub problems and merges these sub problems into a final solution. Here’s a high-level algorithm that gets you to your goal:

    1) Start with a random seed number, x_1 between 0..7

    2) Now do the following three times (i = 2, 3, 4) :

    3) Find the minimally possible next number. To get an average of 5 for your five numbers, your target sum for all five is 25. So you need to ensure that you don’t deny yourself the ability to reach 25 at all. So let min_i+1 determine the smallest number of 0..7 so that the sum of all x_i so far plus min_i+1 * (5-i) >= 25.

    Example: Say i=2 and your numbers so far were 4 and 5. Then the minimally allowed third number min_3 is 6. The sum so far is 9 and 5-i = 3. 9 + 3*6 = 27 >= 25 and 9 + 3*5 = 24 < 25. This means if you chose 5 as min_3, you would no longer be able to reach your goal of a sum of 25.

    4) Choose x_i+1 as a random number between min_i+1 and 7.

    5) Finally, choose x_5 as 25 – sum of x_1..x_5. Output x_1 to x_5.


    Example for the entire algorithm:

    Let x_1 = 6.

    => min_2 = 5, sum = 6

    Let x_2 = 5.

    => min_3 = 5, sum = 11

    Let x_3 = 7.

    => min_4 = 4, sum = 18

    Let x_4 = 5

    => sum = 23

    => x_5 = 2 (=25 – 23)

    Output: [6, 5, 7, 5, 2] which indeed has an average of 5.

    Now this algorithm will produce very biased output, if you want to make it appear more randomly, simply serve a permutation of the final result, e.g. in our example you could output [5, 7, 2, 5, 6] instead.

    It should be no problem to implement this in Javascript and it can be easily adapted to suit other possible ranges for x_i and the total average. Just be sure to modify the target sum as n * avg if your final sample size should be n with an average of avg.

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

Sidebar

Related Questions

This is a difficult and open-ended question I know, but I thought I'd throw
I know this will be a difficult question, so I am not necessarily looking
I know this question has been asked before, but I ran into a problem.
I know this question isn't directly programming related, but since I want to be
I know this question has been asked a bit before. But looking around I
I know this question might sound a little cheesy but this is the first
I know this question has been done but I have a slightly different twist
I know this question is overly popular, but I find nothing that addresses rewriting
I appreciate this is an incredibly noob question, but having Googled multiple combinations of
Bit flags are a little difficult to understand :) I know about this 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.