OZONE Asylum
Forums
Server-Side Scripting - Oh my!
Latin Squares and XOR
This page's ID:
33315
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
My Bamboo Fun was rendered useless several months ago. But, several days ago, my Intuos Art arrived. So I kind of hurried through this just a tad so I can play with Krita and Blender. Python 2.7. I did try Python 3.5.2 and it doesn't like print().format(). I'm not sure what else it doesn't like. But I'm okay with that because I use 2.7 and ya'll are free to fix it for 3.whateveryouuse. Yeah, play with it and all that. If you know anything about coding in any language, you should be able to see how ridiculously simple the defs are. It really is that simple. It uses a simple method to create 4x4 orthos. Then uses those to create 16x16 orthos. Then uses those to create 256x256 orthos. But it is very limited because of the small space that it starts in: 4x4. If you used another method to create a larger variety of 16x16, like the XOR extend method, then you will get more 256x256 orthos - by more than a few magnitudes. But... still a bit boring on one front in particular. This whole thing is based on XOR patterns, and those patterns will still be there. Cool as shit as-is, but it doesn't really introduce anything new. But maybe, just maybe... I have a few more tricks up my sleeve. Heh. [code] #!/usr/bin/env python import random import numpy as np def cout_2d(pme): bseq=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', #00 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V', #10 'W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l', #20 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','+','/'] #30 for row in pme: c='' for col in row: c=c+' '+bseq[col%64] # testing bigger grids print(c) print('') return def cout_1d(pme): bseq=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'] c='' for i in pme: c=c+' '+bseq[i] print(c) print('') return def cout_mini(lgrid,lrow,lcol,lval): bseq=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', #00 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V', #10 'W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l', #20 'm','n','o','p','q','r','s','t','u','v','w','x','y','z','+','/'] #30 for tr in range(len(lrow)): c='' if lrow[tr]==lval: for tc in range(len(lcol)): if lcol[tc]==lval: c=c+' '+bseq[lgrid[tr][tc]%64] # testing bigger mini-grids print(c) print('') return def gen_xor(n): # using uint8 because I don't plan on going # beyond 0-255 anytime soon fx=np.zeros((n,n),dtype=np.uint8) for row in range(n): for col in range(n): fx[row,col]=row^col return fx def gen_ls_ortho4(): # hardcoded to 4 # this works 100% # but this implementation # has some oddities that iron-out ls=gen_xor(4) ortho=gen_xor(4) if random.choice([0,1]): n=random.choice(range(4)) if n==0: ortho[0,:],ortho[1,:]=ortho[1,:].copy(),ortho[0,:].copy() if n==1: ortho[2,:],ortho[3,:]=ortho[3,:].copy(),ortho[2,:].copy() if n==2: ortho[:,0],ortho[:,1]=ortho[:,1].copy(),ortho[:,0].copy() if n==3: ortho[:,2],ortho[:,3]=ortho[:,3].copy(),ortho[:,2].copy() n=random.choice(range(8)) if n==0: ortho[0,:],ortho[2,:]=ortho[2,:].copy(),ortho[0,:].copy() if n==1: ortho[0,:],ortho[3,:]=ortho[3,:].copy(),ortho[0,:].copy() if n==2: ortho[1,:],ortho[2,:]=ortho[2,:].copy(),ortho[1,:].copy() if n==3: ortho[1,:],ortho[3,:]=ortho[3,:].copy(),ortho[1,:].copy() if n==4: ortho[:,0],ortho[:,2]=ortho[:,2].copy(),ortho[:,0].copy() if n==5: ortho[:,0],ortho[:,3]=ortho[:,3].copy(),ortho[:,0].copy() if n==6: ortho[:,1],ortho[:,2]=ortho[:,2].copy(),ortho[:,1].copy() if n==7: ortho[:,1],ortho[:,3]=ortho[:,3].copy(),ortho[:,1].copy() else: n=random.choice(range(8)) if n==0: ortho[0,:],ortho[2,:]=ortho[2,:].copy(),ortho[0,:].copy() if n==1: ortho[0,:],ortho[3,:]=ortho[3,:].copy(),ortho[0,:].copy() if n==2: ortho[1,:],ortho[2,:]=ortho[2,:].copy(),ortho[1,:].copy() if n==3: ortho[1,:],ortho[3,:]=ortho[3,:].copy(),ortho[1,:].copy() if n==4: ortho[:,0],ortho[:,2]=ortho[:,2].copy(),ortho[:,0].copy() if n==5: ortho[:,0],ortho[:,3]=ortho[:,3].copy(),ortho[:,0].copy() if n==6: ortho[:,1],ortho[:,2]=ortho[:,2].copy(),ortho[:,1].copy() if n==7: ortho[:,1],ortho[:,3]=ortho[:,3].copy(),ortho[:,1].copy() n=random.choice(range(4)) if n==0: ortho[0,:],ortho[1,:]=ortho[1,:].copy(),ortho[0,:].copy() if n==1: ortho[2,:],ortho[3,:]=ortho[3,:].copy(),ortho[2,:].copy() if n==2: ortho[:,0],ortho[:,1]=ortho[:,1].copy(),ortho[:,0].copy() if n==3: ortho[:,2],ortho[:,3]=ortho[:,3].copy(),ortho[:,2].copy() return ls,ortho def flatten2d(fme): # not numpy, but seems to work just fine fl=[] for i in fme: fl.extend(i) return fl def solve_mini(mgrid,mrow,mcol,mval): # this will solve for a mini-grid # should add some breaks in there to speed things up msolve=[] sqmult=int(np.sqrt(len(mgrid))) for val in range(mval*sqmult,mval*sqmult+sqmult): for row in range(len(mrow)): for col in range(len(mcol)): if mrow[row]==mval: if mcol[col]==mval: if mgrid[row][col]==val: msolve.append([row,col,val]) return msolve def shuffle_tandem(a,b): # i don't normally randomize the values (rvals) # but going to because it will shuffle # the solver later down the road # does not return a numpy array ll=len(a) rrows=random.shuffle(range(ll)) rcols=random.shuffle(range(ll)) rvals=random.shuffle(range(ll)) m=[];n=[] for row in rrows: tline=[] sline=[] for col in rcols: tline.append(rvals[a[row][col]]) sline.append(rvals[b[row][col]]) m.append(tline) n.append(sline) return m,n def is_ortho(grid0,grid1): # this checks to see if two grids are orthogonal # it does this by treating each grid as bit # in a base(n) manner # then counts the unique numbers # that is, eaching pairing of numbers in # the same position in each grid # should be unique ll=len(grid0) fcheck=set() for i in range(ll): for j in range(ll): fcheck.add(grid0[i][j]*ll+grid1[i][j]) print('len(fcheck)={}').format(len(fcheck)) return def main(args): ls0,ls1=gen_ls_ortho4() #ls0,ls1=shuffle_tandem(ls0,ls1) srow=flatten2d(ls0) scol=flatten2d(ls1) ls16=gen_xor(16) print('The first latin square, XOR size=4:') cout_2d(ls0) print('The orthogonal to the first latin square:') cout_2d(ls1) print('First latin square flattened for rows:') cout_1d(srow) print('Second latin square flattened for cols:') cout_1d(scol) print('XOR size=16:') cout_2d(ls16) print('mini grid 0, solve for 0,1,2,3') cout_mini(ls16,srow,scol,0) # 0 1 2 3 print('mini grid 1, solve for 4,5,6,7') cout_mini(ls16,srow,scol,1) # 4 5 6 7 print('mini grid 2, solve for 8,9,A,B') cout_mini(ls16,srow,scol,2) # 8 9 A B print('mini grid 3, solve for C,D,E,F') cout_mini(ls16,srow,scol,3) # C D E F #cout_2d(ls16) fsolve=[] for i in range(4): fsolve.extend(solve_mini(ls16,srow,scol,i)) print('Final solve data, fsolve[i][row,col,val]:') for i in fsolve:print(i) print('') lt16=gen_xor(16) for i in range(16): lt16[i]=ls16[fsolve[i][0]] print('Orthogonal using final solve data to permutate the rows:') cout_2d(lt16) print('Check to make sure that it is orthogonal, should be 256:') is_ortho(ls16,lt16) # the BIG jump print('') print('Time to make the big jump to 256.') gsolve=[] big256a=gen_xor(256) br=flatten2d(ls16) bs=flatten2d(lt16) print('') print('Previous 16x16 flattend for rows and columns.') print('Uncomment lines in code to print.') #print('br={}').format(br) #print('bs={}').format(bs) print('') print('Here is a mini-grid:') cout_mini(big256a,br,bs,0) print('Not completely accurate because of the lack of 256 symbols.') print('Uses 64 symbols with %64.') print('') print('Begin the countdown!') for i in range(16): print(15-i) gsolve.extend(solve_mini(big256a,br,bs,i)) print('Solve data is done.') print('Uncomment line in code to print.') #print('gsolve={}').format(gsolve) b256b=np.zeros([256,256],dtype=np.uint8) for i in range(256): b256b[i]=big256a[ gsolve[i][0] ] print('') print('256x256={}').format(256*256) fs=is_ortho(big256a,b256b) print('If the above number is 65536, then you have orthogonal') print('latin squares of size 256 in a numpy array dtype=uint8.') return 0 if __name__ == '__main__': import sys sys.exit(main(sys.argv)) [/code]
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