[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] Re: non random integer partition
Hello,
nop MagicWindow, what I want is something like
5 => (1, 1, 1, 1, 1) , (2, 1, 1, 1), (2, 2, 1), (3, 1, 1), (3, 2), (4, 1),
(5)
And as always, thank you Daniel, the enum tool is very useful :D !
But, in reality, my question stays : is it possible to "translate" the first
python func, which seems pretty similar to your function "g" in tutorial,
Daniel
g = { |a,n,ascending = true|
var p = 0!(n+1);
{ |x,i,col|
var order = ((i > 0) && ascending).if { x >= col[i-1] }{ true };
p[i+1] = p[i] + x;
order and: {
(i + 1 < n).if {
// check if partial sums are not too large
ascending.if { x }{ 1 } * (n - i) + p[i] <= a
}{
// partition check at last index i == n-1
p[i+1] == a
}
}
}
};
// Function for listing all partitions of number a with n summands
~partition = { |a,n,pool,ascending = true| n.enum(pool, g.(a,n,ascending),
true) };
but the python's one seems more direct, as it doesnt need your tool.
Is it a simple translation in SC ?
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/non-random-integer-partition-tp7622273p7622283.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/