Topic awaiting preservation: Latin Squares and XOR |
|
---|---|
Author | Thread |
Maniac (V) Mad Scientist From: |
posted 10-07-2017 04:34
Nugget of joy that I started some time ago, but got put on hold just tad. code: #!/usr/bin/env python # -*- coding: utf-8 -*- import pickle import itertools def ndlist(s, v): # http://stackoverflow.com/questions/13447882/python-2-7-creating-a-multidimensional-list # by pterodragon return [ndlist(s[1:], v) for i in range(s[0])] if s else v def remap(rgrid,rseq): ngrid=[] for i in rseq: ngrid.append(rgrid[i]) return ngrid def is_ortho(agrid,bgrid): isbit=0 tsize=len(agrid) olist=[] for j in range(tsize): for i in range(tsize): olist.append(tsize*agrid[j][i]+bgrid[j][i]) t=set(olist) if len(t)==(tsize*tsize): isbit=1 return isbit ss=16 tgrid=ndlist([ss,ss],0) for j in range(ss): for i in range(ss): tgrid[j][i]=j^i pseq=[1,3,4,5,6,7,8,9,10,11,12,13,14,15] fseq=[] tcount=0 for x in itertools.permutations( pseq, 3): s=[0] y=[2] y.extend(x) for i in y: t=[] for v in s: t.append(i^v) s.extend(t) ts=set(s) if len(ts)==ss: rmgrid=remap(tgrid,s) obit=is_ortho(tgrid,rmgrid) if obit: fseq.append(y) print('{} --> {}').format(y,s) tcount=tcount+1 print('tcount={}').format(tcount) output = open('xor16_orthoseq.pkl', 'wb') pickle.dump(fseq, output,-1) output.close()
code: #!/usr/bin/env python # -*- coding: utf-8 -*- import pickle import random def ndlist(s, v): # http://stackoverflow.com/questions/13447882/python-2-7-creating-a-multidimensional-list # by pterodragon return [ndlist(s[1:], v) for i in range(s[0])] if s else v def cout_2dgrid(cgrid): ll=len(cgrid) cmap=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'] for row in range(ll): pme=' ' for col in range(ll): pme=pme+' '+cmap[ cgrid[row][col] ] print(pme) print('') return def remap(rgrid,rseq): ngrid=[] for i in rseq: ngrid.append(rgrid[i]) return ngrid def is_ortho(agrid,bgrid): isbit=0 tsize=len(agrid) olist=[] for j in range(tsize): for i in range(tsize): olist.append(tsize*agrid[j][i]+bgrid[j][i]) t=set(olist) if len(t)==(tsize*tsize): isbit=1 return isbit ss=16 tgrid=ndlist([ss,ss],0) for j in range(ss): for i in range(ss): tgrid[j][i]=j^i pkl_file = open('xor16_orthoseq.pkl', 'rb') xseq = pickle.load(pkl_file) y=random.choice(xseq) s=[random.choice( range(ss) )] for i in y: t=[] for v in s: t.append(i^v) s.extend(t) print('s={}\n').format(s) ogrid=remap(tgrid,s) cout_2dgrid(ogrid) fcheck=is_ortho(tgrid,ogrid) if fcheck: print('yes, ortho') else: print('fail')
|
Maniac (V) Mad Scientist From: |
posted 10-11-2017 13:42
T + XOR = F! code: 0 1 2 3 0 . . . . 1 . . . . 2 . . . . 3 1 0 3 2 --> . . 3 . . . . 2 1 . . . . 0 . . ---+ 2 3 0 1 . . . 1 . . 0 . . 3 . . 2 . . . | 3 2 1 0 . 2 . . 3 . . . . . . 0 . . 1 . | | 0 1 2 3 0 . . . . 1 . . . . 2 . . . . 3 | 2 3 0 1 <-- . . 0 . . . . 1 2 . . . . 3 . . <--+ 3 2 1 0 . . . 0 . . 1 . . 2 . . 3 . . . 1 0 3 2 . 0 . . 1 . . . . . . 2 . . 3 .
code: 0 1 2 3 1 0 3 2 2 3 1 0 3 2 0 1
code: #!/usr/bin/env python # -*- coding: utf-8 -*- import itertools def cout_trans(cgrid,inds): ll=len(cgrid) bseq=['0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F'] for trow in range(ll): cme=' ' for tcol in range(ll): if inds[trow]==tcol: cme=cme+' '+bseq[cgrid[trow][tcol]] else: cme=cme+' .' print(cme) print('') return tgrid=[[0,1,2,3], [1,0,3,2], [2,3,1,0], [3,2,0,1]] dr=len(tgrid) tcount=0 for p in itertools.permutations(range(dr)): tset=set() for c in range(dr): tset.add( tgrid[c][p[c]] ) if len(tset)==dr: tcount=tcount+1 cout_trans(tgrid,p) print('tcount={}').format(tcount)
code: . . . . . 5 . . . . . . . . 7 . . . 0 . . . . . . 2 . . . . . . . . . . . . . 3 . . . . 1 . . . 6 . . . . . . . . . . 4 . . . . row=[0,1,2,3,4,5,6,7] col=[5,6,2,1,7,4,0,3] val=[5,7,0,2,3,1,6,4]
code: nrow=col ncol=val nval=row
|
Maniac (V) Mad Scientist From: |
posted 10-13-2017 00:20
Okay, let's do some 2d reduction kind of stuff to find code: 0 1 2 3 +-------- 0 | 0 1 2 3 1 | 1 0 3 2 2 | 2 3 0 1 3 | 3 2 1 0
code: val=[0] row=[0] col=[0] 1 2 3 +------ 1 | 0 3 2 2 | 3 0 1 3 | 2 1 0
code: val=[0,1] row=[0,2] col=[0,3] 1 2 +---- 1 | 0 3 3 | 2 1
code: val=[0,1,2] row=[0,2,3] col=[0,3,1] 2 +-- 1 | 3
code: val=[0,1,2,3] row=[0,2,3,1] col=[0,3,1,2] 0 . . . . . 3 . . . . 1 . 2 . .
code: 0 . . . . 2 . . . . 3 . . . . 1 0 1 2 3 3 2 1 0 1 0 3 2 2 3 0 1
code: 0 1 2 3 4 5 6 7 +---------------- 0 | 0 1 2 3 4 5 6 7 1 | 1 0 3 2 5 4 7 6 2 | 2 3 0 1 6 7 4 5 3 | 3 2 1 0 7 6 5 4 4 | 4 5 6 7 0 1 2 3 5 | 5 4 7 6 1 0 3 2 6 | 6 7 4 5 2 3 0 1 7 | 7 6 5 4 3 2 1 0
code: val=[0,1] row=[1,2] col=[1,3] 0 2 4 5 6 7 +------------ 0 | 0 2 4 5 6 7 3 | 3 1 7 6 5 4 4 | 4 6 0 1 2 3 5 | 5 7 1 0 3 2 6 | 6 4 2 3 0 1 7 | 7 5 3 2 1 0
code: val=[0,1,2,3] row=[1,2,5,6] col=[1,3,7,5] 0 2 4 6 +-------- 0 | 0 2 4 6 3 | 3 1 7 5 4 | 4 6 0 2 7 | 7 5 3 1
code: val=[0,1,2,3,4,5] row=[1,2,5,6,0,3] col=[1,3,7,5,4,6] 0 2 +---- 4 | 4 6 7 | 7 5
code: val=[0,1,2,3,4,5,6,7] row=[1,2,5,6,0,3,4,7] col=[1,3,7,5,4,6,2,0]
code: val=[0,1,2,3,4,5,6,7] row=[1,2,5,6,0,3,4,7] col=[1,3,7,5,4,6,2,0] . . . . 4 . . . . 0 . . . . . . . . . 1 . . . . . . . . . . 5 . . . 6 . . . . . . . . . . . . 2 . . . . . 3 . . 7 . . . . . . .
code: . . . . . . . 2 . . . . . . 5 . . . . . . 3 . . . . . . 4 . . . . . . 1 . . . . . . 6 . . . . . . 0 . . . . . . 7 . . . . . . . 5 4 7 6 1 0 3 2 3 2 1 0 7 6 5 4 6 7 4 5 2 3 0 1 0 1 2 3 4 5 6 7 2 3 0 1 6 7 4 5 4 5 6 7 0 1 2 3 1 0 3 2 5 4 7 6 7 6 5 4 3 2 1 0
code: 2 5 B C 7 0 E 9 8 F 1 6 D A 4 3
code: 02 11 23 30 0 1 2 3 2 1 3 0 13 00 32 21 1 0 3 2 3 0 2 1 20 33 01 12 2 3 0 1 0 3 1 2 31 22 10 03 3 2 1 0 1 2 0 3
|
Maniac (V) Mad Scientist From: |
posted 11-04-2018 00:11
Started writing again. Going to go over what I was talking about in the first again using code: 0 1 2 3 4 5 6 7 1 0 3 2 5 4 7 6 2 3 0 1 6 7 4 5 3 2 1 0 7 6 5 4 4 5 6 7 0 1 2 3 5 4 7 6 1 0 3 2 6 7 4 5 2 3 0 1 7 6 5 4 3 2 1 0
code: 0 2 4 6 3 1 7 5 1 3 5 7 2 0 6 4 2 0 6 4 1 3 5 7 3 1 7 5 0 2 4 6 4 6 0 2 7 5 3 1 5 7 1 3 6 4 2 0 6 4 2 0 5 7 1 3 7 5 3 1 4 6 0 2
code: [0,[2,4,3]] # starting number and XOR extend sequence [0]^2=[2] # xor with first [0,2] # extend [0,2]^4=[4,6] # xor with second [0,2,4,6] # extend [0,2,4,6]^3=[3,1,7,5] # xor with third [0,2,4,6,3,1,7,5] # extend
code: # re-index rows using [0,2,4,6,3,1,7,5] 0 1 2 3 4 5 6 7 2 3 0 1 6 7 4 5 4 5 6 7 0 1 2 3 6 7 4 5 2 3 0 1 3 2 1 0 7 6 5 4 1 0 3 2 5 4 7 6 7 6 5 4 3 2 1 0 5 4 7 6 1 0 3 2
code: # by index by value 0 . . . . . . . 0 . . . . . . . . . 3 . . . . . . . . 2 . . . . . . . . 6 . . . . . . . . . 4 . . . . . . . 5 . . . . . . 6 . . . . . 7 . . . . . . . . . . . 3 . 4 . . . . . . . . . . 1 . . . . . . . . . . 1 . 7 . . . . . . . . . . . 2 . . . . 5 . . . . .
code: 243 341 413 512 612 713 245 345 416 516 615 715 251 352 432 532 631 731 256 357 436 537 637 736 261 361 452 543 641 751 265 367 457 547 647 756 273 372 463 573 672 763 276 375 467 576 675 765
code: (0, [2, 4, 3], [0, 2, 4, 6, 3, 1, 7, 5]) (1, [2, 4, 3], [1, 3, 5, 7, 2, 0, 6, 4]) (2, [2, 4, 3], [2, 0, 6, 4, 1, 3, 5, 7]) (3, [2, 4, 3], [3, 1, 7, 5, 0, 2, 4, 6]) (4, [2, 4, 3], [4, 6, 0, 2, 7, 5, 3, 1]) (5, [2, 4, 3], [5, 7, 1, 3, 6, 4, 2, 0]) (6, [2, 4, 3], [6, 4, 2, 0, 5, 7, 1, 3]) (7, [2, 4, 3], [7, 5, 3, 1, 4, 6, 0, 2])
code: 238C 2483 2581 2681 2783 2815 2914 2A14 2B15 2C14 2D15 2E15 2F14 238D 2485 2586 2685 2786 2816 2917 2A17 2B16 2C17 2D16 2E16 2F17 238E 2489 2589 2689 2789 281C 291C 2A1C 2B1C 2C19 2D19 2E19 2F19 238F 248F 258E 268D 278C 281F 291F 2A1F 2B1F 2C1A 2D1A 2E1A 2F1A 239C 2491 2593 2693 2791 2834 2935 2A35 2B34 2C34 2D35 2E35 2F34 239D 2497 2594 2697 2794 2837 2936 2A36 2B37 2C37 2D36 2E36 2F37 239E 249A 259A 269A 279A 283D 293D 2A3D 2B3D 2C39 2D39 2E39 2F39 239F 249C 259D 269E 279F 283E 293E 2A3E 2B3E 2C3A 2D3A 2E3A 2F3A 23AC 24A1 25A3 26A3 27A1 2854 2954 2A54 2B54 2C51 2D51 2E51 2F51 23AD 24A7 25A4 26A7 27A4 2856 2956 2A56 2B56 2C53 2D53 2E53 2F53 23AE 24A9 25A9 26A9 27A9 285C 295D 2A5C 2B5D 2C5D 2D5C 2E5D 2F5C 23AF 24AF 25AE 26AD 27AC 285E 295F 2A5E 2B5F 2C5F 2D5E 2E5F 2F5E 23BC 24B3 25B1 26B1 27B3 2865 2965 2A65 2B65 2C61 2D61 2E61 2F61 23BD 24B5 25B6 26B5 27B6 2867 2967 2A67 2B67 2C63 2D63 2E63 2F63 23BE 24BA 25BA 26BA 27BA 286D 296C 2A6D 2B6C 2C6D 2D6C 2E6D 2F6C 23BF 24BC 25BD 26BE 27BF 286F 296E 2A6F 2B6E 2C6F 2D6E 2E6F 2F6E 23C4 24C1 25C1 26C1 27C1 2894 2985 2A94 2B85 2C81 2D91 2E91 2F81 23C5 24C7 25C6 26C5 27C4 2897 2986 2A97 2B86 2C83 2D93 2E93 2F83 23C6 24C9 25CA 26C9 27CA 289D 298D 2A9C 2B8C 2C8D 2D9C 2E9D 2F8C 23C7 24CF 25CD 26CD 27CF 289E 298E 2A9F 2B8F 2C8F 2D9E 2E9F 2F8E 23D4 24D3 25D3 26D3 27D3 28B5 29A4 2AB5 2BA4 2CB1 2DA1 2EA1 2FB1 23D5 24D5 25D4 26D7 27D6 28B6 29A7 2AB6 2BA7 2CB3 2DA3 2EA3 2FB3 23D6 24DA 25D9 26DA 27D9 28BC 29AC 2ABD 2BAD 2CBD 2DAC 2EAD 2FBC 23D7 24DC 25DE 26DE 27DC 28BF 29AF 2ABE 2BAE 2CBF 2DAE 2EAF 2FBE 23E4 24E3 25E3 26E3 27E3 28C5 29D5 2AD4 2BC4 2CD4 2DC5 2ED5 2FC4 23E5 24E5 25E4 26E7 27E6 28C7 29D7 2AD6 2BC6 2CD7 2DC6 2ED6 2FC7 23E6 24E9 25EA 26E9 27EA 28CD 29DC 2ADC 2BCD 2CD9 2DC9 2ED9 2FC9 23E7 24EF 25ED 26ED 27EF 28CF 29DE 2ADE 2BCF 2CDA 2DCA 2EDA 2FCA 23F4 24F1 25F1 26F1 27F1 28F4 29E4 2AE5 2BF5 2CF4 2DE5 2EF5 2FE4 23F5 24F7 25F6 26F5 27F4 28F6 29E6 2AE7 2BF7 2CF7 2DE6 2EF6 2FE7 23F6 24FA 25F9 26FA 27F9 28FC 29ED 2AED 2BFC 2CF9 2DE9 2EF9 2FE9 23F7 24FC 25FE 26FE 27FC 28FE 29EF 2AEF 2BFE 2CFA 2DEA 2EFA 2FEA
|
Paranoid (IV) Inmate From: cell 3736 |
posted 11-04-2018 16:35
Warjournals adventures into the wonderful world of mathematical patterns. |
Maniac (V) Mad Scientist From: |
posted 11-07-2018 13:37
I always assume that someone somewhere is listening. But it is good to hear for sure, Arthurio. Thank you. |
Maniac (V) Mad Scientist From: |
posted 11-07-2018 17:11
I got the important parts converted to numpy. code: F G g r 1 U a x 2 T d u C J f s U 1 x a G F r g J C s f T 2 u d j o 8 N Z y 6 P W / 5 Q k n B K y Z P 6 o j N 8 n k K B / W Q 5 B K k n 5 Q W / 6 P Z y 8 N j o Q 5 / W K B n k N 8 o j P 6 y Z f s C J d u 2 T a x 1 U g r F G u d T 2 s f J C r g G F x a U 1 7 O Y z 9 M i p A L l m 4 R X + M 9 p i O 7 z Y R 4 + X L A m l b w 0 V h q E H e t D I c v 3 S q h H E w b V 0 v c S 3 t e I D 3 S c v D I e t E H h q 0 V b w I D t e S 3 v c V 0 w b H E q h X + 4 R l m A L i p 9 M Y z 7 O m l L A + X R 4 z Y O 7 p i M 9
|
Maniac (V) Mad Scientist From: |
posted 11-10-2018 22:50
The first thing we are going to look at is two very particular latin code: 0 1 2 3 0 1 2 3 1 0 3 2 1 0 3 2 2 3 0 1 2 3 1 0 3 2 1 0 3 2 0 1
code: ..C C D D A 0 1 2 3 A 1 0 3 2 B 2 3 0 1 B 3 2 1 0
code: 0 1 2 3 0 3 2 1 1 0 3 2 1 2 3 0 2 3 0 1 3 0 1 2 3 2 1 0 2 1 0 3 First latin square flattened for rows: 0 1 2 3 1 0 3 2 2 3 0 1 3 2 1 0 Second latin square flattened for cols: 0 3 2 1 1 2 3 0 3 0 1 2 2 1 0 3
code: 0 1 2 3 1 0 3 2 2 3 0 1 3 2 1 0 0 3 2 1 1 2 3 0 3 0 1 2 2 1 0 3 00 13 22 31 11 02 33 20 23 30 01 12 32 21 10 03 0 6 A D 5 2 F 8 B C 1 6 E 9 4 3
code: |0 1 2 3 1 0 3 2 2 3 0 1 3 2 1 0 --+------------------------------- 0 |0 1 2 3 4 5 6 7 8 9 A B C D E F 3 |1 0 3 2 5 4 7 6 9 8 B A D C F E 2 |2 3 0 1 6 7 4 5 A B 8 9 E F C D 1 |3 2 1 0 7 6 5 4 B A 9 8 F E D C 1 |4 5 6 7 0 1 2 3 C D E F 8 9 A B 2 |5 4 7 6 1 0 3 2 D C F E 9 8 B A 3 |6 7 4 5 2 3 0 1 E F C D A B 8 9 0 |7 6 5 4 3 2 1 0 F E D C B A 9 8 3 |8 9 A B C D E F 0 1 2 3 4 5 6 7 0 |9 8 B A D C F E 1 0 3 2 5 4 7 6 1 |A B 8 9 E F C D 2 3 0 1 6 7 4 5 2 |B A 9 8 F E D C 3 2 1 0 7 6 5 4 2 |C D E F 8 9 A B 4 5 6 7 0 1 2 3 1 |D C F E 9 8 B A 5 4 7 6 1 0 3 2 0 |E F C D A B 8 9 6 7 4 5 2 3 0 1 3 |F E D C B A 9 8 7 6 5 4 3 2 1 0 0 |0 0 0 0 1 |1 1 1 1 --+------- --+------- 0 |0 5 A F 1 |2 7 8 D 0 |7 2 D 8 1 |5 0 F A 0 |9 C 3 6 1 |B E 1 4 0 |E B 4 1 1 |C 9 6 3 2 |2 2 2 2 3 |3 3 3 3 --+------- --+------- 2 |0 5 A F 3 |2 7 8 D 2 |7 2 D 8 3 |5 0 F A 2 |9 C 3 6 3 |B E 1 4 2 |E B 4 1 3 |C 9 6 3
code: |0 1 2 3 1 0 3 2 2 3 0 1 3 2 1 0 --+------------------------------- 0 |0 . . . . 5 . . . . A . . . . F 3 |. . . 2 . . 7 . . 8 . . D . . . 2 |. . 0 . . . . 5 A . . . . F . . 1 |. 2 . . 7 . . . . . . 8 . . D . 1 |. 5 . . 0 . . . . . . F . . A . 2 |. . 7 . . . . 2 D . . . . 8 . . 3 |. . . 5 . . 0 . . F . . A . . . 0 |7 . . . . 2 . . . . D . . . . 8 3 |. . . B . . E . . 1 . . 4 . . . 0 |9 . . . . C . . . . 3 . . . . 6 1 |. B . . E . . . . . . 1 . . 4 . 2 |. . 9 . . . . C 3 . . . . 6 . . 2 |. . E . . . . B 4 . . . . 1 . . 1 |. C . . 9 . . . . . . 6 . . 3 . 0 |E . . . . B . . . . 4 . . . . 1 3 |. . . C . . 9 . . 6 . . 3 . . .
code: 0 |0 0 0 0 --+------- 0 |0 5 A F 0 |7 2 D 8 0 |9 C 3 6 0 |E B 4 1 0=(0,0) 1=(0,15) 2=(7,5) 3=(9,10)
code: 0 1 2 3 4 5 6 7 8 9 A B C D E F F E D C B A 9 8 7 6 5 4 3 2 1 0 5 4 7 6 1 0 3 2 D C F E 9 8 B A A B 8 9 E F C D 2 3 0 1 6 7 4 5 E F C D A B 8 9 6 7 4 5 2 3 0 1 1 0 3 2 5 4 7 6 9 8 B A D C F E B A 9 8 F E D C 3 2 1 0 7 6 5 4 4 5 6 7 0 1 2 3 C D E F 8 9 A B D C F E 9 8 B A 5 4 7 6 1 0 3 2 2 3 0 1 6 7 4 5 A B 8 9 E F C D 8 9 A B C D E F 0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0 F E D C B A 9 8 3 2 1 0 7 6 5 4 B A 9 8 F E D C C D E F 8 9 A B 4 5 6 7 0 1 2 3 6 7 4 5 2 3 0 1 E F C D A B 8 9 9 8 B A D C F E 1 0 3 2 5 4 7 6
|
Maniac (V) Mad Scientist From: |
posted 11-13-2018 14:25
My Bamboo Fun was rendered useless several months ago. But, several days ago, my Intuos Art arrived. 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)) |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 11-13-2018 16:34
Regarding the print().format() - Python3, print is a function and returns None, |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 11-13-2018 16:36
(so what I think is happening is that the future-compability of 'print()' as a function is implemented |
Maniac (V) Mad Scientist From: |
posted 11-20-2018 01:36
I did do some looking into that, Ty. Thank you. Statement vs. Function. code: 0 1 7 6 5 4 3 2 2 3 0 1 6 7 5 4 4 5 3 2 1 0 7 6 6 7 4 5 2 3 1 0 3 2 5 4 7 6 0 1 5 4 6 7 0 1 2 3 7 6 1 0 3 2 4 5 1 0 2 3 4 5 6 7 3 4 5 7 1 2 6 0 2 5 4 6 0 3 7 1 7 0 1 3 5 6 2 4 6 1 0 2 4 7 3 5 4 7 3 5 6 1 0 2 5 6 2 4 7 0 1 3 0 3 7 1 2 5 4 6 1 2 6 0 3 4 5 7
code: 0 1 7 6 5 4 3 2 2 3 0 1 6 7 5 4 ... 3 4 5 7 1 2 6 0 2 5 4 6 0 3 7 1
|