Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Friday, June 04, 2004

Brute-force method of finding all permutations of five characters

Set permutations = new HashSet();
for (int i = 10000; i < 99999; i++) {
Set characters = new HashSet(Arrays .asList((i+"") .split("")));
characters .removeAll( Arrays .asList(("06789") .split("")));
if (characters .size() == 5) { permutations .add(i+""); }
}

0 Comments:

Post a Comment

<< Home