🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by grunwald Thu, 16 Jul 1987 13:11
Re: T or routing question
#16
Author: grunwald
Date: Thu, 16 Jul 1987 13:11
43 lines
1417 bytes
The following program contains functions to compute one of many grey codes
and the inverse function for that grey code.

The loop would be defined as grey(0), grey(1), ...., grey(N-1) for N nodes.
If each node was 'nodeNumber', then you can define: 

#define wrap(x,y,z) ( (x) < y ? y : ( ( (x) > z ) ? z : x ))

	gNode = grey(nodeNumber)
	leftNode = greyinv( wrap(gNode-1, 0, N-1) );
	rightNode = greyinv( wrap(gNode+1, 0, N-1) );

'wrap' simply servers to keep the node numbers in the range 0..N-1. More
complicated structures.

main()
{
    int i;
    for (i = 0; i < 8; i++) {
	printf("%3d: [%3d, %3d] [%3d,%3d]  [%3d, %3d]\n",
	       i,
	       grey(i-1), invgrey(grey(i-1)),
	       grey(i), invgrey(grey(i)),
	       grey(i+1), invgrey(grey(i+1)));
    }
}

grey(i)
int i;
{
    return (i >> 1) ^ i;
}

invgrey(i)
int i;
{
    int j = i;
    do {
	j = ( j >> 1 );
	i ^= j;
    } while (j != 0);
    return(i);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads