Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class letterCount {
- public static void main(String[] args) {
- int[] base = new int[10];
- for(int i = 0; i < 10; i++) {
- base[i] = -1;
- }
- long ret = getCount(base, 7);
- System.out.println(ret);
- }
- private static boolean inArray(int needle, int[] haystack) {
- for(int i : haystack) {
- if(i == needle) {
- return true;
- }
- }
- return false;
- }
- private static long getCount(int[] base, int maxrec) {
- long count = 0;
- int last = -1;
- int curcount = 0;
- int[] tbase = new int[10];
- for(int j : base) { //Get length of array and last letter in it
- if(j == -1) {
- break;
- }
- else {
- last = j;
- curcount += 1;
- }
- }
- for (int i=0; i<26; i++) {
- if(inArray(i, base)) {
- continue;
- }
- if(last != -1 && i != 0 && last == (i - 1)) {
- continue;
- }
- else {
- System.arraycopy(base, 0, tbase, 0, 10);
- tbase[curcount] = i;
- if(curcount == (maxrec - 1)) {
- count += 1;
- }
- else {
- count += getCount(tbase, maxrec);
- }
- }
- }
- return count;
- }
- }
Add Comment
Please, Sign In to add comment