• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
mark patindol
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Cooke
Marshal
Posts: 4039
239
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if you are supposed to consider the fact that cigarettes can be arranged in honeycomb pattern in a pack.
 
Piet Souris
Master Rancher
Posts: 2041
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
[Thumbnail for 123.png]
This is my code and the output is always 0 :( sorry im 1st year student haha
 
Mark King
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!