Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# I just need the formula. How many cigarettes that can be put inside the pack.

Greenhorn
Posts: 23
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.

Marshal
Posts: 4352
280
• 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.

Bartender
Posts: 3648
16
• 1
Welcome to the Ranch.

I'm not giving you the "formula". It looks like homework.

What do the 2 dimensions represent? imagine you have such a box will make it much simpler.

mark patindol
Greenhorn
Posts: 23
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

lowercase baba
Bartender
Posts: 12613
50
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?

Sheriff
Posts: 11745
191
• 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.

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

Rancher
Posts: 2454
80
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

Bartender
Posts: 10575
66

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

mark patindol
Greenhorn
Posts: 23

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

Ranch Hand
Posts: 55
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.