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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:18:25+00:00 2026-05-25T00:18:25+00:00

Example Given a number of different task types that need to be completed over

  • 0

Example

Given a number of different task types that need to be completed over a period of one month:

Type  |  Number per month
--------------------------
A     |  1
B     |  5
C     |  30
D     |  15
E     |  20
--------------------------
         71

Question:

How do I generate a flat order (1-dimensional array) of types that ensures that

  • 71 jobs are completed within one month
  • the types are spreaded as equally as possible (ABAB instead of AABB)

Edit:

One Idea that came up in the comments is:

Maybe reducing each stack of types by an amount relative to its size
is better than to use the absolute amount of 1. eg. A:2, B:10 results
in “for each A take 5 B” because B is five times larger than A.

  • 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-25T00:18:26+00:00Added an answer on May 25, 2026 at 12:18 am

    Assume you have an array of task types such as:

    types = [[:A,1],[:B,5],[:C,6],[:D,2],[:E,3]]
    

    You can first sort, and then use the greater number as reference point to build the array of tasks.

    Example:

    types = [[:A,1],[:B,5],[:C,6],[:D,2],[:E,3]]
    tasks=[]; i=0
    
    asc = types.sort {|a,b| a[1] <=> b[1] }
    max = asc[types.length-1][1]
    
    (1..max).to_a.each do |i|
        types.each {|t| tasks << t[0] if t[1] >= i}
    end
    
    puts tasks.inspect
    

    produces:

    [:A, :B, :C, :D, :E, :B, :C, :D, :E, :B, :C, :E, :B, :C, :B, :C, :C]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to obtain the number of parameters a given block takes. For example:
Can anyone tell me how to format a given number of seconds (for example
Given a sorted vector with a number of values, as in the following example:
In one of the example servers given at golang.org: package main import ( flag
For example if in a textbox that is full of many different part numbers
Given x number of arrays, each with a possibly different number of elements, how
Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between
In most languages like C# for example given a string you can test (boolean)
I'm trying to run through an example given for the C++ Xerces XML library
I am trying to use Class::DBI with Catalyst::Plugin::Authentication::Store::DBIC. The example given on CPAN does

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.