0
$\begingroup$

I have a java array which contains four cells

A | B | C | D

Each cell can contain numbers 1-4, so for example:

1, 2, 3, 4

1, 1, 3, 4

1, 1, 1, 4

1, 1, 1, 1,

1, 1, 1, 2

And so on.

I'm trying to determine how many possible combinations there are, my algorithm is telling me over 200 and I'm not sure if there's a bug or that's the right number.

NOTE: Any number between 1 and 4 can occupy any of the cells, but there must be a number in each cell. So 1, 2, 3 is not a valid combination.

Thanks

$\endgroup$
5
  • $\begingroup$ Your exampes are all in ascending order -- is that a restriction, or can each cell independently contain any of the numbers $1$ to $4$? $\endgroup$
    – joriki
    Commented Mar 3, 2016 at 8:14
  • $\begingroup$ why not $4^4$? any restriction? $\endgroup$
    – Harry
    Commented Mar 3, 2016 at 8:15
  • $\begingroup$ any number, no restriction $\endgroup$ Commented Mar 3, 2016 at 8:17
  • $\begingroup$ there is a restriction, I edited. There must be a number in each cell. $\endgroup$ Commented Mar 3, 2016 at 8:23
  • $\begingroup$ There are $4^4$ combinations, you don't need any algorithm for that. $\endgroup$ Commented Mar 3, 2016 at 8:27

1 Answer 1

1
$\begingroup$

By the rule of product, there are $4\cdot4\cdot4\cdot4=4^4=256$ different ways to fill the cells.

$\endgroup$
1
  • $\begingroup$ Seems legit, thanks. $\endgroup$ Commented Mar 3, 2016 at 8:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .