Computerhilfen.de Logo
Forum
Tipps
News
Frage stellen

Aufgabe f. Jung-Programmierer

Die Aufgabe :


  DREI
+ DREI
+ VIER
------
  ZEHN



a) für die Buchstaben D - V sind die Ziffern 0 - 9 zu verwenden
b) E = 8
c) suche dir eine Prog-Sprache aus und schreibe den Findungs-Algorithmus
d) wir warten auf deine Lösung
 


Antworten zu Aufgabe f. Jung-Programmierer:

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button
Damits nicht so leicht wird, vielleicht in dieser *g*

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

I sag' nur BRAIN, BRAIN - dann wird's schon geh'n ;);D

 

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

Brute Force geht auch :) glaub ich jedenfalls, ausprobiert hab ich es nicht, das dauert mir zu lange...

package lisaa.main;

import java.math.BigInteger;

public class BruteForce {

private static final String operand1 = "DREI";
private static final String operand2 = "DREI";
private static final String operand3 = "VIER";

private static final String result = "ZEHN";

private static final BigInteger MAX = new BigInteger(
"99999999999999999999999999");

private static final BigInteger MILLION = new BigInteger(
"1000000");

public static void main(String [ ] args) {

BigInteger i = BigInteger.ZERO;

while (i.compareTo(MAX) != 1) {
i = i.add(BigInteger.ONE);
if (test(i)) {
return;
}
}
System.out.println("Keine Lösung");
}

private static boolean test(BigInteger integer) {

char[] dictionary = print(integer).toCharArray();

try {
if (integer.divideAndRemainder(MILLION)[1].equals(BigInteger.ZERO)) {
System.out.println(dictionary);
}
} catch (ArithmeticException e) {
// be quiet
}

String o1 = operand1;
String o2 = operand2;
String o3 = operand3;

String r = result;

int i = 65;

for (char c : dictionary) {
char x = (char)i;

if (x == 'E') {
c = '8';
}

o1 = o1.replace(x, c);
o2 = o2.replace(x, c);
o3 = o3.replace(x, c);
r = r.replace(x, c);
i++;
}

int i1 = Integer.valueOf(o1);
int i2 = Integer.valueOf(o2);
int i3 = Integer.valueOf(o3);
int i4 = Integer.valueOf(r);

if (i1 + i2 + i3 == i4) {

System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
System.out.println(i4);
return true;

}
return false;
}

private static String print(BigInteger integer) {
String s = integer.toString();
String rval = "";

for (int i = 0; i < (26 - s.length()); i++) {
rval += "0";
}
return rval + s;
}
}

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

also ich stell' mal mein Start-Bild bei Prog-Aufruf rein :

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

Hier der passende Suchalgorithmus; etwas abgespeckt und auf die Aufgabe zugeschnitten, dafür findet der auch in weniger als 2 Tagen ein paar Lösungen....

package lisaa.main;

public class BruteForce {

private static final String operand1 = "DREI";
private static final String operand2 = "DREI";
private static final String operand3 = "VIER";

private static final String result = "ZEHN";

private static final char[] characters =
{'D', 'E', 'H', 'I', 'N', 'R', 'V', 'Z'};

public static void main(String [ ] args) {

int i = 0;

while (i < 100000000) {
test(i);
i++;
}
}

private static boolean test(int integer) {

char[] dictionary = print(integer, 8).toCharArray();

String o1 = operand1;
String o2 = operand2;
String o3 = operand3;

String r = result;

for (int i = 0; i < characters.length; i++) {
char x = characters[i];
char c = dictionary[i];

if (x == 'E') {
c = '8';
}

o1 = o1.replace(x, c);
o2 = o2.replace(x, c);
o3 = o3.replace(x, c);
r = r.replace(x, c);

}

int i1 = Integer.valueOf(o1);
int i2 = Integer.valueOf(o2);
int i3 = Integer.valueOf(o3);
int i4 = Integer.valueOf(r);

if (i1 + i2 + i3 == i4) {

System.out.println(print(i1, 4));
System.out.println(print(i2, 4));
System.out.println(print(i3, 4));
System.out.println(print(i4, 4));
System.out.println("#######");
return true;

}
return false;
}

private static String print(int integer, int length) {
String s = String.valueOf(integer);
String rval = "";

for (int i = 0; i < (length - s.length()); i++) {
rval += "0";
}
return rval + s;
}
}


Zum Beispiel:

1684
1684
6486
9854
#######
1086
1086
0680
2852
#######
1086
1086
1680
3852
#######
1086
1086
2680
4852
#######
1086
1086
3680
5852
#######
1086
1086
4680
6852
#######
1086
1086
5680
7852
#######
1086
1086
6680
8852
#######
1086
1086
7680
9852
#######
1586
1586
0685
3857
#######
1586
1586
1685
4857
#######
1586
1586
2685
5857
#######
1586
1586
3685
6857
#######
1586
1586
4685
7857
#######
1586
1586
5685
8857
#######
1586
1586
6685
9857
#######
1488
1488
0884
3860
#######
1488
1488
1884
4860
#######
1488
1488
2884
5860
#######
1488
1488
3884
6860
#######
1488
1488
4884
7860
#######
1488
1488
5884
8860
#######
1488
1488
6884
9860
#######
1988
1988
0889
4865
#######
1988
1988
1889
5865
#######
1988
1988
2889
6865
#######
1988
1988
3889
7865
#######
1988
1988
4889
8865
#######
1988
1988
5889
9865
« Letzte Änderung: 12.09.09, 20:46:09 von Lisaa »

« C-Compiler // ClasspadProgrammieren lernen »
 

Schnelle Hilfe: Hier nach ähnlichen Fragen und passenden Tipps suchen!

Fremdwörter? Erklärungen im Lexikon!
Quellcode
Ein Quellcode, auch als Quelltext bekannt, bezeichnet den unkompilierten Programm-Code einer Software. Quell- oder Programm-Code ist der auch für Menschen lesbare Co...

Unicode
Unicode ist ein international anerkannter Standard, der als universeller Zeichencode ("Universal Code") dient und durch das Unicode-Konsortium entwickelt und verwaltet wi...

QR-Code
QR-Codes, die Abkürzung für "Quick Response Codes", sind eine Form von zweidimensionalen Barcodes. Damit lassen sich Informationen schnell und effizient speiche...