Try using this:
when gf clicked delete [all v] of [factors v]//Sets up rest of script. set [number v] to [whatever number you're checking] set [factor v] to (1) repeat until <((number) / (2)) < (factor)> if <((number) mod (factor)) = (0)>//Checks for factors. add (factor) to [factors v] end change [factor v] by (1) end add (number) to [factor v]Factors should become a list of the number's factors. Now, one method for showing these numbers would be to have the list "factor" show. The other method is to create a sprite with all the numbers 1-10 as well as a comma, and then create a script to stamp itself in such a way that you get a list of numbers. I could give you the script, but it'd take awhile to type up, so I'd rather not.
Last edited by ErnieParke (2012-11-13 20:01:11)
Offline
Faster, but not in order from min to max:
when gf clicked set [number v] to (1036) delete (all v) of [factors v] set [f v] to (1) repeat until<(f) > ([sqrt v] of (number))> if<((number) mod (f)) = (0)> add (f) to [factors v] add ((number)/(f)) to [factors v] end change [f v] by (1) end
Last edited by MoreGamesNow (2012-11-13 19:32:24)
Offline
MoreGamesNow wrote:
Faster, but not in order from min to max:
when gf clicked set [number v] to (1036) delete (all v) of [factors v] set [f v] to (1) repeat until <(f) > ([sqrt v] of (number))> if<((number) mod (f)) = (0)> add (f) to [factors v] add ((number)/(f)) to [factors v] end change [f v] by (1) end
One problem that I can see is that if your number happens to be a perfect square, then you'll get it's square root repeated twice in the list. Other than that, I see no problem with your script.
Offline
ErnieParke wrote:
MoreGamesNow wrote:
Faster, but not in order from min to max:
when gf clicked set [number v] to (1036) delete (all v) of [factors v] set [f v] to (1) set [root v] to ([sqrt v] of (number)) repeat until <(f) > (root)> if<((number) mod (f)) = (0)> add (f) to [factors v] add ((number)/(f)) to [factors v] end change [f v] by (1) end if<(round(root)) = (root)> delete (last) of [factors v] endOne problem that I can see is that if your number happens to be a perfect square, then you'll get it's square root repeated twice in the list. Other than that, I see no problem with your script.
Ah, nice catch. Should be fixed
Offline
Here is an old project of mine that may help you: http://scratch.mit.edu/projects/BoltBait/515051
Offline