"perc"<-
function(n = 10)
{
	i <- 1
	nn <- n * n
	aa <- round(runif(1, 1, nn))
	cc <- rep(0, nn)
	cc[aa] <- aa
	while(i < nn) {
		bb <- round(runif(1, 1, nn))
		if(cc[bb] == 0) {
			i <- i + 1
			aa <- c(aa, bb)
			cc[bb] <- bb
		}
	}
	aa <- matrix(aa, ncol = n, byrow = T)
	for(i in (n - 1):0) {
		cc <- aa
		cc[cc <= (n * ((n - 1) - i))] <- 1
		cc[cc > (n * (n - i))] <- 0
		cat("\nsite filling probability, p = ", (n * (n - i))/(n * n),
			"\n")
		print(cc)
		cat("\n")
	}
	cat("\n\norder of filling of all sites\n")
	aa
}
"percx11"<-
function(n = 10)
{
# a matrix the dimension of the argument is filled randomly;
# the order of filling is displayed point by point in a graphics window;
# after each point is displayed, hit return to display the next
# 	or enter "q" to quit
# 	or enter a number to plot that many points without interruption
# as each point is plotted, local grid segments are drawn about it
# to aid in visualizing clusters
#
# the order of filling of the matrix is returned
#
	i <- 1
	nn <- n * n
	aa <- round(runif(1, 1, nn))
	cc <- rep(0, nn)
	cc[aa] <- aa
	while(i < nn) {
		bb <- round(runif(1, 1, nn))
		if(cc[bb] == 0) {
			i <- i + 1
			aa <- c(aa, bb)
			cc[bb] <- bb
		}
	}
	percplot(aa, n)
	aa
}
"percplot"<-
function(yy, n = 10)
{
# yy is list of n*n numbers, each unique in range 1:n*n
# order determines order of filling of n x n matrix
# plot matrix, by decomposing number into coordinates of range 1:n
# put label = ordinal at coordinate position
#
# after each point is plotted, enter CR to plot next point, 
# or enter a number to plot that many points without break
#
# as each point is plotted, local grid segments are drawn about it
# to aid in visualizing clusters
#
	yy1 <- as.integer((yy - 1)/n) + 1
	yy2 <- as.integer((yy - 1) %% n) + 1
	plot(yy1, yy2, type = "n")
	skip <- 0
	for(i in 1:length(yy)) {
		text(yy1[i], yy2[i], i)
		lines(c(yy1[i] - 0.5, yy1[i] + 0.5), c(yy2[i], yy2[i]))
		lines(c(yy1[i], yy1[i]), c(yy2[i] - 0.5, yy2[i] + 0.5))
		cat(i, "\t")
		if(skip > 1) {
			skip <- skip - 1
			next
		}
		xx <- scan("", what = character(), n = 1)
		if(length(xx) == 0)
			next
		if(xx[1] == "q")
			return()
		skip <- as.numeric(xx)
	}
	return()
}
