Skip to content

Instantly share code, notes, and snippets.

@joriki
Created February 28, 2013 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joriki/5061210 to your computer and use it in GitHub Desktop.
Save joriki/5061210 to your computer and use it in GitHub Desktop.
Count the number of surface paths from a vertex to the opposite vertex of a Rubik's Cube; see http://math.stackexchange.com/questions/317288.
public class Question317288 {
final static int d = 3;
final static int n = 3;
final static int [] state = new int [d];
static int count;
public static void main (String [] args) {
recurse ();
System.out.println (count);
}
static void recurse () {
int count0 = 0;
int countn = 0;
for (int i = 0;i < d;i++) {
if (state [i] == 0)
count0++;
else if (state [i] == n)
countn++;
}
if (countn == d)
count++;
else if (count0 + countn > 0)
for (int i = 0;i < d;i++)
if (state [i] < n) {
state [i]++;
recurse ();
state [i]--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment