1 | initial version |
There is a marvelous combinatorial class called IntegerListsLex
that returns an iterator (a type of python object that you can iterate over) for lists of integers subject to certain constraints. Try trying IntegerListsLex?
at the Sage command line to see the documentation.
Here is an iterator that I think does the job:
sage: L = IntegerListsLex(12, length=7, floor=[1]*7, ceiling=[9]*7)
sage: for i in L:
....: print i
....:
[6, 1, 1, 1, 1, 1, 1]
[5, 2, 1, 1, 1, 1, 1]
[5, 1, 2, 1, 1, 1, 1]
[5, 1, 1, 2, 1, 1, 1]
etc...
2 | No.2 Revision |
There is a marvelous combinatorial class called IntegerListsLex
that returns an iterator (a type of python object that you can iterate over) for lists of integers subject to certain constraints. Try trying entering IntegerListsLex?
at the Sage command line to see the documentation.
Here is an iterator that I think does the job:
sage: L = IntegerListsLex(12, length=7, floor=[1]*7, ceiling=[9]*7)
sage: for i in L:
....: print i
....:
[6, 1, 1, 1, 1, 1, 1]
[5, 2, 1, 1, 1, 1, 1]
[5, 1, 2, 1, 1, 1, 1]
[5, 1, 1, 2, 1, 1, 1]
etc...
3 | No.3 Revision |
There is a marvelous combinatorial class called IntegerListsLex
that returns an iterator (a type of python object that you can iterate over) for lists of integers subject to certain constraints. Try entering IntegerListsLex?
at the Sage command line to see the documentation.
Here is an iterator that I think does the job:
sage: L = IntegerListsLex(12, length=7, floor=[1]*7, ceiling=[9]*7)
sage: for i in L:
....: print i
....:
[6, 1, 1, 1, 1, 1, 1]
[5, 2, 1, 1, 1, 1, 1]
[5, 1, 2, 1, 1, 1, 1]
[5, 1, 1, 2, 1, 1, 1]
etc...
The Lex
part of the name indicates that the lists are returned in lexicographic order.
4 | No.4 Revision |
There is a marvelous combinatorial class called IntegerListsLex
that returns an iterator (a type of python object that you can iterate over) for lists of integers subject to certain constraints. Try entering IntegerListsLex?
at the Sage command line to see the documentation.
Here Below is an iterator that I think does the job:job. The length
parameter limits to sequences of length 7, the floor
parameter limits the integers to be larger or equal to 1, the ceiling
parameter limits the integers to be less or equal to 3.
sage: L = IntegerListsLex(12, length=7, floor=[1]*7, ceiling=[9]*7)
ceiling=[3]*7)
sage: for i l in L:
....: print i
l
....:
[6, 1, 1,
[3, 3, 2, 1, 1, 1, 1]
[5, 2, 1, 1, [3, 3, 1, 2, 1, 1, 1]
[5, 1, 2, 1, 1, [3, 3, 1, 1, 2, 1, 1]
[5, 1, 1, 2, 1, 1, [3, 3, 1, 1, 1, 2, 1]
etc...
The Lex
part of the name indicates that the lists are returned in lexicographic order.
Note that if you sort the sequences, convert to tuples (so that they are hashable), and then uniquify them you get the 3 basic sequences that generate the whole collection by reordering:
sage: L = IntegerListsLex(12, length=7, floor=[1]*7, ceiling=[3]*7)
sage: LS = [ tuple(sorted(i)) for i in L ]
sage: uniq(LS)
[(1, 1, 1, 1, 2, 3, 3), (1, 1, 1, 2, 2, 2, 3), (1, 1, 2, 2, 2, 2, 2)]
Update changed ceiling
option to limit the sequence to 1's, 2's, and 3's