Created
February 28, 2013 23:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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