ref. http://ffcc626.blogspot.com/2018/04/blogger-code-highlighting.html & https://github.com/google/code-prettify for further info about the config
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
class SortingString {
public static void main(String args[]){
System.out.println("Start Time: " + new Date().toString()); //I wonder how long CompileBot goes for
String s = "typewriter";
int i = 0;
int iterationCount = 0;
for(i = 0; i <= Integer.MAX_VALUE && s != "eeiprrttwy"; i++){
s = randomSort(s);
if(i == Integer.MAX_VALUE - 1){
i = 0;
iterationCount++;
}
//if(i % 100000 == 0) //Prevent TOO much console spam... he.
//System.out.println(s); //Should probably disable this for CompileBot... hehe.
}
System.out.println("End Time: " + new Date().toString());
System.out.println(s);
System.out.println("Had " + iterationCount + " iterations over Integer.MAX_VALUE, with an ending i of " + i);
}
public static String randomSort(String x){
ArrayList chars = convertStringToArraylist(x);
Random rand = new Random();
String rtn = "";
while(rtn.length() < x.length()){
int pos = rand.nextInt(chars.size());
rtn += chars.get(pos);
chars.remove(pos);
}
return rtn;
}
沒有留言:
張貼留言