Richard did an excellent job optimizing the algorithm. I just take the low hanging fruit of adding one line to build the array for the frequency of numbers in the inner loop of Richard's repeat loop. Thus obviating the need to go through the data again for the frequency. Also I locked the screen.

-- This is an optimized version
on mouseUp
answer "This is a Greatly Optimized Version" & cr &\
"In order to see the optimization between the Load Matrix code you need to analyze at least 1000 Games"
put empty into field "tNums"
put empty into field "tRCount"
put empty into field "totNumsFtr"
if field "nums" is empty then
answer "You need to import Past Games in order in order to Anaylze Games"
exit mouseUp
end if
-- Bypass ask to use fixed value for timing:
ask "how Many Games do you want to Analyze"
# get 5000
put it into tGames2Analyze
-- Capture start time:
put the millisecs into t
--
-- Load Matrix
set itemdel to tab
set the cursor to watch
put field "nums" into vNums
put 1 into tCounter
lock screen -- added BN
-- New method using a template line which is filled in
-- each time through the loop to avoid item counts:
--
-- Load template line:
put empty into tTemplateLine
repeat 39
put space & tab after tTemplateLine
end repeat
-- Use a copy for each line, filling in appropriate columns
-- as it goes:
repeat for each line tRow in vNums
put tTemplateLine into tThisLine
repeat with tPicks = 6 to 10
put word tPicks of tRow into tColumn
add 1 to tA[tColumn] -- added BN
put "X" into byte (tColumn *2)-1 of tThisLine
end repeat
put tThisLine & cr after tMatrix
add 1 to tCounter
if tCounter >tGames2Analyze then
exit repeat
end if
end repeat
--
put tMatrix into field "tNums"
repeat with i = 1 to 39
put tA[i] &tab after tVals
end repeat
put tVals into fld "totNumsFtr"
--
-- Display elapsed time:
unlock screen -- added BN
answer " It took"&& the millisecs - t && " milliseconds to complete the analysis"
end mouseUp

Thanks Bernd,
It is always good to see other people involved in adding comments and code to samples that people provide.
I haven't added your code yet but did you see any improvement in the timing?
I will modify the code and check.
Thanks, any contributions are always welcome.

There are languages that can produce code that executes faster, but few that offer us as much choice between simple code or fast runtime.

Obviously it would be ideal if the engine could deliver both at the same time, but Computer Science suggests that won't be possible until the engine gets some deep AI, since optimization isn't just about the engine but the algorithms we ask it to perform. The more we think like developers using lower-level languages, the more we get performance on par with those.

But at least we have a choice. We can dive into a problem and get a useful result with minimal effort, solving the problem using very human-centric logic. And if we're working with large amounts of data where optimization can be useful, once we understand the problem well we can go back and think more like a computer to get a result that favors the processing limitations of computers.

This is one of the reasons I keep using LiveCode all these years: I can deliver a good result in minutes, and a great result in hours, but even then I'm usually spending less time coding than my friends using Java or C.

Richard Gaskin
Community volunteer LiveCode Community LiaisonLiveCode development, training, and consulting services: Fourth World Systems:http://FourthWorld.comLiveCode User Group on Facebook :http://FaceBook.com/groups/LiveCodeUsers/