OZONE Asylum
Forums
Server-Side Scripting - Oh my!
Unique Shuffle, Chaos-n-Chains
This page's ID:
33322
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Let's take a closer look at this and why I am using -1 for both variables: [code] def nchoser_min1(n,r): n=n-1 r=r-1 return fact(n)/fact(n-r) [/code] When doing the factorial thing with pools of possibilities, you have something like this: [code] n=6 0=[0, 1, 2, 3, 4, 5] 1=[0, 1, 2, 3, 4, 5] 2=[0, 1, 2, 3, 4, 5] 3=[0, 1, 2, 3, 4, 5] 4=[0, 1, 2, 3, 4, 5] 5=[0, 1, 2, 3, 4, 5] [/code] Then, when you pick one, you prune, and move on to the next one. - the first has 6 options -- pick and prune - the second has 5 options because of pruning -- pick and prune And so on down to the last pool, which will have only one option. Factorial. So why am I using -1? Because I have the added rule that a position can't contain itself in it's pool. [code] n=6 0=[1, 2, 3, 4, 5] 1=[0, 2, 3, 4, 5] 2=[0, 1, 3, 4, 5] 3=[0, 1, 2, 4, 5] 4=[0, 1, 2, 3, 5] 5=[0, 1, 2, 3, 4] [/code] And then the same kind of thing, but remember that it can't be itself (so to speak). - the first pick has only 5 options because it can't be itself -- pick and prune - the next can't be iself or previous, so only 4 options -- pick and prune - the next can't be itself or previous 2 picks, so only 3 options -- pick and prune That's why I said that n=6 is actually (6-1)!=120 for a full chain. Let's look at one with sub-chains. [code] n=6 c=[3,3] 0=[1, 2, 3, 4, 5] 1=[0, 2, 3, 4, 5] 2=[0, 1, 3, 4, 5] 3=[0, 1, 2, 4, 5] 4=[0, 1, 2, 3, 5] 5=[0, 1, 2, 3, 4] pick 02 prune 0=2 1=[3, 4, 5] 2=[1, 3, 4, 5] 3=[1, 4, 5] 4=[1, 3, 5] 5=[1, 3, 4] mini-chain=[02] [/code] What just happened? Why all the 0's taken out? Because it is the start of the mini-chain and has to be set aside to link-back to when you get to the end of the mini-chain. Until then, 0 can't be chosen. [code] pick 21 prune 0=2 1=[3, 4, 5] 2=1 3=[4, 5] 4=[3, 5] 5=[3, 4] mini-chain=[02, 21] [/code] And now you do the link-back thing because you are at the end of the mini-chain (size 3). [code] end of chain has to be 10 0=2 1=0 2=1 3=[4, 5] 4=[3, 5] 5=[3, 4] mini-chain=[02, 21, 10] [/code] Pick a starting point, set it aside, chain away, and then link-back when you get to the end. [code] 0 1 2 3 4 5 2 0 1 4 5 3 [/code] Tada. Perfectly valid solution with all position being different. Added bonus that there are two mini-chains in there instead of a full-on daisy chain of size 6. The possibilities go something like this: [code] n=6 c=[3,3] 0: starting point, 5 possibilities, can't be self, prune and set aside 2: 3 possibilities, can't be self, previous, or starting point, pick-n-prune 1: only one possibility, link-back to start [/code] And that is why using -1 for n and r is good for this. That is why it works to get the same numbers as my brute force. Instead of (6 chose 3), actually doing (5 chose 2). And so on. But there is something in my brute force that really bothers me. These two little lines: [code] ([2, 4], 30) ([4, 2], 60) [/code] They are different. Since they produce different probabilities depending on order they are obviously different. Not to me. To me, [2,4] and [4,2] are the same. Remember when I said that I was going to expand the chains into groups and shuffle? That is why I see them as the same. Check it out: [code] [2, 4] = 0 0 1 1 1 1 [4, 2] = 0 0 0 0 1 1 :shuffle: [2, 4] = 1 1 0 0 1 1 [4, 2] = 0 0 1 1 0 0 [/code] They have over-lap and can produce the exact same groupings. And yet one has a higher probability of happening over the other. Can this be refined even more to take that into account without actually... doing it? Should I keep what I already have working? Or should I go down yet another rabbit hole? But... Yesterday I realized that I had already solved this problem over two years ago. I just didn't realize it right away because it was for a different thing that I was playing with. I already ran a few small samples and the numbers are close enough. I'm going to open the flood gates of possibilities even wider. Chaos is a strange mistress that I adore to no end, and imma make 'er mah bitch. No, I'm not going to abandon this. There is power in manipulating chains. I've already done it several times to great effect. Just not quite in this way. This particular approach will go on the backburner for a bit. Yes, I will show ya'll how I solved this problem over two years ago. One of the goofiest little baubles that I have ever coded. And the basic idea behind it also has a lot of power. Stay tuned. [small](Edited by [url=http://ozoneasylum.com/user/351]warjournal[/url] on 12-10-2018 22:58)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail