Guest User

Untitled

a guest
Dec 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. class letterCount {
  2.     public static void main(String[] args) {
  3.         int[] base = new int[10];
  4.         for(int i = 0; i < 10; i++) {
  5.             base[i] = -1;
  6.         }
  7.         long ret = getCount(base, 7);
  8.         System.out.println(ret);
  9.     }
  10.     private static boolean inArray(int needle, int[] haystack) {
  11.         for(int i : haystack) {
  12.             if(i == needle) {
  13.                 return true;
  14.             }
  15.         }
  16.         return false;
  17.     }
  18.     private static long getCount(int[] base, int maxrec) {
  19.         long count = 0;
  20.         int last = -1;
  21.         int curcount = 0;
  22.         int[] tbase = new int[10];
  23.         for(int j : base) { //Get length of array and last letter in it
  24.             if(j == -1) {
  25.                 break;
  26.             }
  27.             else {
  28.                 last = j;
  29.                 curcount += 1;
  30.             }
  31.         }
  32.         for (int i=0; i<26; i++) {
  33.             if(inArray(i, base)) {
  34.                 continue;
  35.             }
  36.             if(last != -1 && i != 0 && last == (i - 1)) {
  37.                 continue;
  38.             }
  39.             else {
  40.                 System.arraycopy(base, 0, tbase, 0, 10);
  41.                 tbase[curcount] = i;
  42.                 if(curcount == (maxrec - 1)) {
  43.                     count += 1;
  44.                 }
  45.                 else {
  46.                     count += getCount(tbase, maxrec);
  47.                 }
  48.             }
  49.         }
  50.         return count;
  51.     }
  52. }
Add Comment
Please, Sign In to add comment