'Error in function for generating elements stored in lattice structure
I'm trying to retrieve elements stored in lattice architecture as shown in the example:
- D=0 0/
- D=1 {1},{2},{3},{4}
- D=2 {1,2},{1,3},{1,4},{2,3},{2,4},{3,4}
- D=3 {1,2,3},{1,2,4},{1,3,4},{2,3,4}
- D=4 {1,2,3,4}
the function takes 3 inputs first one is the level of the lattice which corresponds to the size of the set returned second one is the number of profiles which defines the limit of the elements of the sets third one is the id of the set in the level
for example getmyset(2,4,0) will return the set that has id 0 in the level 2 which is {1,2}
the function works fine for most of the inputs but in some cases it returns false results for example getmyset(6,36,1258557) give: {35, 5, 8, 10, 11, 24} which is wrong
def getmyset(Ralpha=0,P=0, ID=0):
pool = list()
pool.append(1)
SOM=0
for j in range(1,Ralpha+1):
cSOM= SOM
k=0
while (cSOM <= ID):
SOM= cSOM
c=P-(pool[j-1]+(k))
d=Ralpha-(j)
e=c-d
f=math.factorial(c);
f=f//math.factorial(d)
f=f//math.factorial(e)
cSOM+=f
if(cSOM<=ID):
k=k+1
pool[j-1]= pool[j-1]+(k)
if(j-1<Ralpha-1):
pool.append(pool[j-1]+1)
set2= set();
for x in pool:
set2.add(x-1)
return set2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
