Talk:Ordered partitions: Difference between revisions
Content added Content deleted
(→Discarded code: new section) |
|||
Line 27: | Line 27: | ||
::::: Fair enough. Thank you. --13:15, 9 February 2011 (UTC) |
::::: Fair enough. Thank you. --13:15, 9 February 2011 (UTC) |
||
== Discarded code == |
|||
I wrote this code for [[Ruby]]. It seems to return the correct result, but the algorithm seems to be too slow, so I will not post it on the page. --[[User:Kernigh|Kernigh]] 04:13, 10 February 2011 (UTC) |
|||
<lang ruby>require 'set' |
|||
def partitions(*args) |
|||
(1..args.reduce(:+)).to_a.permutation.inject(Set[]) do |set, perm| |
|||
set << (args.inject([]) do |dist, arg| |
|||
dist.push(perm.shift(arg).to_set) |
|||
end) |
|||
end |
|||
end</lang> |