Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 04-25-2018, 02:27 PM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 492
Default Quick and simple function to go through a list and compare each vale to all previous

Basically if you had a list like this:

90 10 60 40 73 0 32 9 44 565 4 34 32 90 10 883 89 73 0 32 9 44 565 4 34 32 90 10 883 89 73 0 32 9 44 565 4 34 32 90 10 883 89 73 0 32 9 44 565 4 34 32 90 10 883 89 73 0 32 9 44 565 4 34 32 90 10 883 89 73 0 32 9 44 565

and you wanted to know how far apart each value is from the values proceeding it.. so output somthing like

#2:80
#3:50,30
#4:20,30,50

IE:
There are 80 numbers between 10-80

There are 50 numbers between 60-10
There are 30 numbers between 60-90

There are 20 numbers between 40-60
There are 30 numbers between 40-10
There are 50 numbers between 40-90 .. and so on..

My brain is mush this morning.. this shouldn't even require any thought.. its something I would nornally code on auto-pilot while mapping out the next section.. but grrrrr. Please send help!
__________________
"not quite smart enough to be dumb"
Extended Stats No Longer Available Due To Changes To The Forum.
  #2  
Old 04-25-2018, 10:01 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 313
Default

I'm not even sure I understand the question. What is the application ? May help to understand what you are doing.
  #3  
Old 04-26-2018, 10:53 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 841
Default

@Ouiji

Try this:
Code:
const
   Numbers: string = '90 10 60 40 73 0 38 9 44 565 4 34 31 90 10 883 89 73 0 32 ';

type
  TAI = array of Integer;

procedure ParseNumbers(ANumber: String; var AI: TAI);
var
  P: Integer;
  Len: Integer;
  Number: Integer;
  I: Integer;
begin
  repeat
     P := Pos(' ', ANumber);
     if (P > 0) then
     begin
       Number := StrToIntDef(Trim(Copy(ANumber, 1, P - 1)), -1000);
       if Number <> -1000 then
       begin
         Len := Length(AI);
         SetLength(AI, Len + 1);
         AI[Len] := Number;
       end;
       Delete(ANumber, 1, P);
       ANumber := TrimLeft(ANumber);
     end;
  until (ANumber = '') or (P = 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I, J: Integer;
  AI: TAI;
begin
  ParseNumbers(Numbers, AI);
  for I := Low(AI) + 1 to High(AI) do
    for J := I - 1 downto Low(AI) do
      Memo1.Lines.Add('There are ' + IntToStr(Abs(AI[I] - AI[J])) + ' between ' + IntToStr(AI[I]) + '-' + IntToStr(AI[J]))
end;
  #4  
Old 05-12-2018, 04:25 PM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 492
Thumbs up Thank YA

Thank you, that's pretty much exactly what I was looking for!
__________________
"not quite smart enough to be dumb"
Extended Stats No Longer Available Due To Changes To The Forum.
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 02:43 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.