12.05.2016, 14:16 |
Auf diesen Beitrag antworten » |
Haevelin |
Rätsel reduzieren
Wie kann ich zu folgendem Rätsel
H U N G E R 1 1 1
1 1 1 1 S 1 1 1 1
1 1 1 1 S 1 1 1 1
M A T S E 1 1 1 1
1 1 1 1 N E T T 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
ein Rätsel der Form
H U N G E R 1 1
1 1 1 1 S 1 1 1
1 1 1 1 S 1 1 1
M A T S E 1 1 1
1 1 1 1 N E T T
generieren? |
12.05.2016, 21:42 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
Indem du ein unschließendes Rechteck findest. Ermittle den kleinsten und größten x (/y) Wert, bei dem ein Buchstabe vorkommt. Erstelle dann ein neues Array und kopiere die Buchstaben, |
13.05.2016, 08:07 |
Auf diesen Beitrag antworten » |
Haevelin |
Das habe ich schon funktioniert, aber irgendwie hat sich hier ein Variablendreher eingeschlichen. Brauche das für eine Hausaufgabe. Wäre schön wenn der Code korrigiert wird.
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
|
public char[][] versteckt_ausgang(char[][] versteckt){
int x = 100;
int y = 100;
int a = 0;
int b = 0;
for (int j = 0; j < versteckt.length; j++) {
for (int h = 0; h < versteckt.length; h++) {
if (versteckt[j][h] != '1') {
if (h <= x) {
x = h;
y = j;
}
}
if ((h == versteckt.length - 1 && versteckt[j][h] !=
'1') || (h < versteckt.length - 1 && versteckt[j][h] != '1' && versteckt[j][h + 1] == '1')) {
if (h >= b) {
a = j;
b = h;
}
}
}
} // ende j
int zwischen=x;
x=y
; y=zwischen;
int x1 = 100;
int y1 = 100;
int a1 = 0;
int b1 = 0;
for (int j = 0; j < versteckt.length; j++) {
for (int h = 0; h < versteckt.length; h++) {
if (versteckt[h][j] != '1') {
if (h <= x1) {
y1 = h;
x1 = j;
}
}
if ((h == versteckt.length - 1 && versteckt[h][j] != '1') || (h < versteckt.length - 1 && versteckt[h][j] != '1' && versteckt[h + 1][j] == '1'))
{
if (h >= a1) {
b1 = h;
a1 = j;
}
}
}
} // ende j
System.out.println("Grenzpunkt "+x+" "+y);
System.out.println("Grenzpunkt "+a+" "+b);
System.out.println("Grenzpunkt "+x1+" "+y1);
System.out.println("Grenzpunkt "+a1+" "+b1);
Random rnd=new Random();
System.out.println("Erstes Chargrenze "+(b-y+1));
System.out.println("Zweite Chargrenze "+ (a1-x1+1));
char[][] versteckt_result= new char[a1-x1+1][b-y+1];
try{ for (int i=x1; i<a1+1;i++){
for (int j=y; j<b+1;j++){
if (versteckt[i][j]=='1'){
int z=rnd.nextInt(26)+65;
versteckt_result[i-x1][j-y]= (char) z;
}
else versteckt_result[i-x1][j-y]=versteckt[i][j];
}
}
} catch (Exception e) {
System.out.println(e.getMessage()); }
return versteckt_result; }
|
|
|
15.05.2016, 18:03 |
Auf diesen Beitrag antworten » |
Haevelin |
Ein verkleinerter Algorithmus, der aber immer noch nicht funktioniert:
public char[][] versteckt_ausgang(char[][] versteckt){
int x_links=100;
int y_links=100;
int x_rechts=0;
int y_rechts=0;
int x_oben=100;
int y_oben=100;
int x_unten=0;
int y_unten =0;
for (int i=0; i<versteckt.length; i++){
for (int j=0; j<versteckt.length; j++){
if (versteckt[i][j]!='1'){
if (j<y_links){
y_links=j;
x_links=i;
}
if (j>y_rechts){
y_rechts=j;
x_rechts=i;
}
if (i<x_oben){
x_oben=i;
y_oben=j;
}
if (i>x_unten){
x_unten=i;
y_unten=j;
}
}
}
}
System.out.println("Grenzpunkt "+x_links+" "+y_links);
System.out.println("Grenzpunkt "+x_rechts+" "+y_rechts);
System.out.println("Grenzpunkt "+x_oben +" "+y_oben);
System.out.println("Grenzpunkt "+x_unten+" "+ y_unten);
Random rnd=new Random();
char[][] versteckt_result= new char[x_unten-x_oben+1][y_rechts-y_links+1];
try{
for (int i=x_oben; i<x_unten+1;i++){
for (int j=y_rechts; j<y_links+1;j++){
if (versteckt[i][j]=='1'){
int z=rnd.nextInt(26)+65;
versteckt_result[i-x_oben][j-y_rechts]= (char) z;
} else versteckt_result[i-x_oben][j-y_rechts]=versteckt[i][j];
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return versteckt_result;
} |
15.05.2016, 18:30 |
Auf diesen Beitrag antworten » |
eulerscheZahl |
code: |
1:
2:
3:
4:
5:
6:
7:
8:
|
int x_links = 100;
int y_links = 100;
int x_rechts = 0;
int y_rechts = 0;
int x_oben = 100;
int y_oben = 100;
int x_unten = 0;
int y_unten = 0; |
|
Da fängt es schonmal an: um ein Rechteck zu beschreiben, reichen 4 Zahlen.
Ungetestet (ich habe keine Lust, eine Main Methode zum Testen zu schreiben, so weit müsstest du mir entgegenkommen):
code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
|
public char[][] versteckt_ausgang(char[][] versteckt) {
int xMin = 100;
int xMax = 0;
int yMin = 100;
int yMax = 0;
for (int y = 0; y < versteckt.length; y++) {
for (int x = 0; x < versteckt[0].length; x++) {
if (versteckt[y][x] != '1') {
xMin = Math.min(xMin, x);
xMax = Math.max(xMax, x);
yMin = Math.min(yMin, y);
yMax = Math.max(yMax, y);
}
}
}
Random rnd = new Random();
char[][] versteckt_result = new char[xMax - xMin + 1][yMax - yMin + 1];
for (int x = xMin; x <= xMax; x++) {
for (int y = yMin; y <= yMax; y++) {
if (versteckt[y][x] == '1') {
versteckt_result[y - yMin][x - xMin] = (char) (rnd.nextInt(26) + 65);
} else
versteckt_result[y - yMin][x - xMin] = versteckt[y][x];
}
}
return versteckt_result;
} |
|
|