PRIME Quiz 2013 Praktische Proef

3742 days ago by J.Demeyer

blok1 = [(0,0,0), (1,0,0)] blok2 = [(0,0,0), (1,0,0), (0,1,0)] blok3 = [(0,0,0), (1,0,0), (0,1,0), (1,1,0)] blok4 = [(0,0,0), (1,0,0), (0,1,0), (0,2,0), (1,2,0)] blok5 = [(0,0,0), (1,0,0), (0,1,0), (1,1,0), (2,0,0), (0,2,0)] blok6 = [(0,0,0), (1,0,0), (0,1,0), (1,1,0), (2,0,0), (0,2,0), (1,2,0)] 
       
def rotxy(stuk): x,y,z = stuk return y,-x,z 
       
def rotyz(stuk): x,y,z = stuk return x,z,-y 
       
def addtocoord(stuk,c,a): s = list(stuk) s[c] += a return tuple(s) 
       
def configuraties(blok): S = None Snew = set([tuple(blok)]) # Roteren while Snew != S: S = copy(Snew) for bl in S: xyb = [rotxy(stuk) for stuk in bl] Snew.add(frozenset(xyb)) yzb = [rotyz(stuk) for stuk in bl] Snew.add(frozenset(yzb)) # Verschuiven per coordinaat for i in [0,1,2]: T = set() for bl in S: minx = min([stuk[i] for stuk in bl]) maxx = max([stuk[i] for stuk in bl]) for a in [-minx..2-maxx]: newbl = [addtocoord(stuk,i,a) for stuk in bl] T.add(frozenset(newbl)) S = T return frozenset(S) 
       
confs = [configuraties(b) for b in [blok1, blok2, blok3, blok4, blok5, blok6]] 
       
from collections import defaultdict D = defaultdict(list) 
       
for i in range(len(confs)): for j in range(len(confs)): if i == j: continue for bli in confs[i]: for blj in confs[j]: if bli.isdisjoint(blj): D[bli].append(blj) 
       
G = Graph(D) G 
       
Graph on 414 vertices
Graph on 414 vertices
C = G.cliques_maximum() 
       
def blokdist(bloka, blokb): d = 0 for stuka in bloka: for stukb in blokb: dist = (stuka[0]-stukb[0])^2 + (stuka[1]-stukb[1])^2 + (stuka[2]-stukb[2])^2 d += dist^2 return d 
       
def selfdist(blok): return blokdist(blok,blok) 
       
def distn(sol): n = 0 for bloka in sol: for blokb in sol: n += blokdist(bloka,blokb)^2 return n 
       
S = dict() for sol in C: S[distn(sol)] = sol L = S.values() len(L) 
       
13
13
blokcolors = {selfdist(blok4):'yellow', selfdist(blok1):'red', selfdist(blok6):'blue', selfdist(blok2):'green', selfdist(blok5):'white', selfdist(blok3):(1,0.5,0.5)} 
       
def showsolution(sol): P = Graphics() for blok in sol: for stuk in blok: P += cube(center=stuk, size=0.9, opacity=0.8, color=blokcolors[selfdist(blok)]) return P 
       
showsolution(L[0]) 
       
showsolution(L[1]) 
       
showsolution(L[2]) 
       
showsolution(L[3]) 
       
showsolution(L[4]) 
       
showsolution(L[5]) 
       
showsolution(L[6]) 
       
showsolution(L[7]) 
       
showsolution(L[8]) 
       
showsolution(L[9]) 
       
showsolution(L[10]) 
       
showsolution(L[11]) 
       
showsolution(L[12])