Remove xrange in one example

This commit is contained in:
Thomas Nagy 2019-01-18 18:47:33 +01:00
parent 17e973a7d3
commit 3bf0e7049b
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
1 changed files with 8 additions and 8 deletions

View File

@ -43,20 +43,20 @@ def gen(lst, options):
LEN = len(lst)
POP = 3*LEN + 1
popul = [range(LEN) for x in xrange(POP)]
fitn = [0 for x in xrange(POP)]
popul = [range(LEN) for x in range(POP)]
fitn = [0 for x in range(POP)]
def rnd():
return random.randint(0, LEN -1)
def mutate():
for x in xrange(LEN):
for x in range(LEN):
# rotate the previous element by one
v = popul[x+LEN] = popul[x+LEN - 1]
a = v.pop(0)
v.append(a)
for x in xrange(LEN):
for x in range(LEN):
# swap elements
a = rnd()
b = rnd()
@ -66,7 +66,7 @@ def gen(lst, options):
v[a] = v[b]
v[b] = c
for x in xrange(LEN):
for x in range(LEN):
# get one element out, add at the end
v = popul[x+2*LEN]
@ -79,7 +79,7 @@ def gen(lst, options):
best = opti_ref
pos = -1
for x in xrange(len(popul)):
for x in range(len(popul)):
v = popul[x]
arr = [lst[a] for a in v]
tmp = '%s %s' % (cmd, ' '.join(arr))
@ -99,14 +99,14 @@ def gen(lst, options):
assert (sum(popul[x]) == sum(range(LEN)))
#print pos
for x in xrange(len(popul)):
for x in range(len(popul)):
if x == pos:
continue
popul[x] = popul[pos][:]
assert(len(popul[x]) == LEN)
return best
for i in xrange(10000):
for i in range(10000):
mutate()
print(evil())