TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: DAVID WILLIAMS
from: ROBERT FORTUNE
date: 1997-09-23 16:01:00
subject: Scramble

DW>100 ' scramble tester
DW>102 A$="abc"
DW>105 T=600 ' number of trials for each routine
DW>110 RANDOMIZE TIMER
DW>120 DIM P$(6), N$(2), C(6), L$(3) 'permutations, names, counts, letters
DW>125 '
DW>130 FOR X=1 TO 2:READ N$(X):NEXT
DW>140 DATA Williams, Fortune
DW>145 '
DW>150 FOR X=1 TO 6:READ P$(X):NEXT
DW>160 DATA abc, acb, bac, bca, cab, cba
DW>165 '
DW>170 FOR X=1 TO 2
DW>175 '
DW>180 FOR Y=1 TO 6
DW>190 C(Y)=0 ' zero counters
DW>200 NEXT Y
DW>205 '
DW>210 FOR Y=1 TO T
DW>215 '
DW>220 ON X GOSUB 1000, 2000 'perform Williams or Fortune shuffle
DW>225 '
DW>230 FOR Z=1 TO 6 ' increment appropriate counter
DW>240 IF B$=P$(Z) THEN C(Z)=C(Z)+1:Z=6
DW>250 NEXT Z
DW>255 '
DW>260 NEXT Y
DW>265 '
DW>270 PRINT N$(X); " routine results:"
DW>280 FOR Y=1 TO 6
DW>290 PRINT P$(Y); C(Y)
DW>300 NEXT Y
DW>310 PRINT
DW>315 '
DW>320 NEXT X
DW>330 END
DW>335 '
DW>999 ' Williams shuffle
DW>1000 FOR U=1 TO 3
DW>1010 L$(U)=MID$(A$,U,1) 'put characters into array
DW>1020 NEXT U
DW>1025 '
DW>1030 FOR U=1 TO 2 'choose an unrandomized chr and swap with it
DW>1040 SWAP L$(U), L$(U+INT(RND*(4-U)))
DW>1050 NEXT U
DW>1055 '
DW>1060 B$=""
DW>1070 FOR U=1 TO 3
DW>1080 B$=B$+L$(U) 'put shuffled chrs into b$
DW>1090 NEXT U
DW>1100 RETURN
DW>1105 '
DW>1999 'Fortune shuffle
DW>2000 B$=A$ 'so a$ is never changed
DW>2020 FOR U=1 TO 3
DW>2030 S=INT(RND*3)+1 'choose a random position, different from U
DW>2040 REM IF S=U GOTO 2030  ' REMed out
DW>2050 E$=MID$(B$,U,1)
DW>2060 MID$(B$,U)=MID$(B$,S,1)
DW>2070 MID$(B$,S)=E$
DW>2080 NEXT U
DW>2090 RETURN
DW>This little program shows your routine to be disastrously awful! Three
DW>of the possibilities are *never* generated!
DW>Try it!
   I did and you're right! However, you're not 100% right. REM out line
   2040 and see what happens. You'll find that it isn't the whole routine
   but only the code that does not allow a character to be swapped with
   itself. Logically that doesn't make any sense. In order for the routine
   to work well it must include the possibilty of exchanging a character
   with itself! I haven't studied it enough to see why it does what it
   does.  (If anyone knows the answer I would like to know!) I did however
   learn something. Thank you!
-Robert
 * OLX 2.1 TD * A moment's insight is worth a lifetime's experience.
--- PCBoard (R) v15.3/M 10
---------------
* Origin: MoonDog BBS þ RIME NetHub Brooklyn,NY (1:278/15)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.