Subj : Re: puzzle To : comp.programming From : spinoza1111 Date : Fri Jul 01 2005 03:58 am karen wrote: > wrote in message > news:1119341868.873117.107560@g44g2000cwa.googlegroups.com... > > > > > > Mike wrote: > >> In article <1119253085.10946.3.camel@gamow.sci.kun.nl>, > >> C.Dams@science.ru.nl says... > >> > On Mon, 2005-06-20 at 00:13 -0700, spinoza1111@yahoo.com wrote: > >> > > >> > >> function ReturnOddElement(A : array of integer) : integer; > >> var > >> p : integer; > >> i : integer; > >> begin > >> p := 1; > >> for i := Low(A) to High(A) do > >> if (p mod A[i]) = 0 > >> then > >> p := p div A[i] > >> else > >> p := p * A[i]; > >> result := p; > >> end; > >> > >> This requires no bitwise operations and will be O(n) on any > >> system on which MaxInt is sufficiently large. > > > > STILL fails to work for floating point systems because in FP systems > > there can be >1 bitwise representation of the same n. > > > > Never mind the validity of the code. Do you recall the original specs? > > ok here is a puzzle. > there is an integer array whose length is odd, and all the numbers in > the array appear exactly two times except one. Find the number in O(n) > time. Try to do it without using any other data structure. > > Note that word "INTEGER". It doesn't HAVE to work for floating point > systems! Real programming is not a matter of solutions isomorphic to problems, and responding to one problem as expressed "today" with a solution tuned to that problem. Instead, the real programmer recognizes, as an aura around the user's expression of the problem, a genuine class of problems to which today's problem will evolve. He thus eschews solutions which are overly tuned, in a trickster fashion, to one empirical property of the problem such as "integers". Now, I realize this is Martian in a world in which actual, as opposed to real, programmers whine about the user's lack of specificity and the way the "user" changes the problem...a world in which programmers consistently play the Child in relation to the Parent figure of the user. Nonetheless, real, as opposed to actual programming continues to minimize assumptions and regards the Xor solution as just that sort of stunt that creates, in the real, as well as actual, world, creates Bad Code. Conducting itself as an Adult in relation to the user's Adult, real programming insists on joining the user and in many cases seeing further. In the real world, integers do indeed become real numbers, most famously in the conceptual revolution in "rocket science" finance when programmers realized that better financial models could be built using real numbers and not fixed-point dollars and cents numbers, a form of integer. Now, all this is perhaps "sour grapes" because I failed, as I have mentioned, to recollect how my prof in graduate school, more than 20 years ago, mentioned XOR stunts. But from sour grapes we can make fine wine, as well as whine, and here I propose that a sort of slack-jawed empiricism is that which insists that there is but one answer which pleases the Parent, and has made, in my experience, vicious children out of a generation of post-C programmers. But I do note that every time a member of my generation attempts to "grow up" in the sense of actually evolving alternatives, he becomes a marginal and suspicious figure, which is what I am content to be. The alternatives here are to unimaginative data systems, just chock full of multiple clever tricks, which contain no vision of how the problem might evolve. In a word, then, nyahh nyahh, so's your old man, and you and Hoover and Bush are dumb bastids. With which I think I shall end my participation in this thread. > > -karen .