Table of Contents

Komentáře k programům

Generování permutací

 def init(self, glob, count):
        self.codename = "slozite_generovani"
        self.glob = glob
        self.test = count
        if count == 4:
            for a in range(6):
                for b in range(6):
                    for c in range(6):
                        for d in range(6):
                            self.S.append([a,b,c,d])
        if count == 5:
            for a in range(7):
                for b in range(7):
                    for c in range(7):
                        for d in range(7):
                            for e in range(7):
                                self.S.append([a,b,c,d,e])
        if count == 6:
            for a in range(8):
                for b in range(8):
                    for c in range(8):
                        for d in range(8):
                            for e in range(8):
                                for f in range(8):
                                    self.S2.append([a,b,c,d,e,f])   

Používání stringů ve formě čísel

if self.b1 == (self.b2-1):
   self.neni.append("0")
elif self.b2 == (self.b1-1):
   self.neni.append("6")

for i in self.neni:
    i = int(i)
    self.jes.remove(i)     

# pokud toRemove[i] = 0, pak i-ty prvek nechame, jinak ho smazeme
toRemove = [0] * len(self.jes)
 
# nasledujici kod nastavuje toRemove:
if self.b1 == (self.b2-1):
   toRemove[0] = 1
elif self.b2 == (self.b1-1):
   toRemove[6] = 1
 
# a tady jednoduse 'promazeme' jes tak, ze vztvorime nove pole:
jes2 = []
for i in range(len(jes2)):
   if toRemove[i] == 0:
      jes2.append(jes[i])   
jes = jes2
 
# a je to !

Podmínky na nesprávném místě

m = 0                                                                                      
for a in range(10):
    for b in range(100):
        for c in range(20):
            if not c == a:
                m += 1

cnt = 0
m = 0                                                                                      
for a in range(10):
    for b in range(100):
        for c in range(20):
            cnt +=1
            if not c == a:
                m += 1
print(m, cnt)

cnt = 0
m = 0                                                                                      
for a in range(10):
    for c in range(20):
        cnt += 1
        if not c == a:
            for b in range(100):
                m += 1
 
print(m, cnt)

Používání append pro pole předem známé délky

mask = [] 
for i in range(test):  # count black points and mark used position
  if (g[i]==tr[i]):
     black+=1
     mask.append(1)
  else:
     mask.append(0)

#pole nul
mask = [ 0 ] * len(test)
 
for i in range(test):  # count black points and mark used position
  if (g[i]==tr[i]):
     black+=1
     mask[i] = 1

Neopodstatnění continue

for i in range(len(cand)):
   tr = cand[i]
   res = mind.secondevaluate(self,gues,tr)
   if(b == res[0] and res[1] == w):
      newcand.append(tr)
      continue
   else:       
      continue

Neopodstatnění list

element = [0,0,0,0,0]
while(True):
   candidates.append(list(element))
   if(element[4]!=6):   
     element[4]+=1

Pozor na metodu index()

for i in range(self.n):
                if temp1[i] != '' and temp1[i] in temp2:
                    whitecounter += 1
                    temp2[temp2.index(temp1[i])] = ''
 

Hledani maxima

#maximum v radku
for i in range (len(matrix)):
    maximum=-1000000000000000000000000000000000000000000000000000000
    for j in range (len(matrix[i])):