tags:

views:

124

answers:

3

how would i write a function in java that generates all the 3*3 multidimensional arrays such that every number between 1...9 only appears once?

thanks!

A: 

Note: this is not actually homework according to the OP.

How far have you gotten? It sounds like homework, and that is fine, SO will probably help, but you should show us how much you've done. SO is about making better programmers, so show us what you can do and we'll help out

Robert Gould
this isnt homework.
ok then, but I'm sure everyone will think so, so I'll leave this as a sign post
Robert Gould
+5  A: 

Basically, you are looking for all permutations of the series [1, 2, ... 9], but notice that you split them up to a matrix of 3x3.

It is easy to prove mathematically that the number of permutations is 9! (factorial 9).

There are many algorithms to generate permutations. Choose the one you find the most convenient. For example, at wikipedia.

Yuval A
You beat me to it!
Stephan202
toda...i am such an idiot. i will write a bijective function that will take an array of size 9 and turn it into a matrix... i was thinking of very complex things..btw do u learn in tel aviv university?
על לא דבר. No, I don't learn at TAU.
Yuval A
A: 

I'd start small, how would you do it for a 2*2 arrays? Do it manually - i.e. start to write down all the possible 2*2 arrays. How do you do it? Then think how you can do that in code. If you do it for a 2*2 you should be able to see if your results look good by eye so you'll know if you are on the right track.

This is basically a permutation problem, once you figure it out for small numbers the same solution should scale.

Steve Haigh