perm filename LUCKY.MAC[B,PMP] blob sn#059331 filedate 1973-08-16 generic text, type T, neo UTF8
	TITLE	LUCKY - MANY LUCKY NUMBERS
	P=12
	S=13
	T=14
	U=15
	LEN=20000
BEGIN:	MOVE	P,[-LEN,,0]
	SETOM	START(P)
	AOBJN	P,.-1
	MOVE	P,[LOOP,,0]	;GET BLT POINTER FOR SUBROUTINE
	BLT	P,11		;MOVE SUBROUTINE INTO ACS
	MOVEI	T,1
	MOVEM	T,STPCTR
	MOVE	T,[-LEN,,0]
	MOVEM	T,STPPTR
	JRST	.+3
NEWSTP:	JOV	.+2		;SKIP IF CHANGED ANYTHING IN LOOP
	JRST	FINISH		;NOTHING WAS CHANGED, SO FINISH UP
	MOVE	P,STPPTR	;GET STEP POINTER
	MOVE	T,START(P)	;  AND WORD IN STRING WITH STEP BIT
	AOS	U,STPCTR
	LSH	T,(U)		;SHIFT SO DON'T CONSIDER PREVIOUS BITS
	JFFO	T,.+3		;SKIP IF NEXT STEP BIT FOUND
	SETZM	STPCTR		;ADVANCE TO NEXT WORD IN STRING
	AOBJN	P,.-4		;LOOP FOR NEW STEP BIT
	ADDB	U,STPCTR	;ADD PLACE IN THIS WORD TO OLD STEP POSITION
;NEW STEP = (36*WORD + BIT)*3 ! 1
	HRRI	S,(P)
	IMULI	S,44
	ADDI	S,(U)
	IMULI	S,3
	TDO	S,[1B0+1B35]	;WILL BE DECREMENTING LARGEST NEG NUMBER
				;PLUS STEP SO OVERFLOWS IF IT REACHES ZERO
	SOJ	S,		;SO WRAPS AROUND TO POSITIVE CORRECTLY
	MOVEM	S,STEP		;SET STEP VALUE
	MOVEM	P,STPPTR	;SAVE NEW STEP POINTER
	MOVE	P,PSTART	;GET POINTER TO FIRST WORD OF STRING
	JRST	NEXT		;ENTER LOOP
LOOP:	PHASE	0		;LOOP TO CLEAR EVERY 'STEP'TH BIT IN BIT STRING
CLRTMP:	AND	T,ZERTAB(U)	;CLEAR BIT IN TEMPORARY REGISTER
	SOJL	S,JIFFY		;DECREMENT STEP COUNT AND LOOP
CLRBIT:	MOVE	S,START(P)	;GET WORD TO CHANGE
	AND	S,ZERTAB(U)	;CLEAR BIT IN BIT STRING
	MOVEM	S,START(P)	;STORE NEW WORD IN BIT STRING
	MOVE	S,STEP		;RESET STEP COUNT
JIFFY:	JFFO	T,CLRTMP	;JUMP IF NON-ZERO
NEXT:	AOBJP	P,NEWSTP	;BUMP STRING POINTER
	MOVE	T,START(P)	;GET WORD TO EXAMINE
	JRST	JIFFY		;GO LOOK FOR BITS
	DEPHASE
FINISH:	EXIT
PSTART:	-<LEN+1>,,-1
STPCTR:	Z
STPPTR:	Z
STEP:	Z
	DEFINE	ZERO<
	EXP	-<1B<N>+1>
	N==N+1	>
	N==0
ZERTAB:
REPEAT	45,<	ZERO	>
START:	BLOCK	LEN
	END	BEGIN