[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

21.0. "Betty Crocker" by PSYCHE::MCVAY () Sat May 05 1984 13:03

 Okay -- I have a hacking request to get this file going:

 Over the years I have accumulated a number of nice-to-have routines that
I keep in a small book.  Wheneven I need a fast sort algorithm or something,
I pull this book out and throw in the code.  With the advent of more and
more library utilities, this doesn't become as necessary, but the need is
still there on occasion.

 I need some good, small cookbook algorithms for the following:

1. Day of week, preferrably by Zeller's congruence.  [I KNOW there are
   a lot of routines out there--every one I've ever tried had a bug!
   I'd like a good one, please!]

2. LIB$TPARSE, but on a small scale: say, a good routine for slicing
   through known states in a hurry, with a few simple terminators.

When I get around to it, I will add a couple of my own routines to this
file, starting with a couple of simple sorts, an elegant but simple
command line parser, and a non-repetitive random order generator (such
as shuffling a pack of cards).
T.RTitleUserPersonal
Name
DateLines
21.1HERMES::MARTINSat May 05 1984 23:5117
Day of the week is easy when the date is expressed in the "Universal Date
Time Standard" that Tops-10/20 use.  November 18th, 1858 is day 1, and the
number is incremented by 1 each day.  My Popular Science Perpetual Calendar
and Bookmark says that Day 1 was a Thursday, so you take the day number, and
Wednesday is 0 MOD 7.  Since there was a reference to screwed up NOTES files
having a date in 1858 a few notes back, I assume the same thing is available
on VMS.  This is worthy of mention in a hacker file, because I discovered
the data-of-the-week trick by reading some hacker's code that used it.  The
program actually added 4 to the date number before dividing by 7, because
then it could test for weekends by (date

Damned ^W
((date+4) MOD 7) AND %O'6' EQL 0.

I was reading the code with DDT at the time, because I was probing a .SAV
file, with no sources available.  So that counts as hacking too.
				/AHM
21.2ACE::BREWERMon May 07 1984 20:597
I'll send you a file that I use to keep track of the backups I do on 
my 750 system. It is useful in that I turn off the .com file on weekends
as a backup is not (normally) needed then...

I didnt write it ... I copped it off another machine.

	-John
21.3ORPHAN::BRETTFri May 11 1984 15:456
ZELLER's congruence is totally unnec. on VMS - just get the system quadword
time, do an EDIV to get the #days since day 0, and then a plus followed by
a mod to get the day of the week...

/Bevin
21.4MARVIN::ISBELLTue May 15 1984 14:078
I have a little FORTRAN program I wrote at college which uses Zeller's 
whatsit to produce a calendar for any year. There is no checking 
performed on the year requested, and no compensation for the calendar 
change. Send me mail if you are interested in a copy. (This program also 
contains an example of a hack to get the output format correct, which 
could not be done with the FORTRAN I/O on the college system.)

			Chris.
21.5HARE::STANMon May 21 1984 22:356
Come on guys - this file is for hackers.

If your calendar program doesn't print out the phases of the moon
then you're not hacking; you're just writing useful code.
Perhaps there should be another notes file somewhere for people
to file away useful code fragments.
21.6REX::MINOWTue May 22 1984 17:4866
! Moon.tec puts the phase of the moon at the end of the text buffer	!
! Programmed by Martin Minow.   The algorithm is taken from Knuth's	!
! The Art of Computer Programming, vol. 1.  See also CACM Apr 63	!
!									!
! The macro is loaded into Q register P					!
! Internal Q register usage:						!
!	T	Temporary storage of radix flag, etc.			!
!	Y,M,D	Year, month, day					!
!	C,G	Century and Golden number (Moon's 19 year cycle		!
!	E	Epact (age of the moon on Jan. 1)			!
!									!
! Note: this routine is intentionally rather crude.			!

@^UP%
  [T [Y [M [D [C [G [E 10UT ^D  ! Save registers and radix		!
  ^BUD                          ! Get operating system date		!

! RSX-specific code, get QY=year, QM=month, QD=day			!
  QD/512UY QD-(QY*512)UD QD/32UM QD-(QM*32)UD QY+1900UY

! Calculate EPACT							!
  QY/100+1UC                    ! Century, 1900 = 20			!
  QY-(QY/19*19)+1UG             ! Mentonic cycle "golden" number	!
  QG*11+20+(8*QC+5/25-5)-(3*QC/4-12)UE  QE-(QE/30*30)UE ! Epact		!
  QE-25"E QG-11"G QE+1UE ' '
  QE-24"E         QE+1UE '      ! QE now has moon age on Jan 1.		!

! Calculate the day in the year						!
  QM-02"E QD+031UD '
  QM-03"E QD+059UD '
  QM-04"E QD+090UD '
  QM-05"E QD+120UD '
  QM-06"E QD+151UD '
  QM-07"E QD+181UD '
  QM-08"E QD+212UD '
  QM-09"E QD+242UD '
  QM-10"E QD+273UD '
  QM-11"E QD+304UD '
  QM-12"E QD+334UD '  

  QM-2"G                                ! Leap year correction needed?	!
    QY-(QY/4*4)"E                       ! Maybe, is it one in 4?	!
      QY-(QY/100*100)"N QD+1UD '        ! Yes, leap it if not / 100	!
      QY-(QY/400*400)"E QD+1UD '        ! Or if it's divisible by 400	!
  ' '

! Calculate phase of the moon and load the text				!
! Note:  The moon's period is 29.5 days, thus				!
!	177	= (29.5 * 6)						!
!	 22	= (29.5 / 8) * 6					!
!	 11	= 22 / 2						!
  QD+QE-1*6+11UD QD-(QD/177*177)/22&7UD ! QD has the phase (0 - 7)	!
  ZJ
  QD-0"E @I/new/ '
  QD-1"E @I/waxing crescent/ '
  QD-2"E @I/in the first quarter/ '
  QD-3"E @I/waxing gibbous/ '
  QD-4"E @I/full/ '
  QD-5"E @I/waning gibbous/ '
  QD-6"E @I/in the last quarter/ '
  QD-7"E @I/waning crescent/ '

! Finish up								!
  10-QT"N ^O ' ]E ]G ]C ]D ]M ]Y ]T
% @^A/MOON.TEC now loaded into Q register P
/<ESC><ESC>
21.7NACHO::CONLIFFETue May 22 1984 18:361
I love it!!!   And in TECO, too.. My favorite programming language!
21.8HUMAN::BURROWSWed May 23 1984 11:232
OK, martin, are you going to regale us with the tale of your phase of the moon
bug?
21.9REX::MINOWWed May 23 1984 23:2516
fixed in .7

(The phase of the moon program had a phase of the moon bug that
caused the phase to go to 8 on the equinox full moon, which happens
twice a year.  Wherefor the mask by 7).

Blame Knuth, it's his algorithm.

If you have strong stomach, search out the reference Knuth gives
for the Easter program in Volume 1.  (CACM 1963, if I recall
correctly.  He wrote that date of Easter program in Cobol.)

Then, again, I've written an Ansi Standard Escape Sequence Parser
in Microsoft Basic.

M.
21.11TURTLE::COWANFri May 25 1984 12:2014
	I'm glad to see there are other TECO hackers out there.  Come
to think of it, TECO must be the oldest unsupported progamming language
in the company, eh?  Yes, yes, I know it is now supported under VMS V-whatever.

	I used to work for a company that cycled large amounts of data
through their machine.  Frequently, we came accross freak data entry 
aids that were needed.  Real people would have hired data entry help,
but my company preferred magic-- a la TECO.  To you and I, it wasn't
real magic, it was just simple TECO complicated slightly to deal 
with buffers that stopped at bad place.  Consquently (see, they
did teach me something in college), I'll not ramble further.

Cheers, KC
21.12MARVIN::ISBELLMon Jun 04 1984 16:1910
The REAL TECO hack was RT-11 EDIT. This, as far as I can gather, is TECO 
without all the nice bits. It had the effect of turning me totally off 
TECO. On many occasions I entered a command string ending with an insert 
of a number of lines. If there was some trivial error in the commands, 
all the inserted text was lost. 

Any editor which requires the escape key as a command terminator, and is
character orientated produces a strong conditioned reaction of aversion.

			Chris.
21.13LATOUR::KKLEINERTue Jun 05 1984 12:113
.0, .5 - When such a notes file is started (oh no, not another one!) perhaps
	it should be called HAKMEM.NOT (see #24.0).
21.14NY1MM::MUSLINFri Jun 29 1984 00:095
Re: .5

	"Useful code," what's that?

				-\- Victor -/-
21.15NY1MM::MUSLINFri Jun 29 1984 00:266
	Somewhere I have a state machine parser that goes through a table of 
allowed/unallowed states. The only use it has is to prove to a friend of mine 
(a TOPS-20 specialist in the office) that VAX can simulate TOPS' %CMND jsys
(it also tries to simulate CLI - why do only one thing, right?)

					-\- Victor -/-
21.16Vaxuum::DYERFri Jun 29 1984 20:162
	I believe Stan's done a good job simulating the %CMND jsys...
		<_Jym_>