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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:45:06+00:00 2026-05-30T04:45:06+00:00

I am given a list of months ( TOTAL_NUM_MONTHS ) and from this list

  • 0

I am given a list of months (TOTAL_NUM_MONTHS) and from this list I need to select only 12 months proportionally. I have following algorithm up to now:

IF TOTAL_NUM_MONTHS<12 THEN
   STEP = 1
ELSE IF (TOTAL_NUM_MONTHS % 12 == 0) THEN
   STEP = TOTAL_NUM_MONTHS / 12
ELSE
   STEP = ???

So, if total number of months is less then 12 I will select all of them, and if it is divisible to 12 then I will select them with a step equal to TOTAL_NUM_MONTHS/12.

Question: What to do if the total number of months is not divisible to 12 ? How to calculate the step in order to select 12 months from the given list of months proportionally ?

  • 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-30T04:45:07+00:00Added an answer on May 30, 2026 at 4:45 am

    Maybe you should take a step of variable length for each iteration, something like:

    step(i) = step(i-1) + NUM_MONTHS/12.0, step(0) = 0.0 [note: step(i) is a floating point number and not an integer]

    And use floor(step(i)) to chose element. [assuming here NUM_MONTHS > 12]

    i is the step’s number. You chose a[i] = floor(step(i)) as your i’th element for each 0 <= i < 12

    The idea is to create a monotonically increasing function that distributes uniformly. It doesn’t get more uniform then NUM_MONTHS/12 size, with floating points. So, you calculate it with floating points – and then use floor(step(i)) to get the integer out of it.

    This method ensures 2 things:

    1. No element is chosen twice [because NUM_MONTHS/12 > 1]
    2. The maximum difference between every two steps is 1.

    Also note that if NUM_STEPS % 12 == 0 this method decays to your else if and behave the same.

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

Sidebar

Related Questions

I have created the following to explain my problem. Given a list with PayDates
Given a data with list of a months worth of data, I need to
Given a list like this: num = [1, 2, 3, 4, 5] There are
I need to get a list of weeks for a given month, with Monday
I need to get a list of all Saturday dates in a given year.
I have an FQL query that queries a list of photos. For months, it
Hi I have about six months experience in web development. I have the following
is there a MySQL select of function to have the list days of any
I have the following case : a list or array .the size is a
Until now I selected Entities like this: public List<Customer> findAll() { TypedQuery<Customer> query =

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.