/**
* print all binary from zero to num-1 with length log2(num)
* @param num maximum number
*/
public static void printAllBinary(int num) {
String str = "";
int binLen = (int)Math.ceil(Math.log(num)/Math.log(2));
for(int j=0; j<num; j++){
int n = j;
for(int i=0; i<binLen; i++){
if(n % 2 == 0)
str = "0" + str;
else
str = "1" + str;
n = n/2;
}
Print.plb(str);
str = "";
}
}
// [1 -> 26] = ['A' -> 'Z']
// [0 -> 25] ['A' -> 'Z']
public static void excelNumSaveLength(int num) {
int binLen = 1;
if(num == 1)
binLen = 1;
else
binLen = (int)Math.ceil(Math.log(num)/Math.log(26));
for(int j=1; j<=num; j++){
int n = j;
String str = "";
for(int i=1; i<=binLen; i++){
String s = Aron.intToAlphabetUpper((n-1)%26);
str = s + str;
n = (n-1)/26;
}
Print.plb(str);
}
}
// [1 -> 26] = ['A' -> 'Z']
// [0 -> 25] ['A' -> 'Z']
public static void printExcel(int num){
int base = 26;
for(int i=1; i<=num; i++){
int x = i;
String str = "";
if(x-1 == 0)
str = 'A' + str;
else{
while( x > 0){
int r = (x-1) % base;
String s = Aron.intToAlphabetUpper(r);
str = s + str;
x = (x-1) / base;
}
}
Print.plb(str);
}
}