martes, 13 de marzo de 2012

Project Euler 38

public class Problema38 {
 static boolean isPandigital(String num){
  if(num.length()!=9)
   return false;
  for (int i = 1; i < 10; i++) 
   if(!num.contains(""+i))
    return false;
  return true;
 }
 public static void main(String[] args) {
  String max = "123456789";
  for (int i = 9; i < 10000; i++) {
   int m = 1;
   String sol = "";
   while(sol.length()<9){
    sol += (i*m);
    m++;
   }
   if(sol.length()==9)
    if(isPandigital(sol))
     if(sol.compareTo(max)>0)
      max = sol;
  }
  System.out.println(max);
 }
}

No hay comentarios:

Publicar un comentario