435,098 Members | 2,007 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

FINDING OUT WHAT'S LEFT

 P: n/a I have a scenario where I have these things that take up (x) number of space. I know the max number of space I will ever have is 512. I am trying to figure out a way to write a formula or whatever will make it work to tell me how many of these things I can put in this space. So example I want to put 60 of these thing that take up (21) units each. Well given that I cannot go over 512 the max I am able to put in any one space is 29. I did the math to do that, but what sort of formula am I looking for to do this. I want to know how many of these things I can fit and what the next available number for space is. I have in the worksheet a cell that contains the number of units each different thing takes up because it varies. Thank you for any help. Matt Sep 12 '07 #1
4 Replies

 P: n/a On Sep 12, 3:38 pm, mattG

 P: n/a On Sep 12, 4:38 pm, mattG I want to know how many of these things I can fit and what the next available number for space is. I have in the worksheet a cell that contains the number of units each different thing takes up because it varies. Look at integer division and mod operators. int MaxSpace = 512; int SpacePerItem = 21; int itemCount = MaxSpace / SpacePerItem; int spaceLeftOver = MaxSpace % SpacePerItem; Sep 12 '07 #3

 P: n/a mattG wrote: I have a scenario where I have these things that take up (x) number of space. I know the max number of space I will ever have is 512. I am trying to figure out a way to write a formula or whatever will make it work to tell me how many of these things I can put in this space. So example I want to put 60 of these thing that take up (21) units each. Well given that I cannot go over 512 the max I am able to put in any one space is 29. I did the math to do that, but what sort of formula am I looking for to do this. What math did you do to figure out the 29, and what aspect of it are you finding difficult to translate into code? Are you sure you didn't come up with 24, but then mis-read your handwriting as 29 instead? You should be able to do a plain integer division (ie, no fraction, decimal, remainder, etc.) to arrive at the correct number. When I do the math, I actually get 24 "things" that are 21 units large in a space that is 512 units large. The code is simple -- "int count = 512 / dxThingWidth" -- but telling you that might not give you the tools you need to derive a similar line of code in the future. If you can explain why you weren't able to translate the math you did into a line of code like that, that could help you better understand how to do it successfully in the future (for that matter, the act of explaining it may be sufficient for you to have that "aha!" moment yourself). Pete Sep 12 '07 #4

 P: n/a "mattG" I have a scenario where I have these things that take up (x) number of space. I know the max number of space I will ever have is 512. I am trying to figure out a way to write a formula or whatever will make it work to tell me how many of these things I can put in this space. So example I want to put 60 of these thing that take up (21) units each. Well given that I cannot go over 512 the max I am able to put in any one space is 29. I did the math to do that, but what sort of formula am I looking for to do this. I want to know how many of these things I can fit and what the next available number for space is. I have in the worksheet a cell that contains the number of units each different thing takes up because it varies. Thank you for any help. Matt This is pretty simple if you think about it. If you have x objects that take up y units then that is a total of x*y units taken up... or x + x + x + x + ... + x where there are y x's in the sum. To make this concrete, suppose you have 10 dollar bills and each dollar bill is 4 quarter(or represents 4 units where are unit is the quarder), then 10 dollar bills * [4 quarters / 1 dollar bill] = 40 quarters. notice that I used dimensional analysis here. What this means is that I treat the "dimension"(this case its dollars and quarters) which represents what type of object the number is as sorta its own "number" that can be used like a number. That probably doesn't make sense but realize that 4 quarters / 1 dollar bill = 1 because 4 quarters = 1 dollar bill. (dividing both sides by the same amount is a valid mathematical operation) So essnetially what I did was start with 10 dollar bills = 10 dollar bills * 1 (multiplying by 1 doesn't change it) but now I used 4 quarters / 1 dollar bill = 1 to get 10 dollar bills * [4 quarters / 1 dollar bill] but then the dollar bill(s) cancel each other because have something like 10 * x * 4 * y / x = 10*4*y. Which results in 40 quarters. What that means is that 10 dollar bills = 40 quarters. ---------- Thats kinda a long explination but hopefully you understand it. (trying to make it very simple so you can learn how to do this yourself) If your a computer guy and know about bits and bytes you can do the same, 1000 bytes * [8 bits / byte] = 8000 bits i.e., 1000 bytes is the same as 8000 bits. ----------- Your problem is the exact same but a different perspective x objects * [y space / object] = x*y space [for x objects] i.e., x objects is the number of objects we are talking about y space / object or y space / one object is the space taken by one object, which is y. The we multiply them and the units cancel and we are left with the total space. ----- For your specific problem its 60*21 = 1260 units of space. (I left out the units in the product but I know they are implicitly there) Now if you have a max of 512 then you went over. By how much? Well, its simple, we are looking for how many objects we can put into 512 because that would be our max. i.e., x * 21 = 512. This gives us x = 24.123... but since x has to be an integer(because we can't have partial objects), it means that we can have a max of 24 units. Notice that x = 512/21... but you can generalize this to be "Max space"/"Size of one object". Since you have 60 objects and 24 was the max then you are over by 60 - 24 = 36. You can replace numbers with variables to make the equations more abstract but more useful. If you don't know algebra then its about time to start because this is what algebra is all about. Sep 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion. 