[Lazarus] some number manipulation

appjaws lazarus at appjaws.plus.com
Sat Mar 9 16:06:51 CET 2013


On 09/03/13 12:11, Howard Page-Clark wrote:
> On 09/03/13 11:12, appjaws wrote:
>> Hi all,
>> I have a series of results, for each day of the month I have 10 numbers
>> ranging from 1 to 20. i.e.
>> Day1    1,3,4,5,7,9,12,16,17,20
>> Day2    3,4,5,6,8,9,15,17,18,19
>> etc.
>>
>> Question 1 how can I find the number of 1's 2's 3's 4's etc. for the
>> whole month series?
>>
>> Question 2 How can I test for 3 or more consecutive numbers in each day?
>
> Q1 for such a small dataset a brute force approach of iterating over all
> values and counting each occurrence of 1, 2, 3 etc. in 20 distinct
> counters seems best.
>
> Q2 Your data is ordered by value, so a function along these lines ought
> to work:
>
> type
>    TNumber = 1..20;
>    TDayData = array[1..10] of TNumber;
>
> function ThreeOrMoreConsecutiveNos(dd: TDayData): boolean;
> var i: integer=1;
> begin
>   Result:= False;
>   while i <=8 do
>    begin
>      if ( dd[i]=Pred(dd[i+1]) )
>       and ( dd[i+1]=Pred(dd[i+2]) )
>      then Exit(True);
>      Inc(i);
>    end;
> end;

Thank you Howard,
I just realised that I need to sort the numbers because they are not 
like my example above. So where and how would I sort the array for each 
Day and then call ThreeOrMore?

I'm still learning and really appreciate your help
Paul


-- 
---This message has been sent using Thunderbird on kubuntu---




More information about the Lazarus mailing list