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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:41:55+00:00 2026-05-22T18:41:55+00:00

So I got a problem that I can’t wrap my mind around. I’m creating

  • 0

So I got a problem that I can’t wrap my mind around.

I’m creating a shopping list that is divided into ten categories of various lengths. (All of the items come from a database). I got it to work when using a single column, but I have to divide the list into four columns. The code should decide which categories should go where so that the four columns have the most equal number of items possible.

This is what the list will look like when the code is working.

Out of these ten categories, four of them have a specific category they belong to.

The way I’ve approached this is to count the total number of items and divide it by four to compute the average number of items per column. I put the four special categories in their respective column and kept track of how many items were now in each column.

Now I still have six columns remaining of various sizes. What is the best approach to put them in the column that would fit best? Since some categories are much larger than others, some columns could potentially have three or four categories.

UPDATE: Right after I posted this I came to the realization that I should find the column with the least items and add the largest category to it. This seems like it will work. And it looks like Dave is suggesting the same!

  • 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-22T18:41:56+00:00Added an answer on May 22, 2026 at 6:41 pm

    After writing your 4 “main” categories to the columns, make an array that has a total of each column:

    $columnTotals = array(10,6,12,13)
    //example - obviously you'd use count or something to get the totals
    

    Then, order your non-special categories in an array by largest to smallest:

    $subcatTotals = array(18,15,13,12,8,4);
    //here, you'll have to get the totals, then use an array sort to order them
    //probably want an associative array so you know which total matches which cat.
    

    Then, in a loop, add the first(largest) sub-category to the smallest column, and get a new total for that column.

    This SHOULD give you the most even columns you can get – at least it has in all the made-up examples I’ve tried it with.

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

Sidebar

Related Questions

Here's the problem I'm having, I've got a set of logs that can grow
Has anyone else run into this problem before? I've got a method that calls
I got this problem that I can't just solve algorithmically. Let's say i have
I got one problem that how can i display the .jpeg and other type
I've got this problem that I can't solve. Partly because I can't explain it
I've got a problem that I think is probably straight forward but I can't
I got a small problem that I can't figure out. I have a superclass
I've got a problem in a C++ program that I can't solve. I'm trying
I've got a MVC 3 view which displays a list of items that can
I've got a problem that probably has a very easy solution, but I can't

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.