Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Soduko
Message
From
01/12/2005 15:31:56
Walter Meester
HoogkarspelNetherlands
 
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Re: Soduko
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01073278
Message ID:
01073927
Views:
34
How about this one.

It will create a new sudoko (never heard about it until today though) map each time.
DIMENSION aStrings[9], aResult[9], aRandomize[6,3]
CLEAR 

FOR nT = 0 TO 17
	aRandomize[nT+1] = VAL(SUBSTR(GETWORDNUM("123 132 231 213 312 321", INT(nT/3)+1),(nT%3)+1,1))
ENDFOR

* Generate a random number to use as a base
cString = "123456789"
FOR nT = 1 TO 9
	nPos = INT(RAND() * 9)+1
	cString = IIF(nPos>1, SUBSTR(cString, nPos,1)+LEFT(cString, nPos-1)+SUBSTR(cString,nPos+1), cString)
	cString =  SUBSTR(cString,2)+LEFT(cString,1)
ENDFOR

* Make a basic Soduko map
nT = 1
FOR nY = 1 TO 3
	FOR nX = 1 TO 3
		aStrings[nT] = cString
		cString = SUBSTR(cString,4)+LEFT(cString,3)
		nT = nT + 1 
	ENDFOR
	cString =  SUBSTR(cString,2)+LEFT(cString,1)
ENDFOR

* Move rows arround, to randomize
nT = 1
nRand2 = INT(RAND()*6)+1
FOR nY = 1 TO 3
	nRand = INT(RAND()*6)+1
	FOR nY2 = 1 TO 3
		aResult[nT] = aStrings[(aRandomize[nRand2, nY]-1)*3+aRandomize[nRand, nY2]]
		nT = nT + 1 
	ENDFOR
ENDFOR

* Move columns arround, to randomize
nT = 1
nRand2 = INT(RAND()*6)+1
FOR nX = 1 TO 3
	nRand = INT(RAND()*6)+1
	FOR nX2 = 1 TO 3
		FOR nX3 = 1 TO 9
			aStrings[nX3] = STUFF(aStrings[nx3], (aRandomize[nRand2, nX]-1)*3+aRandomize[nRand, nX2], 1, ;
				SUBSTR(aResult[nX3], nT,1))
		ENDFOR
		nT = nT + 1 
	ENDFOR
ENDFOR

* Display puzzle

FOR nT = 1 TO 9
	? " "+aStrings[nT]
ENDFOR
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform