[net.puzzle] Another code puzzle

jim@cadomin.UUCP (Jim Easton) (03/23/85)

For the line eater.

Since we're doing code puzzles try this one.  I make no claims for
efficiency - It's a C version of some code I wrote for a Honywell
on which it took only three instructions and ran like stink.

	Jim@alberta

/* comments have been deliberately omitted */
#define NBITS 9	/**/

int doit(arg)
short arg;
{
long unsigned register pick, flip, work;
int register i;

	pick = 1 << NBITS;
	flip = pick - 1;
	work = (arg & flip) << NBITS;
	for (i = 0; i < NBITS; i++) {
		if (work & pick) work ^= flip;
		work = work >> 1;
		}
	return ((int) work);
	}

larry@hpfclg.UUCP (larry) (04/13/85)

*** SPOILER ***

rot13 (original puzzle follows, rot0)


Q'wn rire urne bs ovanel Tenl pbqr ?  Guvf uhzzre pbairegf sebz
ovanel Tenl pbqr gb ovanel.

Va Tenl pbqrf, rknpgyl bar qvtvg punatrf sebz bar pbqr gb gur arkg.
Plpyvp vf orfg.  Vg unf znal hfrshy nccyvpngvbaf, rfcrpvnyyl plpyvp
ovanel Tenl pbqr.  (bs pbhefr V pna'g guvax bs nal bss gur gbc bs
zl urnq, ohg V erzrzore V arrqrq vg ynfg jrrx sbe fbzrguvat)

Abj, svaq gur (zber hfrshy) pbairefr: ovanel gb ovanel Tenl pbqr pbairegre.

GGSA,
Yneel Srafxr
{ucynof, vuac4}!ucspyn!yneel-s


TTFN,
Larry Fenske
{hplabs, ihnp4}!hpfcla!larry-f


Text from the original note:

/***** hpfclg:net.puzzle / cadomin!jim /  4:31 pm  Mar 31, 1985*/

/* comments have been deliberately omitted */
#define NBITS 9	/**/

int doit(arg)
short arg;
{
long unsigned register pick, flip, work;
int register i;

	pick = 1 << NBITS;
	flip = pick - 1;
	work = (arg & flip) << NBITS;
	for (i = 0; i < NBITS; i++) {
		if (work & pick) work ^= flip;
		work = work >> 1;
		}
	return ((int) work);
	}
/* ---------- */