All pastes #422100 Raw Edit

Something

public text v1 · immutable
·published 2007-04-03 07:53 UTC
rendered paste body
function FindNextDirectionPos(Sequence: string): Integer;
var
  UPos, DPos, LPos, RPos, SoFarMinimum: Integer;
  LeaveOutFirstChar: string;
begin
  LeaveOutFirstChar:= copy(Sequence, 2, Length(Sequence));
  Writeln('Left out first char: ' + LeaveOutFirstChar);
  UPos:= pos('U', LeaveOutFirstChar);
  Writeln('Upos:= ' + IntToStr(UPos));
  DPos:= pos('D', LeaveOutFirstChar);
  Writeln('Dpos:= ' + IntToStr(DPos));
  LPos:= pos('L', LeaveOutFirstChar);
  Writeln('Lpos:= ' + IntToStr(LPos));
  RPos:= pos('R', LeaveOutFirstChar);
  Writeln('Rpos:= ' + IntToStr(RPos));
  if(not(UPos <= 0) and not(DPos <= 0))then
    begin
      Result:= Min(UPos, DPos);
      SoFarMinimum:= Min(UPos, DPos);
    end;
  Writeln('Current Result1:= ' + IntToStr(Result));
  if(not(UPos = 0) and not(LPos = 0))then
    if(SoFarMinimum >= Min(UPos, LPos))then
      begin
        Result:= Min(DPos, LPos);
        SoFarMinimum:= Min(DPos, LPos);
      end;
  Writeln('Current Result2:= ' + IntToStr(Result));
  if(not(UPos = 0) and not(RPos = 0))then
    if(SoFarMinimum >= Min(UPos, RPos))then
      begin
        Result:= Min(UPos, RPos);
        SoFarMinimum:= Min(UPos, RPos);
      end;
  Writeln('Current Result3:= ' + IntToStr(Result));
  if(not(DPos = 0) and not(LPos = 0))then
    if(SoFarMinimum >= Min(DPos, LPos))then
      begin
        Result:= Min(DPos, LPos);
        SoFarMinimum:= Min(DPos, LPos);
      end;
  Writeln('Current Result4:= ' + IntToStr(Result));
  if(not(DPos = 0) and not(RPos = 0))then
    if(SoFarMinimum >= Min(DPos, RPos))then
      begin
        Result:= Min(DPos, RPos);
        SoFarMinimum:= Min(DPos, RPos);
      end;
  Writeln('Current Result5:= ' + IntToStr(Result));
  if(not(LPos = 0) and not(RPos = 0))then
    if(SoFarMinimum >= Min(LPos, RPos))then
        Result:= Min(LPos, RPos);
    Writeln('Current Result6:= ' + IntToStr(Result));
end;

begin
  Writeln(inttostr(FindNextDirectionPos('U12DRL')));
end.