Friday, March 30, 2007

a puzzle about minimum number of weights required, and how i by chance found its solution

it was a very boring class going on, and so my friend sitting next to me on the desk gave me a puzzle. what minimum number of weights does one need to be able to make measurements upto 100 kg [assuming a least count of 1 kg], and tell those weights too. i have heard/read this problem before, but i had not read or thought about its solution.

my strategy, which i by chance got somehow, was this.

-to measure any weight, we need to build it up
-to build up a weight, there are 3 methods
  1. a direct weight of its measurement. example to measure 2 kg, we have a weight that weighs 2 kg
  2. additive weight- i.e. a weight produced by adding 2 or more available direct weights. example to measure 2 kg, i add 2 available 1 kg weights
  3. subtractive weight- i.e. a weight produced by subtracting 2 [or more- in some combinations] available direct weights. example to produce 2 kg, subtract 3 from 5.
having formed this strategy, the simple task was now to implement it on the whole length of integers from 1 to 100.

here's the digest

-for 1 kg- 1st option is mandatory, unless we want to deliberately use a less efficient combination. hence 1 kg weight is mandatory

-for 2 kg, although all 3 methods can be used, subtractive approach looks like the most efficient, since for subtraction we would necessarily have to have a highest possible weight [from which an already present direct weight- 1 kg in this case- would be subtracted]. not only would this highest weight itself serve us till its own magnitude, but by adding it to already available weight rather than subtracting that from it, we would be able to achieve higher weights. a simple way to calculate the magnitude of this subtractive weight is to add the sum total of already available weights to the value we want to form. example 1 kg is available as direct weight. we want to form 2 kg value. so add 1 [already available] to 2 [value we want to form] and thus we need 3 kg weight. with 1 and 3, not only can we form 2 by subtraction, but we can also form 4 by addition. had we chosen to have 2 kg direct weight so as to be able to form 3 kg by addition, we would not have been able to form 4 kg, and also there would have been a redundant combination- subtracting 1 from 2 to achieve 1- which we already have in form of 1 kg direct weight. with 1 and 3 there is no redundant combination. and hence it is most efficient. so far till 4 kg.

-for 5, again we need to add 1+3+5= 9. we can achieve 5,6,7,8,9,10,11.....13 with this

-14- add 1+3+9+14= 27. values up to 40 possible.

-41- we need 81 as per above algorithm.

-with 81 available, we can calculate any value till 121. so there are 21 redundant values here.

i will someday try to find out a way to calculate precisely till 100, and not till 121, since any unnecessarily heavy weight will cause unnecessary cost increase- since metal is obviously used in creating these weights. anyways, i am happy that a nice strategy by chance came to my mind the moment he put his puzzle.

how i think one can cool a room in a college's hostel with no cooler or air conditioner

its getting hotter in india, and especially here in delhi. i am on the 3rd floor of my hostel, and naturally its hotter here than it would be at the ground floor.

my room is approximately 6 meter x 6 meter x 8 meter [l x b/w x h]. only a ceiling fan on top and a fluorescent tube light. the ambient temperature here should be about 34 degree celsius [i have no thermometer with me here, but to find out the ambient temperature, i put my laptop to standby mode, and then after 2 hours- to give it time to cool to ambient temperature- i resumed it from standby mode. immediately i checked the hard disk temperature in hddlife program, which showed me 35 degree celsius. i compensated for slight increase in temperature during resuming by 1 degree, and so 34 should be a very accurate calculation. here in india we call such a method an intelligent jugaad :-)].

anyways, this is uncomfortable. my friend too cribbed about it, and i suggested him something that came to my mind all of a sudden. why not fill a bucket with cold water [from the water cooler in my hostel]. the water's temperature should be at most 13-14 degrees celsius, and thus there is a good difference of about 20 degrees between water and room air.

put this big bucket in room, and let its water absorb heat. water has high specific heat, and according to newton's law of cooling, the temperature difference will ensure rapid heat absorption. i dont know whether this method will indeed be effective in making the room temperature just comfortable, or less uncomfortable at least. i think it should work, after all whatever heat is absorbed by water, its obviously reducing temperature of room. but any reduction in room temperature will also cause heat from outside room to flow in. nevertheless, there should be some benefit of this no-cost method.

if it doesnt work satisfactorily, i simply gonna take that bucket, turn it around over my head and drench myself with cold water to mar the heat.

Monday, March 26, 2007

windows xp's management of thumbs.db has a potential privacy threat

i found this out of curiosity. actually a thought came to my mind minutes back that does windows explorer delete thumbnails of those images which have been deleted from a folder, from thumbs.db too? it turns out that it doesn't.

i put 10 images in a folder

then i switched the folder to thumbnails view and this generated thumbs.db

its sha-1 hash is- E7CB4A8AA45C9CF0E64720AC670EEBFBE34FA6E4

then i removed 3 images from the folder and refreshed and re-entered the folder but thumbs.db's sha-1 hash continued to be- E7CB4A8AA45C9CF0E64720AC670EEBFBE34FA6E4

this confirms that windows xp does not delete redundant data in thumbs.db

i think this is not good engineering. a company which so vehemently emphasizes on its product being secure and responsible when it comes to privacy shouldn't take this issue lightly. its easy for image viewers like irfanview, xnview, or farstone viewer to implement reading thumbs.db and/or extracting thumbnails from it. remnants of deleted images can cause situations akin to those caused by browser's history, or by files that have been deleted, but shortcuts to whom remain in the 'recent' folder [in this case, the filename and file type is the only available data, along with date and time of the shortcut of course].

one good thing windows explorer does is to update thumbnails of those images which have same name as some previously present image in the folder, which had same filename as a newly added image. but in this case too, as i found out, if i modify the image's size and modification date time etc to match that of old image [assuming dimensions etc are all identical], windows explorer does not update the thumbnail. it is not programmed to check if a newly added image with filename and date/time same as a previously added image is different from it. this is not needed too since the probability of a newly added image being of same size and with same specifications and same size/date etc is zero for all practical purposes.

Wednesday, March 14, 2007

The magnitude of a Gigabyte (Gibibyte actually)

Today a friend of mine told me that good quality blank DVDs are now available for 11 Rupees (approximately 0.25 US $- down from about 15 rupees). I just smiled in surprise. Approximately 4.4 GiB of digital information can be stored for just 11 rupees now. That is about 4 Paisa per MiB. An intriguing fact is that standard floppy disks with 1.44 MB capacity are still available for 10 rupees.

As a reminder to myself of the huge amount of information that 1 GiB represents, I thought this. Consider a man with life span of 80 years. The number of seconds in his life are

80*365*24*3600 + 20*24*3600= 2522880000 + 1728000= 2524608000

1 GiB has 1073741824 bytes.

So if this man were to dictate the decoded (assume binary to decimal) form of each byte at the rate of 1 byte per second, he would manage to dictate only about 2.35 GiB in his entire lifetime, assuming he never sleeps, never eats and just keeps dictating 1 byte per second. And that is just about half of a DVD. An 11 rupee DVD.