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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:36:29+00:00 2026-06-07T21:36:29+00:00

I’m trying to create an method to evenly distribute an array into X numbers

  • 0

I’m trying to create an method to evenly distribute an array into X numbers of new arrays, where there is only allowed 15 items pr array, and you are only allowed to create a new array, if the previous have 10 items, except if the array has less than 10 items.

EDIT

To make my question more understandable for future readers.

  • This is just like a fabric.
  • You need to build X number of products.
  • One product takes T amount to build for an employee.

How many employees do you need and how do you share the work load between them?

END EDIT

 Max allowed number in array = 15;
 Min allowed number in array = 10;    

 Number = Numbers of Items in the Collection.

 Number  5 =>   [5]
 Number 13 =>   [13]
 Number 16 =>   [10] [6]
 Number 29 =>   [15] [14]
 Number 30 =>   [15] [15]
 Number 31 =>   [11] [10] [10]
 Number 32 =>   [12] [10] [10]
 Number 33 =>   [11] [11] [11]

I’m trying to solve this in C#.

This is my code so far, but it fails at numbers like 16 = [16], 29 = [19][10], 38 = [18][10][10]

const int maxAllowedOrderLines = 15;
const int minAllowedOrderLines = 10;
var optimalOrderDisp = new List<int>();

Console.WriteLine("Number of OrderLines");
int linjer = Convert.ToInt32(Console.ReadLine());

if (linjer <= maxAllowedOrderLines)
   optimalOrderDisp.Add(linjer);
else
{
   for (var i = maxAllowedOrderLines; i > 0; i--)
   {
      var maxOrderLines = linjer%i;
      if (maxOrderLines == 0 || i <= minAllowedOrderLines || linjer < maxAllowedOrderLines)
      {
         Console.WriteLine("Optimal number of order lines {0}--{1}", i, (double) linjer/(double) i);

          var optimalNumberOfOrders = linjer/i;
          for (var orderNumber = 0; orderNumber < optimalNumberOfOrders; orderNumber++)
          {
             optimalOrderDisp.Add(i);
          }

          if (maxOrderLines != 0)
             optimalOrderDisp[0] += maxOrderLines;
          break;
       }
    }
 }
 foreach (var i1 in optimalOrderDisp)
 {
    Console.Write("[{0}]", i1);
 }
 Console.WriteLine();
  • 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-07T21:36:30+00:00Added an answer on June 7, 2026 at 9:36 pm

    Erm …

    const double bucketSize = 15.0;
    var totalItems = (double)linjer;
    var optimumBuckets = Math.Ceiling(totalItems / bucketSize);
    var itemsPerBucket = (int)Math.Ceiling(totalItems / optimumBuckets);
    
    var buckets = new int[(int)optimumBuckets];
    
    var itemsLeft = (int)totalItems
    for (var i = 0; i < buckets.length; i++)
    {
        if (itemsLeft < itemsPerBucket)
        {
            buckets[i] = itemsLeft;
        }
        else
        {
            buckets[i] = itemsPerBucket;
        }
        itemsLeft -= itemsPerBucket;
    }
    

    seems to do what you want.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.