Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site dartvax.UUCP Path: utzoo!linus!decvax!dartvax!andyb From: andyb@dartvax.UUCP (Andy Behrens) Newsgroups: net.bizarre Subject: Re: Bizarre Code Message-ID: <3487@dartvax.UUCP> Date: Thu, 15-Aug-85 10:45:13 EDT Article-I.D.: dartvax.3487 Posted: Thu Aug 15 10:45:13 1985 Date-Received: Tue, 20-Aug-85 01:02:42 EDT References: <462@moncol.UUCP> Organization: Dartmouth College, Hanover, NH Lines: 30 > What is the most bizarre line/piece of code you have seen in a production > program? I haven't seen it personally, but here's an example from Kernighan and Plauger's "Elements of Programming Style": DO 14 I = 1,N DO 14 J = 1,N 14 V(I,J) = (I/J)*(J/I) Their comment on this fragment is "A modest familiarity with Fortran tells us that this doubly nested DO loop assigns something to each element of an N by N matrix V. What are the values assigned? I and J are positive integer variables and, in Fortran, integer division truncates toward zero. Thus when I is less than J, (I/J) is zero; conversely, when J is less than I, (J/I) is zero. When I equals J, both factors are one. So (I/J)*(J/I) is one if and only if I equals J; otherwise it is zero. The program fragment puts ones on the diagonal of V and zeros everywhere else. (V becomes an identity matrix.) How clever! "Or is it?" Andy Behrens {astrovax,decvax,cornell,ihnp4,linus}!dartvax!andyb.UUCP andyb@dartmouth.CSNET andyb%dartmouth@csnet-relay.ARPA