# Calculate start middle and end of any number [closed]

EDIT: It appears what OP wants is this: divide a given positive integer $n$ into three parts; the parts are to be roughly equal; the first and last parts to be equal.

ORIGINAL POST:

I need a start, middle and end value of any given number, it doesn't have to be equally distributed, just needs a bit of logic. Example:

var parts = 3;

Obviously, I could devide this by 3 and get an even devised result start: 1; middle: 1; end: 1.

However if the user was to put in something like:

var parts = 8;

In my eyes, the answer would be start: 2; middle: 4; end: 2.

I need to perform a basic task depending on the length of the 'parts' variable.

Example:

I need to calculate the start, middle and end values so I can do something like this.

for (var t=0; t < start; t++){
console.log('Start');
}
for (var t=0; t < middle; t++){
console.log('Middle');
}
for (var t=0; t < end; t++){
console.log('End');
}


How could I calculate this?

-

## closed as unclear what you're asking by Alex Wertheim, Amzoti, Jared, L.G., Danny Cheuk Jun 30 '13 at 7:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Please, before voting to delete, ask yourself, what is unclear about the question, in its current form? –  Gerry Myerson Jan 4 at 2:42
@GerryMyerson I really don't know why it was closed, I don't really see what's so unclear but thankyou anyway :) –  Shannon Hochkins Jan 7 at 1:21

So, you are trying to divide a given positive integer $n$ into three parts; you want the parts to be roughly equal; it also seems you'd like the first and last parts to be equal. First divide $n$ by $3$, and call the quotient $q$, and the remainder $r$. Then your desired parts are $q$, $q+r$, $q$. This agrees both with your example of $3\to1,1,1$ and $8\to2,4,2$.
var parts=9; var start = end = middle = (parts - (parts % 3)) / 3; middle += parts % 3; Like that? :) –  Shannon Hochkins Jun 30 '13 at 6:51