[英]Function to return number partitions
我正在尋找一個返回整數分區的函數。 在這個問題中,我幾乎找到了我想要的:
此函數顯示整數的分區。 但是,如何更改它以實際存儲和返回所有分區(也許在列表中)?
我知道Java具有combinatoricslib
。 C#中是否有類似的東西? 如果沒有,如何使該函數返回所有可能的分區?
您提供的鏈接只是打印結果,但是您希望返回結果。 最好的方法可能是在“打印”方法中添加一個額外的“結果收集器”參數,然后將該方法添加到收集器中,而不是打印每個分區。
根據您的需求,您的收集器將是以下之一:
// Each partition is a string of the numbers, like when printed
List<String> partitions;
// Each partition is a list of the numbers
List<List<Integer>> partitions;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.