I’ve gathered most of the scripts here and ran them here on my workstation, so here’s a zip with the scripts and the results:
"V1 - lo's original"
processing: 1.462 seconds heap: 168065736L
Num unique elem 1000000
OK
"V1 - jonadb"
processing: 1.752 seconds heap: 56065456L
OK
"V5 - lo's alternate using collect"
processing: 1.422 seconds heap: 56065440L
Num unique elem 1000000
OK
"V9 - XOR Swap"
processing: 3.821 seconds heap: 240074760L
Num unique elem 1000000
OK
"V10 - Fisher-Yates shuffle"
processing: 1.229 seconds heap: 56065408L
Num unique elem 1000000
OK
Biddle algorithm (thank you wikipedia):
Time: 0.019s, Mem: 0Kb
OK
denisT code:
Time: 0.114s, Mem: 0Kb
OK
i knew that people like brain-twisters
i will show the practical application of last task and if you guys want i can give an another one.
Sounds good to me.
Denis, can you come up with another brain twister then?
This is almost like academic integration (various algorithms).
I certainly don’t mind, as I won’t have much extra time until the week after E3.
YES YES YES Please create a new thread for it, or I can do it for you, whatever fits best Next please
I thought this “simple” brain-twister like you’ve called it, was awesome and lots of fun, also it’s incredible how much I’ve learned with just a simple task. It was a great idea Denis, thanks!
here is random poly sub selector based on [b]biddle[/b]'s little friend ([b]wikipedia[/b]) method slightly modified by me for better performance in mxs:
try(destroydialog SubSel_Rollout) catch()
global SubSel_Rollout
-- SubSel_Settings = undefined
global SubSel_Settings = if SubSel_Settings == undefined then #([100,100],0,50) else SubSel_Settings
rollout SubSel_Rollout "Random Polysel" width:200 height:94
(
group "Random: "
(
spinner seed_sp "Seed: " range:[0,1e9,SubSel_Settings[2]] type:#integer fieldWidth:56 align:#right offset:[0,-4] tooltip:"Zero is no seed"
spinner rand_sp "Percent: " range:[0,100,SubSel_Settings[3]] type:#integer fieldWidth:56 align:#right offset:[0,-2]
button rand_bt "Select" width:181 align:#left offset:[-4,2] tooltip:"Select Sub-Objects/CTRL - add/ALT - deselect/SHIFT - toggle/RC - all"
)
on seed_sp changed val do SubSel_Settings[2] = val
on rand_sp changed val do SubSel_Settings[3] = val
fn validPoly node = (iskindof node Editable_poly)
fn getSelectType = case of
(
(keyboard.controlPressed): #add
(keyboard.altPressed): #deselect
(keyboard.shiftPressed): #toggle
default: #select
)
fn getNumberSubs obj level = case level of
(
#vertex: obj.GetNumVertices()
#edge: obj.GetNumEdges()
#face: obj.GetNumFaces()
)
fn getRandomList count percent:100 seedvalue:0 =
(
if percent == 0 then #{}
else
(
if seedvalue > 0 do seed seedvalue
subs = #()
subs.count = count
for i = 1 to count do
(
k = random 1 i
subs[i] = subs[k]
subs[k] = i
)
subs.count = (count*percent*0.01 + 0.5)
subs as bitarray
)
)
fn polySubSelect obj list: type: = if validPoly obj do
(
if type == unsupplied do type = getSelectType()
level = GetSelectionLevel obj
sel = obj.GetSelection level
list = case list of
(
#all: #{1..(getNumberSubs obj level)}
#percent: getRandomList (getNumberSubs obj level) percent:SubSel_Settings[3] seedvalue:SubSel_Settings[2]
)
func = obj.SetSelection
list = case type of
(
#select: list
#add: list + sel
#deselect: sel - list
#toggle: list - (sel*list)
default: list
)
func level list
gc light:on
(obj.GetSelection level)
)
on rand_bt pressed do undo "Poly Sub Select" on polySubSelect (modpanel.GetCurrentObject()) list:#percent
on rand_bt rightclick do undo "Poly Sub Select" on polySubSelect (modpanel.GetCurrentObject()) list:#all
on SubSel_Rollout close do
(
SubSel_Settings[1] = getdialogpos SubSel_Rollout
)
on SubSel_Rollout open do
(
)
)
createdialog SubSel_Rollout pos:SubSel_Settings[1]
i’ve made it this morning and didn’t test it well. so… it might has bugs.
how to use:
-
select a editable poly object
-
choose a subobject level (#vertex, #edge, #face)
-
press random (check button’s tooltip for more options)
please, don’t use the code without giving a credit everyone participated.
i saw at least 4 similar tools in different resources but only this one really works for 1,000,000 verts/polys
Wow, great stuff, makes perfect sense! Never thought of it though Once again, thanks Denis for your work+time and everybody else of course! Now… what’s the next challenge ?
I’ve written a small tool to help compare execution times and memory usage for blocks of code, saves me the trouble of writing timestamp commands