HAKMEM
HAKMEM
(publication)Item 41 (Gene Salamin): There are exactly 23,000 prime numbersless than 2^18.
Item 46 (Rich Schroeppel): The most *probable* suitdistribution in bridge hands is 4-4-3-2, as compared to4-3-3-3, which is the most *evenly* distributed. This isbecause the world likes to have unequal numbers: athermodynamic effect saying things will not be in the state oflowest energy, but in the state of lowest disordered energy.
Item 81 (Rich Schroeppel): Count the magic squares of order 5(that is, all the 5-by-5 arrangements of the numbers from 1 to25 such that all rows, columns, and diagonals add up to thesame number). There are about 320 million, not counting thosethat differ only by rotation and reflection.
Item 154 (Bill Gosper): The myth that any given programminglanguage is machine independent is easily exploded bycomputing the sum of powers of 2. If the result loops withperiod = 1 with sign +, you are on a sign-magnitude machine.If the result loops with period = 1 at -1, you are on atwos-complement machine. If the result loops with periodgreater than 1, including the beginning, you are on aones-complement machine. If the result loops with periodgreater than 1, not including the beginning, your machineisn't binary - the pattern should tell you the base. If yourun out of memory, you are on a string or bignum system. Ifarithmetic overflow is a fatal error, some fascist pig with aread-only mind is trying to enforce machine independence. Butthe very ability to trap overflow is machine dependent. Bythis strategy, consider the universe, or, more precisely,algebra: Let X = the sum of many powers of 2 = ...111111 (base2). Now add X to itself: X + X = ...111110. Thus, 2X = X -1, so X = -1. Therefore algebra is run on a machine (theuniverse) that is two's-complement.
Item 174 (Bill Gosper and Stuart Nelson): 21963283741 is theonly number such that if you represent it on the PDP-10 asboth an integer and a floating-point number, the bitpatterns of the two representations are identical.
Item 176 (Gosper): The "banana phenomenon" was encounteredwhen processing a character string by taking the last 3letters typed out, searching for a random occurrence of thatsequence in the text, taking the letter following thatoccurrence, typing it out, and iterating. This ensures thatevery 4-letter string output occurs in the original. Theprogram typed BANANANANANANANA.... We note an ambiguity inthe phrase, "the Nth occurrence of." In one sense, there arefive 00's in 0000000000; in another, there are nine. Theediting program TECO finds five. Thus it finds only the firstANA in BANANA, and is thus obligated to type N next. ByMurphy's Law, there is but one NAN, thus forcing A, and thus aloop. An option to find overlapped instances would be useful,although it would require backing up N - 1 characters beforeseeking the next N-character string.
Note: This last item refers to a Dissociated Pressimplementation. See also banana problem.
HAKMEM also contains some rather more complicated mathematicaland technical items, but these examples show some of its funflavour.
HAKMEM is available from MIT Publications as a TIFF file.
ftp://ftp.netcom.com/pub/hb/hbaker.