Topic awaiting preservation: Unique Shuffle, Chaos-n-Chains (Page 1 of 1) |
|
---|---|
Maniac (V) Mad Scientist From: |
posted 12-10-2018 16:02
When I started looking into latin squares and sudoku, I came across an interesting code: 0 1 2 3 1 2 3 0
code: 0 1 2 3 0 2 3 1
code: 0 1 2 3 1 2 3 0 01 12 23 30 len(chain)=[4]
code: a b c d e f g h 0 1 3 3 0 1 d a c b e f g h
code: 0 1 2 3 1 0 3 2 len(chain)=[2,2]
code: len(master_chain)=6 [2,2,2] [2,4] [6]
code: n=6 coins=[2,3,4,6] [2, 2, 2] [2, 4] [6]
code: n=6 ([2, 2, 2], 15) ([2, 4], 30) ([3, 3], 40) ([4, 2], 60) ([6], 120) g00dcount=265 badcount=455 720
code: #!/usr/bin/env python from math import factorial as fact def nchoser_min1(n,r): # permutation without repetition # with a reduction in possibilities n=n-1 r=r-1 return fact(n)/fact(n-r)
code: #!/usr/bin/env python from math import factorial as fact def nchoser_min1(n,r): # permutation without repetition # with reduction in possibilities n=n-1 r=r-1 return fact(n)/fact(n-r) print('n=6') print('') #[2, 2, 2] 15 a=nchoser_min1(6,2) b=nchoser_min1(4,2) c=nchoser_min1(2,2) print('[2, 2, 2] {}*{}*{}={}'.format(a,b,c,a*b*c)) gc0=a*b*c #[2, 4], 30 a=nchoser_min1(6,2) b=nchoser_min1(4,4) print('[2,4] {}*{}={}'.format(a,b,a*b)) gc1=a*b #[3, 3] 40 a=nchoser_min1(6,3) b=nchoser_min1(3,3) print('[3,3] {}*{}={}'.format(a,b,a*b)) gc2=a*b #[4, 2], 60 a=nchoser_min1(6,4) b=nchoser_min1(2,2) print('[4,2] {}*{}={}'.format(a,b,a*b)) gc3=a*b #[6], 120 a=nchoser_min1(6,6) print('[6] {}'.format(a)) gc4=a print('') print('g00dcount={}'.format(gc0+gc1+gc2+gc3+gc4))
code: brute force n chose r n=6 n=6 ([2, 2, 2], 15) [2, 2, 2] 5*3*1=15 ([2, 4], 30) [2,4] 5*6=30 ([3, 3], 40) [3,3] 20*2=40 ([4, 2], 60) [4,2] 60*1=60 ([6], 120) [6] 120 g00dcount=265 g00dcount=265
code: n=6 0 1 2 3 4 5 based on probability, the chain picked is: [2,4] expand into mini-chains: 0 0 1 1 1 1 shuffle all willy-nilly: 1 0 1 1 1 0 take each mini-chain in turn and daisy chain shuffle put it all back together . 0 . . . 0 1 . 1 1 1 . 1 0 1 1 1 0 . 1 . . . 5 0 . 2 3 4 . 0 1 2 3 4 5 . 5 . . . 1 2 . 4 0 3 . 2 5 4 0 3 1 [2]=15 51 [4]=02 24 43 30
|
Maniac (V) Mad Scientist From: |
posted 12-10-2018 22:21
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: 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: 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: 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: 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: 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: 0 1 2 3 4 5 2 0 1 4 5 3
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: ([2, 4], 30) ([4, 2], 60)
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
|
Maniac (V) Mad Scientist From: |
posted 12-11-2018 01:50
This all started because I wanted to do a unique shuffle by code: 0 1 2 3 4 1 2 3 4 0 01 12 23 34 40
code: 0 1 2 3 4 1 0 3 4 2
code: 0 1 2 3 4 5 1 2 3 4 0 .
code: 0 1 1 2 2 3 3 4 4 [5, 0] 5 [0]
code: 0 1 0 1 0 1 1 2 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 [5, 0] 4 [5] 4 5 5 [0] 5 0 5 0 0 1 2 3 4 5 1 2 3 4 5 0
code: n=7 [2, 2, 3], 48 3% [2, 3, 2], 72 4% [3, 2, 2], 90 5% [2, 5], 144 8% [5, 2], 360 16% [3, 4], 180 10% [4, 3], 240 13% [7], 720 38% g00dcount=1854
code: n=7 i=1000 [2, 2, 3], 29, 3% [2, 3, 2], 31, 3% [3, 2, 2], 43, 4% [2, 5], 65, 7% [5, 2], 191, 19% [3, 4], 97, 10% [4, 3], 151, 15% [7], 393, 39% len=8
code: #!/usr/bin/env python import random import copy def find_chains(aseq,bseq): keepme=0 findme=[] rlist=[] while aseq: if findme==[]: pcount=1 keepme=aseq.pop(0) findme=bseq.pop(0) else: t=aseq.index(findme) aseq.pop(t) findme=bseq.pop(t) pcount+=1 if keepme==findme: findme=[] rlist.append(pcount) return rlist def unique_shuffle(mpool): fpool=[] # build the pools for i in range(len(mpool)): t=copy.deepcopy(mpool) t.remove(mpool[i]) fpool.append(t) for i in range(len(mpool)): # find minimum length minl=len(mpool)+1 for p in fpool: if isinstance(p,list): t=len(p) if t<minl: minl=t # build list of minimums ml=[] for p in range(len(fpool)): if isinstance(fpool[p],list): if len(fpool[p])==minl: ml.append(p) # pick a pool a=random.choice(ml) # pick random from pool b=random.choice(fpool[a]) fpool[a]=b # prune for i in range(len(fpool)): if isinstance(fpool[i],list): if b in fpool[i]: fpool[i].remove(b) return fpool tl=list(range(7)) mlist=[] olist=[] for i in range(1000): x=unique_shuffle(tl) y=find_chains(copy.deepcopy(tl),copy.deepcopy(x)) if y not in mlist: mlist.append(y) olist.append(1) else: # it is already in mlist[] j=mlist.index(y) k=olist[j] olist[j]=k+1 ts=sum(olist) for i in range(len(mlist)): print(mlist[i],olist[i],float(olist[i])/float(ts) ) print('\nlen={}'.format(len(olist)))
|
Maniac (V) Mad Scientist From: |
posted 12-26-2018 23:00
Been meaning to get back to this, but I keep getting side-tracked. Been hanging with |
Maniac (V) Inmate From: The Pool Of Life |
posted 01-04-2019 03:04 |