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:
01128371
Views:
23
Walter,

This thread invoked my interest to the issue. Take a look on Download # 30434. If you do not mind, it will contain your code, otherwise I will add something on my own. Let me know.
If you have ideas about how to code the puzzle with single solution and/or define the difficulty level, I would greatly appreciate if you share it with me.

Thanks


>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