Statistics

Problem Statement for "MNS"

Problem Statement

9 numbers need to be arranged in a magic number square. A magic number square is a square of numbers that is arranged such that every row and column has the same sum. For example:

1 2 3
3 2 1
2 2 2

Create a class MNS containing a method combos which takes as an argument a int[] numbers and returns the number of distinct ways those numbers can be arranged in a magic number square. Two magic number squares are distinct if they differ in value at one or more positions. For example, there is only one magic number square that can be made of 9 instances of the same number.

Definition

Class:
MNS
Method:
combos
Parameters:
int[]
Returns:
int
Method signature:
int combos(int[] numbers)
(be sure your method is public)

Notes

  • Unlike some versions of the magic number square, the numbers do not have to be unique.

Constraints

  • numbers will contain exactly 9 elements.
  • each element of numbers will be between 0 and 9, inclusive.

Examples

  1. {1,2,3,3,2,1,2,2,2}

    Returns: 18

  2. {4,4,4,4,4,4,4,4,4}

    Returns: 1

  3. {1,5,1,2,5,6,2,3,2}

    Returns: 36

  4. {1,2,6,6,6,4,2,6,4}

    Returns: 0

  5. {1,2,3,4,5,6,7,8,9}

    Returns: 72

  6. {4,4,4,4,4,4,3,3,3}

    Returns: 6

  7. {3,2,6,2,3,5,2,6,7}

    Returns: 0

  8. {2,6,2,8,9,9,5,7,6}

    Returns: 0

  9. {4,6,4,3,5,6,3,5,3}

    Returns: 0

  10. {0,0,0,0,9,0,0,0,0}

    Returns: 0

  11. {0,0,0,3,3,3,0,0,0}

    Returns: 6

  12. {1,2,3,1,2,3,1,2,3}

    Returns: 12

  13. {1,2,3,4,5,6,7,8,0}

    Returns: 72

  14. {3,4,3,4,3,4,5,5,5}

    Returns: 12

  15. {0,2,4,6,8,2,4,6,8}

    Returns: 0

  16. { 4, 4, 5, 6, 7, 8, 9, 2, 3 }

    Returns: 72

  17. { 1, 2, 3, 4, 5, 6, 7, 8, 9 }

    Returns: 72

  18. { 1, 4, 2, 3, 1, 4, 5, 6, 7 }

    Returns: 0

  19. { 1, 5, 1, 2, 5, 6, 2, 3, 2 }

    Returns: 36

  20. { 4, 4, 4, 4, 6, 2, 4, 2, 6 }

    Returns: 18

  21. { 4, 4, 4, 4, 4, 4, 4, 4, 5 }

    Returns: 0

  22. { 1, 1, 1, 1, 1, 1, 1, 1, 4 }

    Returns: 0

  23. { 2, 1, 1, 1, 2, 1, 1, 1, 2 }

    Returns: 6


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: