dynamicke programovani:
{ pos = where is Mr. Black; lights = state of lights (0..2^10-1) } Type TState = Record pos: Integer; lights: Integer; End; Var Space : Array [1..MAXROOM, 0..(MAXCOMB-1)] of Integer; {try all possible moves from the given state} Procedure ExpandState (S: TState); Var I, C: Integer; SX: TState; Begin C := Space[S.pos, S.lights]; For I := 1 to MAXROOM do if Door[S.pos, I] and ((S.lights and GetBit(I)) <> 0) then Begin SX := S; SX.pos := I; EnqueueState (SX, C+1); End; For I := 1 to MAXROOM do If Light[S.pos, I] and (I<>S.pos) then Begin S.lights := S.lights xor GetBit(I); EnqueueState (S, C+1); S.lights := S.lights xor GetBit(I); End; End;