Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Soduko
Message
 
To
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:
01074216
Views:
28
Yes - that seems to work. I'm not sure about the complexity of the puzzle though...I've been doind a lot of reading on this. Turns out, this is a very big deal with a lot of people. One *new* stipulation I found was that the puzzle needs to have only one solution - meaning when you remove some of the numbers, there should be only one way to solve it.

>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
Reply
Map
View

Click here to load this message in the networking platform