home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
ddjmag
/
ddj8708.arc
/
BOWMAN.EXP
< prev
next >
Wrap
Text File
|
1987-08-12
|
2KB
|
101 lines
1: bktkfind( node )
2: begin
3: if( node = SUCCESS )
4: then
5: return( I_FOUND_IT )
6: endif
7: for( each_choice_at_this_node )
8: do
9: ret_stat = bktkfind( child_node )
10: if( ret_stat = SUCCESS )
11: then
12: return( ret_stat )
13: endif
14: done
15: return( FAIL )
16: endproc
Example 1: Pseudocode for a chronological backtracking function
@puzzle
----
$-$- (`$' = Blank)
----
-$$-
@words
best
tamp
tops
era
to
Example 2: Sample input
best
$r$o (`$' = Blank)
tamp
o$$s
Example 3: Sample output
1: posn := [];
2: (forall j in [ 1..8 ])
3: { j : j in [ 1..8 ] | OK }
4: unattacked := { 1..8 } - { posn(k) + (j-k)*slope
5: : k in [ 1..j-1 ],
6: slope in [ -1..+1 ] }
7: if( unattacked = {} )
8: then
9: FAIL;
10: else
11: posn(j) := ord unattacked;
12: endif;
13: end forall;
14: print( posn );
Example 4: Eight queens problem
1: solve( length, width )
2: int length, width;
3: {
4: int l, w, i, len, tmp, type;
5: char old[ WORDLEN - MINWORD + 1 ];
6:
7: w = width;
8: l = length;
9: len = next( &l, &w, &type );
10: if( len == 0 )
11: return( SOLVED );
12:
13: for(i = 0;i<MAXWORD&&WORD(len,i)[0]!=NIL;i++){
14: if( FLAG(len, i) == FREE
15: && itfits(l, w, WORD(len, i), type) ){
16: FLAG(len, i) = USED;
17: enter(old, l, w, WORD(len,i), type);
18: prev = type;
19: tmp = solve( l, w );
20: if( tmp == SOLVED )
21: return( SOLVED );
22: restore( old, l, w, type );
23: FLAG(len, i) = FREE;
24: }
25: }
26:
27: return( 0 );
28: }
Example 5: The function solve().