Hi,
I have a sequence of numbers 1 to 32. I want to rearrange them from 1, 2, 3, 4, 5, etc,
so they are odd and even, like this:
1, 3, 5, 7, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14, 16
17, 19, 21, 23, 25, 27, 29, 31, 18, 20, 22, 24, 26, 28, 30, 32
And then print the numbers in a loop in that order
Beating my brains up with this one!
Brian
			
			
			
				Quick and dirty.
	openconsole
	int even[17],odd[17]
	int even_ndx=0:odd_ndx=0
	for i=1 to 32
		if i%2 = 0
			even_ndx++
			even[even_ndx]=i
		else
			odd_ndx++
			odd[odd_ndx]=i
		endif
	next i
	for x=1 to 8
		print str$(odd[x])+",",
	next x
	for x=1 to 7
		print str$(even[x])+",",
	next x
	print str$(even[8])
	for x=9 to 16
		print str$(odd[x])+",",
	next x
	for x=9 to 15
		print str$(even[x])+",",
	next x
	print str$(even[16])
	waitcon
	closeconsole
end
LarryMc
			
			
			
				I am not sure he meant that Larry. ::)
It just would be too simple. ;)
You could do FOR NEXT loops with STEP 2.
I think he has 32 random numbers but I can be wrong. :D
Anyway in that case my pseudo proposal:
1.) Put the numbers in an array. (Array0)
2.) Sort the array incremental.
3.) Make a loop (FOR 0 TO 31) and check if the number is even
If even copy the number in an other array (Array1) and replace the element with 0 or other unique number in Array0.
4.) Make an other loop and shift up the elements if Array0[y] == unique number.
Now you have 2 Arrays, Array0 with odd and Array1 with even numbers.
5) Make a nested loop 4X8 and with a little juggle you can take the elements out from the 2 Arrays in the sequence you want it. ;D
			
			
			
				Ficko
I started at your step 3, since he didn't say random. ;)
He can use my code simplly by doing your step 1 and 2 and then using my i loop as the index to his sorted random numbers.
The odd/even array sizes would have to be increased since with random numbers you could end up with all odd or all even(worse case).
LarryMc
			
			
			
				Larry and Ficko,
Thank you both for your suggestions. I have already tried two loops with STEP 2,
the second one starting at 1 higher than the first. Works OK for the first 16
numbers, and then goes to pot. I could end up with up to 8,000 consecutive
numbers to sort this way - the number of labels could change
Let me tell you what I am doing. I am printing labels - 16 to a sheet, two across
My labels program insists on printing DOWN the sheet, 1 to 8, then the second column,
9 to 16
The customer wants (and should have, of course) the labels to run across - so
top left is 1, top right is 2, second down on left 3, second down on right 4, and so on
There is a program call you can use to land your label text on exactly the label you
wish, so I know it is possible, but need to work out how
Brian
			
			
			
				i'm probably completely missing the point and just redoing what has already been done But..............
OPENCONSOLE
int i=1,s=1
for x = 1 to 4
print " --" 'rem just for cosmetics
	for i = 1 to 8
		print s
		s=s+2
		next i
 if x = 1 then s=2
 if x = 2 then s=17
 if x = 3 then s=18
 
next x
waitcon
closeconsole
			
			
			
				If I understand you right this is the structure you are looking for.
	openconsole
	'establish number of labels to print
	int count=519
	'set up array to hold max labels
	string tag[10000]
	'load the tag array 
	'here I did the numbers because it is easy
	'in reality if you are doing names
	'I would create a listview and set the sort flag
	'and just keep adding names to the end and let the LV
	'take care of the sorting
	for x=0 to count-1
		tag[x]=str$(x)
	next x
	
	'set up the outer loop to handle 16 labels at a time
	for x=0 to count-1 step 16
		'address the left col which is odd
		for y=0 to 15
			if (x+y)%2 = 0
				print tag[x+y]+",",
			endif
		next y
		'now we address the right col
		for y=0 to 15
			if (x+y)%2 = 1
				print tag[x+y]+",",
			endif
		next y
		'page advance
		print
	next x
LarryMc
			
			
			
				This version accounts for the last partial page by printing a "B" (blank) in the necessary locations.
	openconsole
	'establish number of labels to print
	int count=519
	'set up array to hold max labels
	string tag[10000]
	'load the tag array 
	'here I did the numbers because it is easy
	'in reality if you are doing names
	'I would create a listview and set the sort flag
	'and just keep adding names to the end and let the LV
	'take care of the sorting
	'then read the LV into the array
	for x=0 to count-1
		tag[x]=str$(x)
	next x
	
	'set up the outer loop to handle 16 labels at a time
	for x=0 to count-1 step 16
		'address the left col which is odd
		for y=0 to 15
			if (x+y)%2 = 0
				if (x+y)< count
					print tag[x+y]+",",
				else
					print "B,",	
				endif
			endif
		next y
		'now we address the right col
		for y=0 to 15
			if (x+y)%2 = 1
				if (x+y)< count
					print tag[x+y]+",",
				else
					print "B,",	
				endif
			endif
		next y
		'page advance
		print
	next x
LarryMc
			
			
			
				Or with a formula to sort out the numbers...
OPENCONSOLE
for x = 1 to 64
	y = ((x - 1) & -9) + ((x - 1) & 7) + ((x - 1) & 8) / 8 + 1
	print using(" ###",y),
	if (x % 16) = 0 then print
next x
DO
UNTIL INKEY$ > ""
closeconsole
(Well OK, it's a CBasic example, but the formula should do in both versions anyway...)  ;D
Cheers,
Johnny
			
			
			
				Johnny,
Your example worked perfectly, as long as I start at 1 to a multiple of 16. If I need to start
the count at, say, 100 to 164, the sequence goes wrong
Larry,
I was out last night, so I only had chance to test Johnny's submission. Will get more
time tonight
Thanks to all who have helped,
Brian