Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package hexadec;
  2.  
  3. public class Hexadec
  4. {
  5.     public static final long MAX = 16;
  6.    
  7.     public static void main(String [] args)
  8.     {
  9.         System.out.println(Long.toHexString(GetPermutes(0, 0, 0, 0)).toUpperCase());
  10.     }
  11.    
  12.     public static long GetPermutes(int spos, int acount, int bcount, int ccount)
  13.     {
  14.         long total = 0;
  15.  
  16.         if (acount >= 1 && bcount >= 1 && ccount >= 1)
  17.         {  
  18.             long a = (MAX-spos);
  19.             long c = (long)Math.pow(13, (MAX-a) - (acount + bcount + ccount));
  20.             long t = 0;
  21.  
  22.             for (int i = 0; i <= a; i++)
  23.                 t += (long)Math.pow(16, i)*c;
  24.            
  25.             return t;
  26.         }
  27.        
  28.         if (spos == MAX) return 0;
  29.  
  30.         for (int i = 0; i < 4; i++)
  31.         {
  32.             if (spos == 0 && i == 0) continue;
  33.  
  34.             if (i == 0) {
  35.                 total += GetPermutes(spos+1, acount+1, bcount, ccount);
  36.             } else if (i == 2) {
  37.                 total += GetPermutes(spos+1, acount, bcount+1, ccount);
  38.             } else if (i == 3) {
  39.                 total += GetPermutes(spos+1, acount, bcount, ccount+1);
  40.             } else {
  41.                 total += GetPermutes(spos+1, acount, bcount, ccount);
  42.             }
  43.         }
  44.        
  45.         return total;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement