Re: Get all combinations of n digits among m digits

new topic     » goto parent     » topic index » view thread      » older message » newer message
petelomax said...

I couldn't understand why you were testing nr=1, if nr=1 and ns!=ne then ?9/0 end if never triggered, so I took it out...

If you don't return at this step if nr = 1, you will try to recurse an empty remaining sequence as I remove the first digit before recursing.

  -- select next 
  recurse(remove(remaining, 1), ne, selected & remaining[1]) 
  -- skip next 
  recurse(remove(remaining, 1), ne, selected) 

I don't get the same results as yours on your second proposal which takes more time than mine, but your first proposal is quicker.

Mine: 
Euphoria:recurse, duration: 10.684000 s 
 
Yours: 
Euphoria:recurse, duration: 8.822000 s 
Euphoria:recurse, duration: 10.956000 s 

Jean-Marc

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu