Subj : Re: puzzle To : comp.programming From : Gerry Quinn Date : Fri Jul 01 2005 08:22 pm In article , cbarber@curl.com says... > spinoza1111@yahoo.com wrote: > > He thus eschews solutions which are overly tuned, in a trickster > > fashion, to one empirical property of the problem such as "integers". > > I don't see how "integers" is an empirical property of a problem. No > experimentation was needed. The problem stated the data type. In > the real programming world, you usually know the data types of your > input in advance. You also neglect that the more significant limitiation to > the problem definition is not that it specified integers but that it specified > that each value appears exactly twice except for one unique value, this latter > property seems much more strange than limiting the data set to integers. Furthermore, the properties of XOR are not relevant only to integers. Indeed, the set of datatypes for which its properties are useful is larger than the set of numbers. A use which almost everyone will be familiar with is in graphics. An efficient way to draw an moving outline - such as the new size of a window or the region where an object is to be placed - on a typical memory-mapped display is to XOR the pixel data of the region to be outlined with a value that has all bits set, then XOR with that value again to restore the original pixel data. Depending on the display system, the results may be varied, but all but extraordinary circumstances you will get a visible line, and it's fast. With PC hardware nowadays it's not needed, but it was used on Windows until quite recent versions, and is probably still in use in many systems. Observe, incidentally, that this will work even if the pixel data is in the form of floating point numbers! The reason XOR might not work on a floating point version of the puzzle discussed here might in fact be considered an empirical property or quirk of the floating point equality operator and/or the floating point arithmetic system, rather than XOR. The operator considers two numbers equal when their representation is different, because the arithmetic system represents the same number in different ways when it feels like it. Surely *that's* something of an empirical fact about how computer software/hardware works? - Gerry Quinn .