Commit | Line | Data |
---|---|---|
81e70d48 PH |
1 | PROGRAM ROESSELSPRUNG(OUTPUT); |
2 | ||
3 | CONST N = 5; NSQ = 25; | |
4 | ||
5 | VAR I,J: INTEGER; | |
6 | FELD: ARRAY[1..N,1..N] OF INTEGER; | |
7 | A,B: ARRAY[1..8] OF INTEGER; | |
8 | ERFOLGREICH: BOOLEAN; | |
9 | ||
10 | ||
11 | PROCEDURE VERSUCH(I: INTEGER; X,Y: INTEGER); | |
12 | VAR K,U,V: INTEGER; | |
13 | BEGIN K := 0; | |
14 | REPEAT K:= K+1; | |
15 | U := X + A[K]; V := Y + B[K]; | |
16 | IF (1<=U) AND (U<=N) AND (1<=V) AND (V<=N) THEN IF FELD[U,V]=0 THEN | |
17 | BEGIN | |
18 | FELD[U,V] := I; | |
19 | IF I < NSQ THEN | |
20 | BEGIN | |
21 | VERSUCH(I+1,U,V); | |
22 | IF NOT ERFOLGREICH THEN FELD[U,V] := 0 | |
23 | END | |
24 | ELSE ERFOLGREICH := TRUE | |
25 | END | |
26 | UNTIL ERFOLGREICH OR (K=8) | |
27 | END (* VERSUCH *); | |
28 | ||
29 | BEGIN | |
30 | A[1] := 2; B[1] := 1; | |
31 | A[2] := 1; B[2] := 2; | |
32 | A[3] := -1; B[3] := 2; | |
33 | A[4] := -2; B[4] := 1; | |
34 | A[5] := -2; B[5] := -1; | |
35 | A[6] := -1; B[6] := -2; | |
36 | A[7] := 1; B[7] := -2; | |
37 | A[8] := 2; B[8] := -1; | |
38 | ||
39 | ERFOLGREICH := FALSE; | |
40 | FOR I := 1 TO N DO FOR J := 1 TO N DO FELD[I,J] := 0; | |
41 | ||
42 | FELD[1,1] := 1; VERSUCH(2,1,1); | |
43 | ||
44 | WRITELN("WEG DES SPRINGERS:"); WRITELN; | |
45 | IF ERFOLGREICH THEN | |
46 | FOR I := 1 TO N DO | |
47 | BEGIN | |
48 | FOR J := 1 TO N DO WRITE( FELD[I,J] :5); | |
49 | WRITELN | |
50 | END | |
51 | ELSE WRITELN("KEINE LOESUNG!") | |
52 | END. |