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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:35:33+00:00 2026-05-11T20:35:33+00:00

A random thought popped into my head (when I was sharing a chocolate bar

  • 0

A random thought popped into my head (when I was sharing a chocolate bar of course!). I was wondering if there is a generic algorithm to solve this problem.

The problem goes like this:

Info

1. You have a chocolate bar with small squares arranged in a rectangular matrix

2. There are n people in the room

The problem

Write an algorithm that outputs the optimal configuration (p x q) where the bar can be shared equally between n, n-1, n-2...., 2, 1 people given the following restrictions:

1. A small squares (the unit square) cannot be cut into smaller pieces
2. All breaks have to be made completely along one axis
3. The total number of breaks cannot be more than n (this is to discourage inefficient solutions such as trying to break the whole bar apart into small pieces and dividing the small pieces)
4. p or q cannot be equal to 1. yx pointed out in one of the answers that the problem is easily solvable if one side has 1 bar. This, however is not a good solution for real world situations – which was the intent of solving this problem 🙂

Example

For n = 4, the optimal configuration is 4 x 3.

 ~~~~ ~~~~ ~~~~ ~~~~
|    |    |    |    |
 ~~~~ ~~~~ ~~~~ ~~~~
|    |    |    |    |
 ~~~~ ~~~~ ~~~~ ~~~~
|    |    |    |    |
 ~~~~ ~~~~ ~~~~ ~~~~

This configuration can be divided among:

4 people in 3 breaks along the vertical axes
3 people with 2 breaks along the horizontal axes
2 people with 1 break right down the middle

Other empirical solutions are (n, p, q) = (1, 1, 1); (2, 2, 1); (3, 3, 2); (4, 4, 3); (5, 5, 12); (6, 6, 10) OR (6, 5, 12)

Clarifications
A break is defined as a cut along one axis for the subset of the bar, if applicable. To better illustrate this, say you have a 2 x 2 chocolate bar like this:

 ~~~~ ~~~~
|    |    |
 ~~~~ ~~~~
|    |    |
 ~~~~ ~~~~

Conventional wisdom says you need to make 2 breaks (the perpendicular axes in the middle – down and across) to divide this bar into 4 pieces. However, in the real world (if it were a chocolate bar), you would first break it in half and then break each half again, separately. This makes a total of 3 breaks – 1 break on the entire bar and 2 breaks on 2 different sub sets of the bar.

I couldn’t find solution anywhere on the internet – if anyone feels this is not a programming related question or a solution already exists, feel free to close the question =)

  • 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-11T20:35:33+00:00Added an answer on May 11, 2026 at 8:35 pm

    It seems to me that you’re looking for numbers that are evenly dividable by all numbers between 1 and n inclusive. That’s called the least common multiple of 1, …, n. A square containing the least common multiple of 1, …, n squares would by definition be evenly dividable into pieces of size 1, …, n. You’re looking for a maximum of n splits, which adds additional complexity to the problem which may or may not be possible.

    Your example for n = 4 is the LCM(4,3,2,1) which is 12. LCM(5,4,3,2,1) is 60. LCM(6,5,4,3,2,1) is also 60.

    They can always be laid out as 1xLCM(n,…,1) rectangles, and always be dividable into 1,…,n even piles in n-1 or fewer divisions.

    For example, when n = 4, LCM(4,3,2,1) = 12. The rectangle is

    ############
    

    And can be divided as follows:

    1: ############     // 0 cuts
    2: ###### ######    // 1 cut
    3: #### #### ####   // 2 cuts
    4: ### ### ### ###  // 3 cuts (3 being n-1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thought I would throw this one out there and see what other people's experiences
I'm trying to select a random 10% sampling from a small table. I thought
For a random event generator I'm writing I need a simple algorithm to generate
[Just a random thought] I have a pdf doc that is downloaded when the
Note: NOT Javascript. :-) Hello, I just had a random thought, and have decided
Sorry, this looks longer than it probably is but I thought I should include
How do I generate random floats in C++? I thought I could take the
I have this code: def random_answerlist(self): self.li = [] self.winning_button = random.randint(0, 3) i
I always thought the random functions in cstdlib were only rand and srand, but
This is a rather random problem. I'm using CSS3Pie to handle CSS3 compatibility in

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.