mark patindol

Greenhorn

Posts: 23

posted 2 years ago

Hi. I just need the formula to solve this problem.

Write a program that accepts as input three positive integers representing the diameter of the cigarettes to be packed

and the dimensions of the pack to be used.

The required output is the maximum number of cigarettes that can be packed without damaging/re-sizing the cigarettes or packs

NOTE: the diameter of cigarette is 1 and 2 only.

Example: Diameter is: 1 and dimension1: 2 and dimension2: 4

the output is. Maximum number of cigarettes can be put on the pack is 6.

ex.2 diameter is 2 and dimension is 10 and dimension2 is 17

the output is. The maximum number of cigarettes can be put on pack is 40.

ex.3 diameter is 2 and dimension is 5 and dimension2 is 7

the output is. The maximum number of cigarettes can be put on pack is 6.

THANKS IN ADVANCE! I just need the formula to get the number of cigarettes that can be put inside on the pack on its dimension

sorry for my bad grammar lol.

Write a program that accepts as input three positive integers representing the diameter of the cigarettes to be packed

and the dimensions of the pack to be used.

The required output is the maximum number of cigarettes that can be packed without damaging/re-sizing the cigarettes or packs

NOTE: the diameter of cigarette is 1 and 2 only.

Example: Diameter is: 1 and dimension1: 2 and dimension2: 4

the output is. Maximum number of cigarettes can be put on the pack is 6.

ex.2 diameter is 2 and dimension is 10 and dimension2 is 17

the output is. The maximum number of cigarettes can be put on pack is 40.

ex.3 diameter is 2 and dimension is 5 and dimension2 is 7

the output is. The maximum number of cigarettes can be put on pack is 6.

THANKS IN ADVANCE! I just need the formula to get the number of cigarettes that can be put inside on the pack on its dimension

sorry for my bad grammar lol.

posted 2 years ago

- 1

Hello, and welcome to the Ranch!

I'm not sure you're going to get the help you're looking for here. We are NotACodeMill and will not do the work for you. Particularly if it's homework, when we encourage you to DoYourOwnHomework.

The best way to get help is to show us what you've done or tried so far, and tell us exactly the problem you're facing right now.

I'm not sure you're going to get the help you're looking for here. We are NotACodeMill and will not do the work for you. Particularly if it's homework, when we encourage you to DoYourOwnHomework.

The best way to get help is to show us what you've done or tried so far, and tell us exactly the problem you're facing right now.

Tim Driven Development

mark patindol

Greenhorn

Posts: 23

posted 2 years ago

the No.1 example on my work is easy to understand. just multiply the dimension1 which is 2 and dimension 2 which is 4. then multiply on the diameter which is 1. so that the maximum number of cigarettes can be put on the pack is 8.

But if my diameter is 2 i really have a hard time to get it. sorry

But if my diameter is 2 i really have a hard time to get it. sorry

posted 2 years ago

from a mathematical point of view, I don't think the packing circles inside a rectangle has been solved. It's tricky, since you can have the second row sort of next into the first...

But ignoring that...

If you have a box that is eight units wide, and each object takes two units of space, how many object can you put across the width?

But ignoring that...

If you have a box that is eight units wide, and each object takes two units of space, how many object can you put across the width?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

posted 2 years ago

How many 2s are there in 4? How many 2s are there in 6? How many 2s are there in 7? Those are very simple calculations that involve a basic arithmetic operation.

- 1

mark patindol wrote:the No.1 example on my work is easy to understand. just multiply the dimension1 which is 2 and dimension 2 which is 4. then multiply on the diameter which is 1. so that the maximum number of cigarettes can be put on the pack is 8.

But if my diameter is 2 i really have a hard time to get it. sorry

How many 2s are there in 4? How many 2s are there in 6? How many 2s are there in 7? Those are very simple calculations that involve a basic arithmetic operation.

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

posted 2 years ago

I don't know if you are supposed to consider the fact that cigarettes can be arranged in honeycomb pattern in a pack.

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

Piet Souris

Master Rancher

Posts: 2041

75

posted 2 years ago

No, OP isn't.

Just look at one of the examples given in the opening post.

When D = 2, d1 = 10 and d2 = 17, then, according to the

answer given, 40 cigarettes fit. So it is not necessary to

go the complex honeycomb way, that Fred was also hinting

at. So, to OP, look at Junilu's first reply. That's how to proceed.

/********************************/

However, as an easy to calculate upperbound for the number:

what, given a diameter D, is the area of a cigarette, and

what is the area of the package, given dimensions d1 and d2?

According to this view, 54 cigarettes would fit.

(all as seen from above!)

But this is an upperbound. Take D = 1 and d1 = d2 = 1.4.

The formula now gives 2, but only one fits.

And of course, we have the requirements:

d1 >= D AND d2 >= D, otherwise no cigarette will fit.

Greetz,

Piet

Just look at one of the examples given in the opening post.

When D = 2, d1 = 10 and d2 = 17, then, according to the

answer given, 40 cigarettes fit. So it is not necessary to

go the complex honeycomb way, that Fred was also hinting

at. So, to OP, look at Junilu's first reply. That's how to proceed.

/********************************/

However, as an easy to calculate upperbound for the number:

what, given a diameter D, is the area of a cigarette, and

what is the area of the package, given dimensions d1 and d2?

According to this view, 54 cigarettes would fit.

(all as seen from above!)

But this is an upperbound. Take D = 1 and d1 = d2 = 1.4.

The formula now gives 2, but only one fits.

And of course, we have the requirements:

d1 >= D AND d2 >= D, otherwise no cigarette will fit.

Greetz,

Piet

posted 2 years ago

That was my thought too.

Oddly enough, manufacturers (at least I assume it was them) came up with a very neat solution to one of the tax hikes on tobacco in Belgium by reducing the number of cigarettes in a pack from 20 to 19, presumably so they could still sell them for the same price. All they needed to do was change the configuration from 7-6-7 (20) to 6-7-6 (19), and everything else - in particular, package size - remained the same.

Stupid piece of trivia for you .... and, of course it only works

Winston

Junilu Lacar wrote:I don't know if you are supposed to consider the fact that cigarettes can be arranged in honeycomb pattern in a pack.

That was my thought too.

Oddly enough, manufacturers (at least I assume it was them) came up with a very neat solution to one of the tax hikes on tobacco in Belgium by reducing the number of cigarettes in a pack from 20 to 19, presumably so they could still sell them for the same price. All they needed to do was change the configuration from 7-6-7 (20) to 6-7-6 (19), and everything else - in particular, package size - remained the same.

Stupid piece of trivia for you .... and, of course it only works

*once*.

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

mark patindol

Greenhorn

Posts: 23

posted 2 years ago

thanks i got it know. but the output of my program is always 0 i think i have a wrong code.

Junilu Lacar wrote:mark patindol wrote:the No.1 example on my work is easy to understand. just multiply the dimension1 which is 2 and dimension 2 which is 4. then multiply on the diameter which is 1. so that the maximum number of cigarettes can be put on the pack is 8.

But if my diameter is 2 i really have a hard time to get it. sorry

How many 2s are there in 4? How many 2s are there in 6? How many 2s are there in 7? Those are very simple calculations that involve a basic arithmetic operation.

thanks i got it know. but the output of my program is always 0 i think i have a wrong code.

123.png

Mark King

Ranch Hand

Posts: 55

posted 2 years ago

What is this line supposed to do?

What's more is that you are both multiplying and dividing dimensionOne, the result of that is that the multiplying and division cancel each other out, so what you are effectively left with is:

In your example dimensionTwo is greater than diameter, therefore due to the way java handles integer division you will get 0.

Also for next time copy and paste your code into your post, just use code tags, or hit the code button on top to automatically create code tags.

What's more is that you are both multiplying and dividing dimensionOne, the result of that is that the multiplying and division cancel each other out, so what you are effectively left with is:

In your example dimensionTwo is greater than diameter, therefore due to the way java handles integer division you will get 0.

Also for next time copy and paste your code into your post, just use code tags, or hit the code button on top to automatically create code tags.

It is sorta covered in the JavaRanch Style Guide. |