Skip to content

Instantly share code, notes, and snippets.

@valtoni
Last active August 29, 2015 14:19
Show Gist options
  • Save valtoni/07d614a010c69807ccc5 to your computer and use it in GitHub Desktop.
Save valtoni/07d614a010c69807ccc5 to your computer and use it in GitHub Desktop.
public class Testa {
private static int fatorial(int numero) {
if (numero == 1)
return 1;
return numero * fatorial(--numero);
}
private static int combinacao(int n, int p) {
return fatorial(n) / (fatorial(n - p) * fatorial(p));
}
private static int arranjo(int n, int p) {
return fatorial(n) / fatorial(n - p);
}
private static int combinacaoSemRepeticao(int n, int p) {
return fatorial(n) - fatorial(p);
}
private static int[][] gerarCombinacoesDe3(int max) {
System.out.println("Combinações: " + (int) Math.pow(max - 1, 3));
int[][] c3 = new int[(int) Math.pow(max - 1, 3)][3];
int a, b, c;
int n = 0;
for (a = 0; a < max - 1; a++) {
for (b = 0; b < max - 1; b++) {
for (c = 0; c < max - 1; c++) {
c3[n++] = new int[] { a, b, c };
}
}
}
return c3;
}
private static double value11(int value) {
return Integer.parseInt("" + value, 11);
}
public static void main(String[] args) {
//double[] numeros = { 1, 1.3, 3, 3.5, 5, 5.7, 7, 7.9, 9, 9.11, 11, 11.13, 13, 13.15, 15 };
//double[] numeros = { 1, 3, 5, 7, 9, 11, 13, 15 };
double[] numeros = { value11(1), value11(3), value11(5), value11(7), value11(9), value11(11), value11(13), value11(15) };
double n1, n2, n3;
String saida = "";
for (int[] combinacao : gerarCombinacoesDe3(numeros.length)) {
n1 = numeros[combinacao[0]];
n2 = numeros[combinacao[1]];
n3 = numeros[combinacao[2]];
// System.out.format("%f + %f + %f = %f\n", n1, n2, n3, n1 + n2 + n3);
if (n1 + n2 + n3 == 30) {
saida += String.format("ACHADO!!! %f %f %f\n", n1, n2, n3);
}
}
System.out.println(saida.equals("") ? "Não encontrado" : saida);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment