python soliton_config.py
path [ 20 ]: [1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 2, 2, 1]
type: 20
4 *** 0
6 ** 5
6 ** 4
12 * 7
path [ 21 ]: [1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2]
type: 21
5 *** 3
7 ** 7
7 ** 6
13 * 8
path [ 23 ]: [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2]
type: 23
7 *** 6
9 ** 9
9 ** 8
15 * 9
path [ 25 ]: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2]
type: 25
9 *** 9
11 ** 11
11 ** 10
17 * 10
path [ 28 ]: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2]
type: 28
12 *** 12
14 ** 13
14 ** 12
20 * 11
path [ 31 ]: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2]
type: 31
15 *** 15
17 ** 15
17 ** 14
23 * 12
path [ 34 ]: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2]
type: 34
18 *** 18
20 ** 17
20 ** 16
26 * 13
path [ 37 ]: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2]
type: 37
21 *** 21
23 ** 19
23 ** 18
29 * 14
#!/usr/bin/python
class YoungDiagram:
def __init__(self):
self.shape = []
def depth(self):
return len(self.shape)
def total(self):
return sum(self.shape)
def transpose_shape(self):
list = []
for i in range(self.shape[0]):
list.append(len(filter(lambda x: x>i, self.shape)))
return list
def first(self):
if len(self.shape) == 0:
return 0
return self.shape[0]
def m(self,j):
return len(filter(lambda x: x == j, self.shape))
def q(self, j):
if len(self.shape) == 0:
return 0
s = 0
for k in range(self.shape[0]+1):
s += min(j, k)*self.m(k)
return s
def __str__(self):
for i in self.shape:
print "\t","*"*i
return ""
# n=1 type(1^L) only
class Configuration:
def __init__(self):
self.type = 0
self.u1 = YoungDiagram()
self.update_vacancy()
self.rigging = []
def p(self, j):
return self.type - 2 * self.u1.q(j)
def update_vacancy(self):
self.vacancy = []
list = []
for j in range(self.u1.first()+1):
list.append(self.p(j))
for j in self.u1.shape:
self.vacancy.append(list[j])
def sort_rigging(self):
i = 0
while i < len(self.u1.shape):
l = len(filter(lambda x: x == self.u1.shape[i], self.u1.shape))
self.rigging[i:i+l] = sorted(self.rigging[i:i+l], reverse=True)
i += l
def singular_test(self):
list = []
for i in range(len(self.vacancy)):
list.append(self.vacancy[i] == self.rigging[i])
return list
def add_1(self):
self.type += 1
self.update_vacancy()
def add_2(self):
list = self.singular_test()
try:
i = list.index(True) # index of a singular string
self.type += 1
self.u1.shape[i] += 1 # extend the singular string
m = map(lambda x: x < self.u1.shape[i] , self.u1.shape)
try:
j = m.index(True)
if j < i:
self.u1.shape[i],self.u1.shape[j] =self.u1.shape[j],self.u1.shape[i]
self.rigging[i],self.rigging[j] = self.rigging[j],self.rigging[i]
i = j
except ValueError:
0 #nothing to do
self.update_vacancy()
self.rigging[i] = self.vacancy[i]
except ValueError: # no singular string, add 1-string
self.type += 1
self.u1.shape.append(1)
self.update_vacancy()
try:
i = self.u1.shape.index(1)
self.rigging.insert(i, self.vacancy[-1])
except ValueError:
self.rigging.append(self.vacancy[-1])
self.sort_rigging()
def add(self, list):
c = 0
self.path = list
for v in list:
if v == 1:
self.add_1()
else:
self.add_2()
c+= 1
def __str__(self):
print "path [", len(self.path),"]:",self.path
print "type:",self.type
for i in range(len(self.vacancy)):
print "\t",self.vacancy[i], "*"*self.u1.shape[i], self.rigging[i]
return ""
def move(l, ball):
while True:
try:
n = l.index(ball)
l[n] = 'done'
m = l[n+1:]
try:
n2 = m.index(1)
m[n2] = 'new'
except ValueError:
m.append('new')
l[n+1:] = m
except ValueError:
break
for i in range(len(l)):
if l[i] == 'new':
l[i] = ball
elif l[i] == 'done':
l[i] = 1
##test
l=[1,1,1,2,2,2,1,1,1,1,2,1,2,2,1,1,1,2,2,1]
for i in range(8):
c = Configuration()
c.add(l)
print c
move(l, 2)
0 件のコメント:
コメントを投稿