im splitting a string by the square number of his length..
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int a = alphabet.length();
int b = (int)Math.round(Math.sqrt(a));
System.out.println(java.util.Arrays.toString(splitter(key, b)));
// prints: [ABCDE, FGHIJ, KLMNO, PQRST, UVWXY, Z]
The splitter function:
public static String[] splitter(String s, int len) {
return s.split(String.format("(?<=\\G.{%1$d})", len));
}
What i want now is to sort it diagonal like this:
[0] = {A,B,D,G,K}
[1] = {C,E,H,L,P}
[2] = {F,I,M,Q,U}
[3] = {J,N,R,V,Y}
[4] = {O,S,W,Z,0}
[5] = {T,X,0,0,0}
I was trying to solve it with some loops by checking always if (i-1) >= i... but i get confused and kinda lost in here..