Code:
'This was code to solve the "Josephus" puzzle in another thread. 'It's an example of a BYTE array being MUCH faster than a LONG array. 'Try both [REDIM circ(n) AS LONG] and [REDIM circ(n) AS BYTE] below. 'AS BYTE is over 2x faster on my celeron laptop. 'PBCC #COMPILE EXE #DIM ALL FUNCTION PBMAIN () AS LONG LOCAL a, n, ii, lastWarr AS LONG REGISTER warrPos AS LONG, cMod AS LONG ' INPUT "How many warriors? ",n ' INPUT "Counting modus? ",a FOR n = 28048000 TO 28048003 'loop will try a several warrior/modus combinations FOR a = 3 TO 5 REDIM circ(n) AS BYTE 'LONG 'Try both to verify speed increase using BYTE FOR ii = 1 TO n circ(ii) = 49 NEXT DO INCR warrPos IF warrPos > n THEN warrPos = 1 IF circ(warrPos) = 49 THEN INCR cMod IF cMod = a THEN circ(warrPos) = 48 cMod = 0 INCR lastWarr IF n - lastWarr = 1 THEN FOR ii = 1 TO n IF circ(ii) = 49 THEN PRINT "The warrior with position"+ STR$(ii)+ " in the circle is remaining " EXIT DO END IF NEXT END IF END IF END IF LOOP RESET warrPos, cMod, lastWarr NEXT NEXT WAITKEY$ END FUNCTION
Leave a comment: