Skip to content

Instantly share code, notes, and snippets.

@mlc
Created January 6, 2016 05:38
Show Gist options
  • Save mlc/e8b4b9648ae018fb96b3 to your computer and use it in GitHub Desktop.
Save mlc/e8b4b9648ae018fb96b3 to your computer and use it in GitHub Desktop.
import com.google.common.base.Joiner;
import com.google.common.primitives.Ints;
import java.util.Arrays;
public class GrimePuz {
public static void main(String[] args) {
int[] n = new int[10];
int[] counts = new int[10];
n[0] = 1;
while (n[0] < 10) {
for (int i = 0; i < 10; ++i)
counts[i] = 0;
for (int i = 0; i < 10; ++i)
counts[n[i]]++;
if (Arrays.equals(n, counts)) {
System.out.println(Joiner.on("").join(Ints.asList(n)));
}
// move to the next number
n[9]++;
for (int j = 9; j >= 1 && n[j] == 10; j--) {
n[j] = 0;
n[j-1]++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment