Skip to main content
Code Review

Return to Answer

added 169 characters in body
Source Link
Joop Eggen
  • 4.5k
  • 15
  • 19

Unfortunately I would reconsider the algorithm a bit further.

A multiple of 3 is characterized by a useful rule:

A number is divisible by 3 if the sum of its digits is divisible by 3.

This means that for {2, 3, 6}, {2, 6}, {2, 3} any combination will fail.

So bags (unordered list of possible repeated elements) is the way to go: loop over all bags.

The maximum value is given by the bag with most elements, the digits in decreasing order.

For a set of size n the number of combinations are 2n, if not considering 0. For a bag this is different: 6a06b3 = 6b06a3. Given different digits di with frequency fi the total number of combinations is (Σi fi)! / Πj(fj!)

  • case of 0
  • number of occurences of some digit

I leave the joy of a formula to you.

The example data to check:

3, 6, 2, 36, 63, 62, 26, 32, 23, 236, 263, 326, 362, 623, 632

Unfortunately I would reconsider the algorithm a bit further.

A multiple of 3 is characterized by a useful rule:

A number is divisible by 3 if the sum of its digits is divisible by 3.

This means that for {2, 3, 6}, {2, 6}, {2, 3} any combination will fail.

So bags (unordered list of possible repeated elements) is the way to go: loop over all bags.

The maximum value is given by the bag with most elements, the digits in decreasing order.

For a set of size n the number of combinations are 2n, if not considering 0. For a bag this is different: 6a06b3 = 6b06a3.

  • case of 0
  • number of occurences of some digit

I leave the joy of a formula to you.

The example data to check:

3, 6, 2, 36, 63, 62, 26, 32, 23, 236, 263, 326, 362, 623, 632

Unfortunately I would reconsider the algorithm a bit further.

A multiple of 3 is characterized by a useful rule:

A number is divisible by 3 if the sum of its digits is divisible by 3.

This means that for {2, 3, 6}, {2, 6}, {2, 3} any combination will fail.

So bags (unordered list of possible repeated elements) is the way to go: loop over all bags.

The maximum value is given by the bag with most elements, the digits in decreasing order.

For a set of size n the number of combinations are 2n, if not considering 0. For a bag this is different: 6a06b3 = 6b06a3. Given different digits di with frequency fi the total number of combinations is (Σi fi)! / Πj(fj!)

  • case of 0
  • number of occurences of some digit

I leave the joy of a formula to you.

The example data to check:

3, 6, 2, 36, 63, 62, 26, 32, 23, 236, 263, 326, 362, 623, 632
Source Link
Joop Eggen
  • 4.5k
  • 15
  • 19

Unfortunately I would reconsider the algorithm a bit further.

A multiple of 3 is characterized by a useful rule:

A number is divisible by 3 if the sum of its digits is divisible by 3.

This means that for {2, 3, 6}, {2, 6}, {2, 3} any combination will fail.

So bags (unordered list of possible repeated elements) is the way to go: loop over all bags.

The maximum value is given by the bag with most elements, the digits in decreasing order.

For a set of size n the number of combinations are 2n, if not considering 0. For a bag this is different: 6a06b3 = 6b06a3.

  • case of 0
  • number of occurences of some digit

I leave the joy of a formula to you.

The example data to check:

3, 6, 2, 36, 63, 62, 26, 32, 23, 236, 263, 326, 362, 623, 632
default

AltStyle によって変換されたページ (->オリジナル) /