私は、各セットの任意の数のアイテムの合計を含む、さまざまな基準に基づいて2つのデータセットを一致させる必要があるアプリケーションに取り組んでいます。私はこの問題を次のステートメントにまとめました。
アイテムとトランザクションのセットが与えられた場合、合計がトランザクションの最小セットの合計に等しい最小のアイテムセットを見つけます。(この投稿では無視している複雑さがいくつかありますが、今のところ、日付、説明、明確な違いなどではなく、一致する合計金額のみに関心があります。)
または、数学的に:2セットの数値が与えられた場合、合計が等しいそれぞれから最小のセットを見つけます。
私が遭遇した他の同様のSOの質問は、あなたが前もって合計を知っているか、あなたがしようとしている各セットからの量を知っていると仮定しています。
そして、これが(私が思うに)私が何をしようとしているのかを説明するテストです。
[TestMethod]
public void StackOverflowTest()
{
var seta = new[]{10, 20, 30, 40, 50};
var setb = new[]{ 45, 45, 100, 200 };
var result = Magic(seta, setb);
Assert.AreEqual(new[]{40,50},result.SetA);
Assert.AreEqual(new[] { 45, 45 }, result.SetB);
}
class MagicResult
{
public int[] SetA { get; set; }
public int[] SetB { get; set; }
}
private MagicResult Magic(int[] seta, int[] setb)
{
throw new NotImplementedException();
}
私はこのパスを作成するエレガントなソリューションを探していますが、そこに到達するための疑似コードや提案を受け取ります;)