Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Data Structures Message-ID: <1088.UUL1.3#5129@willett.UUCP> Date: 6 Jun 90 03:55:00 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 94 Category 3, Topic 20 Message 97 Tue Jun 05, 1990 W.BADEN1 [Wil] at 20:39 PDT At last Thursday's Fig Bar I promised two algorithms for calculating the date of Easter. I gave the first the same night. I said that the other used UM/MOD ten times. This is from T.H.O'Beirne's (That's O'BEIRNE) delightful PUZZLES AND PARADOXES, Oxford Univ. Press, 1965, chapter titled "Ten Divisions Lead to Easter." My son programmed this for my Apple F83X some years ago, but rather than excavating the code (I don't know where in California it is) or reproducing O'Beirne's description, here is an executible program in ABC. HOW TO DIVIDE dividend BY divisor GIVING quotient WITH remainder REMAINDER PUT floor(dividend/divisor),dividend mod divisor IN quotient, remainder HOW TO EASTER x: \ Display month and day of Easter Sunday, Gregorian year x. DIVIDE x BY 19 GIVING junk WITH a REMAINDER DIVIDE x BY 100 GIVING b WITH c REMAINDER DIVIDE b BY 4 GIVING d WITH f REMAINDER DIVIDE 8*b + 13 BY 25 GIVING g WITH junk REMAINDER DIVIDE 19*a + b - d - g + 15 BY 30 GIVING junk WITH h REMAINDER DIVIDE a + 11*h BY 319 GIVING mu WITH junk REMAINDER DIVIDE c BY 4 GIVING i WITH k REMAINDER DIVIDE 2*f + 2*i - k - h + mu + 32 BY 7 GIVING junk WITH lambda REMAINDER DIVIDE h - mu + lambda + 90 BY 25 GIVING n WITH junk REMAINDER DIVIDE h - mu + lambda + n + 19 BY 32 GIVING junk WITH p REMAINDER WRITE {[3]: "March"; [4]: "April"}[n], p This seems wordy, but after you define a new keyword the system prompts you with suggestions. E.g., When you start a line with "d", ABC echoes "D?ELETE ?" on top of your typing. If you continue with "i" it suggests "DI?VIDE ? BY ? GIVING ? WITH ? REMAINDER". You can write over the suggestion or use tab to copy up to the next hole, given by "?". Notice that you do not have to shift case. Here are some "how-to's" for stack manipulation. HOW TO EMPTY stack \ Also used to make stack. PUT {} IN stack HOW TO PUSH x ONTO stack PUT x IN stack[#stack+1] HOW TO RETURN top stack RETURN stack[#stack] HOW TO SWAP stack PUT stack[#stack], stack[#stack-1] IN stack[#stack-1], stack[#stack] HOW TO DROP stack DELETE stack[#stack] HOW TO DUP stack PUSH top stack ONTO stack HOW TO OVER stack PUSH 1 th'on stack ONTO stack HOW TO RETURN n th'on stack RETURN stack[#stack - n] Here is the clearest expression of The Sieve I've seen. HOW TO SIEVE n \ Sieve of Eratosthenes. (Not a benchmark.) SHARE primes PUT {2..n} IN primes PUT 2 IN prime PUT floor root n IN limit WHILE prime <= limit: PUT prime IN i WHILE i < max primes: PUT i + prime IN i IF i in primes: REMOVE i FROM primes PUT prime min primes IN prime WRITE "There are `#primes` primes <= `n`." "SHARE primes" makes primes available globally. Text files are treated as named tables with line number as the key and text as the value of the key, so no I/O instructions are needed to manage them. There is a built-in editor for all named data: numbers, strings, compounds, lists, and tables. Procedamus in pace. Wil. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu