Recent

Author Topic: Need help with finding the lowest number  (Read 14814 times)

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Need help with finding the lowest number
« Reply #15 on: October 22, 2016, 06:00:47 pm »
btw: I need help with my FREE PASCAL - PHOTOSHOP version... so if you don't mind ...

First try....

Code: Pascal  [Select][+][-]
  1. PROGRAM FPC_PHOTOSHOP;
  2.  {$mode objfpc}{$H+}
  3.  
  4.  USES
  5.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  6.   cthreads,
  7.   {$ENDIF}{$ENDIF}
  8.   sysutils, process;
  9.  
  10.   {$R *.res}
  11.  
  12. var
  13.   PS: TProcess;
  14. Begin
  15.   PS := TProcess.Create;
  16.   try
  17.     {$ifdef windows}
  18.     PS.Executable := 'photoshop.exe';
  19.     {$else}
  20.     PS.Executable := 'gimp';
  21.     {$endif}
  22.     PS.Execute;
  23.   finally
  24.     PS.Free;
  25.   end;
  26. End.    
  27.  

Bart
« Last Edit: October 22, 2016, 06:02:47 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Need help with finding the lowest number
« Reply #16 on: October 22, 2016, 06:53:14 pm »
Sorry, but my first try for the original problem did not parse the Options (TNumberFileOptions) at all.
Fixed setter of Options as well.

Here's a corrected version.

Code: Pascal  [Select][+][-]
  1. program nf;
  2.  
  3. {$mode objfpc}
  4. {$H-}  //don't need ansistrings
  5.  
  6. uses
  7.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  8.   cthreads,
  9.   {$ENDIF}{$ENDIF}
  10.   Classes, SysUtils;
  11.  
  12. {$R *.res}
  13.  
  14. {.$DEFINE DEBUG}
  15. {.$DEFINE TEST}
  16.  
  17. type
  18.   TNumberFileOption = (nfoFirstValueIsNrOfLines, nfoSecondValueIsCount);
  19.   TNumberFileOptions = set of TNumberFileOption;
  20.   TSolution = (solLowest, solHighest);
  21.   TSolutions = set of TSolution;
  22.  
  23.   { TNumberFileStream }
  24.  
  25.   TNumberFileStream = class
  26.   private
  27.     FOptions: TNumberFileOptions;
  28.     FList: TList;
  29.     FExpectedNrOfLines: Integer;
  30.     FRealNrOfLines: Integer;
  31.     FExpectedCount: Integer;
  32.     FSolutions: TSolutions;
  33.     procedure SetOptions(AValue: TNumberFileOptions);
  34.     procedure Scan(AStream: TStream);
  35.     procedure AddToList(L: PtrInt);
  36.     procedure CheckFileValidity;
  37.     function CountLineEndings(S: String): Integer;
  38.     function Count: Integer;
  39.     function FindLowest: PtrInt;
  40.     function FindHighest: PtrInt;
  41.  
  42.     {$IFDEF DEBUG}
  43.     procedure DebugOutPut;
  44.     {$ENDIF}
  45.   protected
  46.   public
  47.     constructor Create;
  48.     destructor Destroy; override;
  49.     procedure ReadAssignmentFromFile(const Fn: String);
  50.     procedure DisplaySolution;
  51.     procedure SaveSolutionToFile(const Fn: String);
  52.     property Options: TNumberFileOptions read FOptions write SetOptions default [nfoFirstValueIsNrOfLines];
  53.     property RequiredSolutions: TSolutions read FSolutions write FSolutions default [solLowest];
  54.   end;
  55.  
  56.   EInvalidFileFormat = class (EStreamError);
  57.  
  58. function ListSortUp(Item1, Item2: Pointer): Integer;
  59. begin
  60.   Result := {%H-}{%H-}PtrInt(Item1) - {%H-}{%H-}PtrInt(Item2);
  61. end;
  62.  
  63. function ListSortDown(Item1, Item2: Pointer): Integer;
  64. begin
  65.   Result := {%H-}{%H-}PtrInt(Item2) - {%H-}{%H-}PtrInt(Item1);
  66. end;
  67.  
  68. procedure TNumberFileStream.SetOptions(AValue: TNumberFileOptions);
  69. begin
  70.   if FOptions = AValue then Exit;
  71.   FOptions := AValue;
  72.   //nfoSecondValueIsCount implies nfoFirstValueIsNrOfLines
  73.   if (FOptions * [nfoSecondValueIsCount] = [nfoSecondValueIsCount]) then
  74.     FOptions := FOptions + [nfoFirstValueIsNrOfLines];
  75. end;
  76.  
  77. procedure TNumberFileStream.Scan(AStream: TStream);
  78. var
  79.   C: Char;
  80.   S, LEString: String;
  81.   L: PtrInt;
  82. const
  83.   WhiteSpace = [#0,#9,#10,#13,#32];
  84.   NewLineChars = [#10,#13];
  85. begin
  86.   AStream.Position := 0;
  87.   if (AStream.Size <> 0) then
  88.     FRealNrOfLines := 1;
  89.   FList.Clear;
  90.   S:= '';
  91.   LEString := '';
  92.   while (AStream.Read(C{%H-}, 1) = 1) do
  93.   begin
  94.     if (C in NewLineChars) then
  95.     begin
  96.       LEString := LEString + C;
  97.     end;
  98.     if (C in WhiteSpace) then
  99.     begin
  100.       if (S <> '') then
  101.       begin
  102.         if not TryStrToInt(S, L) then
  103.           Raise EInvalidFileFormat.CreateFmt('Invalid file format: %s is not a number.',[S]);
  104.         S := '';
  105.         AddToList(L);
  106.       end;
  107.     end
  108.     else
  109.     begin
  110.       S := S + C;
  111.     end;
  112.   end;
  113.   FRealNrOfLines := CountLineEndings(LEString) + FRealNrOfLines;
  114.   if (C in NewLineChars) then Dec(FRealNrOfLines); //file ended with empty line
  115.  
  116.   CheckFileValidity;
  117.   {$IFDEF DEBUG}
  118.   DebugOutPut;
  119.   {$ENDIF}
  120. end;
  121.  
  122. procedure TNumberFileStream.AddToList(L: PtrInt);
  123. begin
  124.   if (FList.Count = 0) and (nfoFirstValueIsNrOfLines in FOptions) and (FExpectedNrOfLines = -1) then
  125.   begin
  126.     if (L <= 0) then
  127.       Raise EInvalidFileFormat.CreateFmt('Invalid file format: %d is not a valid value for "expected number of lines".',
  128.                                          [L]);
  129.     FExpectedNrOfLines := L
  130.   end
  131.   else
  132.   begin
  133.     if (FList.Count = 0) and (nfoSecondValueIsCount in FOptions) and (FExpectedNrOfLines <> -1) and (FExpectedCount = -1) then
  134.     begin
  135.       if (L < 0) then
  136.         Raise EInvalidFileFormat.CreateFmt('Invalid file format: %d is not a valid value for "expected amount of numbers".',
  137.                                            [L]);
  138.       FExpectedCount := L;
  139.     end
  140.     else
  141.       FList.Add({%H-}Pointer(L));
  142.   end;
  143. end;
  144.  
  145. procedure TNumberFileStream.CheckFileValidity;
  146. begin
  147.   //nfoFirstValueIsNrOfLines, nfoSecondValueIsCount
  148.   if (Count = 0) then
  149.     Raise EInvalidFileFormat.Create('Invalid file format: number of values is zero.');
  150.   if FOptions = [] then Exit;
  151.   if (nfoFirstValueIsNrOfLines in FOptions) and (FExpectedNrOfLines <> FRealNrOfLines) then
  152.     Raise EInvalidFileFormat.CreateFmt('Invalid file format:'+LineEnding+
  153.                                        'Expected number of lines (%d) does not match real number of lines (%d)',
  154.                                        [FExpectedNrOfLines,FRealNrOfLines]);
  155.   if (nfoSecondValueIsCount in FOptions) and (FExpectedCount <> FList.Count) then
  156.     Raise EInvalidFileFormat.CreateFmt('Invalid file format:'+LineEnding+
  157.                                        'Expected number of values (%d) does not match real number of values (%d)',
  158.                                        [FExpectedCount,FList.Count]);
  159. end;
  160.  
  161. function TNumberFileStream.CountLineEndings(S: String): Integer;
  162. //Assumes S only contains LineEnding characters: #10 and/or #13
  163. begin
  164.   S := AdjustLineBreaks(S);
  165.   Result := Length(S) div Length(LineEnding);
  166. end;
  167.  
  168. function TNumberFileStream.Count: Integer;
  169. begin
  170.   Result := FList.Count;
  171. end;
  172.  
  173. function TNumberFileStream.FindLowest: PtrInt;
  174. var
  175.   NewList: TList;
  176.   i: Integer;
  177. begin
  178.   NewList := TList.Create;
  179.   try
  180.     for i := 0 to FList.Count - 1 do
  181.       NewList.Add(FList.Items[i]);
  182.     NewList.Sort(@ListSortUp);
  183.     Result := {%H-}PtrInt(NewList.Items[0]);
  184.   finally
  185.     NewList.Free;
  186.   end;
  187. end;
  188.  
  189. function TNumberFileStream.FindHighest: PtrInt;
  190. var
  191.   NewList: TList;
  192.   i: Integer;
  193. begin
  194.   NewList := TList.Create;
  195.   try
  196.     for i := 0 to FList.Count - 1 do
  197.       NewList.Add(FList.Items[i]);
  198.     NewList.Sort(@ListSortDown);
  199.     Result := {%H-}PtrInt(NewList.Items[0]);
  200.   finally
  201.     NewList.Free;
  202.   end;
  203. end;
  204.  
  205. {$IFDEF DEBUG}
  206. procedure TNumberFileStream.DebugOutPut;
  207. var
  208.   i: Integer;
  209. begin
  210.   writeln('FExpectedNrOfLines = ',FExpectedNrOfLines);
  211.   writeln('FRealNrOfLines     = ',FRealNrOfLines);
  212.   writeln('FExpectedCount     = ',FExpectedCount);
  213.   writeln('Count              = ',FList.Count);
  214.   for i := 0 to FList.Count - 1 do
  215.   begin
  216.     writeln(' * ',i:2,#32,{%H-}PtrInt(FList.Items[i]));
  217.   end;
  218.   writeln('Lowest             = ',FindLowest);
  219.   writeln('Highest            = ',FindHighest);
  220. end;
  221. {$ENDIF}
  222.  
  223. constructor TNumberFileStream.Create;
  224. begin
  225.   FList := TList.Create;
  226.   FExpectedNrOfLines := -1;
  227.   FRealNrOfLines := 0;
  228.   FExpectedCount := -1;
  229.   FOptions := [];
  230.   FSolutions := [solLowest];
  231. end;
  232.  
  233. destructor TNumberFileStream.Destroy;
  234. begin
  235.   FList.Free;
  236.   inherited Destroy;
  237. end;
  238.  
  239. procedure TNumberFileStream.ReadAssignmentFromFile(const Fn: String);
  240. var
  241.   FS: TFileStream;
  242. begin
  243.   FS := TFileStream.Create(Fn, fmOpenRead or fmShareDenyNone);
  244.   try
  245.     Scan(FS);
  246.   finally
  247.     FS.Free;
  248.   end;
  249. end;
  250.  
  251. procedure TNumberFileStream.DisplaySolution;
  252. var
  253.   i: Integer;
  254. begin
  255.   if (FSolutions = []) then Exit;
  256.   writeln('Numbers found: ');
  257.   for i := 0 to FList.Count - 1 do
  258.   begin
  259.     write({%H-}PtrInt(FList.Items[i]), #32);
  260.   end;
  261.   writeln;
  262.   if (solLowest in FSolutions) then  writeln('Lowest number : ',FindLowest);
  263.   if (solHighest in FSolutions) then writeln('Highest number: ',FindHighest);
  264. end;
  265.  
  266. procedure TNumberFileStream.SaveSolutionToFile(const Fn: String);
  267. var
  268.   SL: TStringList;
  269.   S: String;
  270.   i: Integer;
  271. begin
  272.   if (FSolutions = []) then Exit;
  273.   SL := TStringList.Create;
  274.   try
  275.     SL.Add('Numbers Found: ');
  276.     S := '';
  277.     for i := 0 to FList.Count - 1 do
  278.     begin
  279.       S := S + IntToStr({%H-}PtrInt(FList.Items[i])) + #32;
  280.     end;
  281.     S := Trim(S);
  282.     SL.Add(S);
  283.     if (solLowest in FSolutions) then SL.Add(Format('Lowest number : %d',[FindLowest]));
  284.     if (solHighest in FSolutions) then SL.Add(Format('Highest number: %d',[FindHighest]));
  285.     SL.SaveToFile(Fn);
  286.   finally
  287.     SL.Free;
  288.   end;
  289. end;
  290.  
  291. procedure SyntaxHelp;
  292. begin
  293.   writeln('Syntax:');
  294.   writeln('nf --in=Filename1 [--out=Filename2] [--sol=Lowest|Highest|Both]  [--opt=1|2]');
  295.   writeln;
  296.   writeln('  --in=<value> : Input file with numbers');
  297.   writeln('  --out=<value>: Outputfile with answers (optional)');
  298.   writeln('  --sol=<value>: Find lowest, or highest, or both numbers. Defaut = lowest (optional)');
  299.   writeln('  --opt=<value>: ');
  300.   writeln('     1: First number in file is expected number of lines.');
  301.   writeln('     2: Second numbers in file is expected number of values that follow.');
  302.   writeln('        AND first number in file is expected number of lines.');
  303.   writeln('     When omitted: none of these rules apply.');
  304. end;
  305.  
  306. function ParseCommandLine(out InFn, OutFn: String; out Sol: TSolutions; out Options: TNumberFileOptions): Boolean;
  307. {$IFNDEF TEST}
  308. var
  309.   i: Integer;
  310.   S:String;
  311.   P: SizeInt;
  312.   Ext: RawByteString;
  313.   {$IFDEF DEBUG}
  314.   ASol: TSolution;
  315.   AOpt: TNumberFileOption;
  316.   {$ENDIF}
  317. {$ENDIF TEST}
  318. begin
  319.   {$IFDEF TEST}
  320.   InFn := 'in.txt';
  321.   OutFn := 'out.txt';
  322.   Sol := [solLowest, solHighest];
  323.   Options := [nfoFirstValueIsNrOfLines, nfoSecondValueIsCount];
  324.   Result := True;
  325.   {$ELSE}
  326.   Result := False;
  327.   InFn := '';
  328.   OutFn := '';
  329.   Sol := [solLowest];
  330.   Options := [];
  331.   if (ParamCount < 1) or (ParamCount > 4)
  332.      or (UpperCase(ParamStr(1)) = '-h')
  333.      or (UpperCase(ParamStr(1)) = '--help')
  334.      or (UpperCase(ParamStr(1)) = '-?')
  335.      or (UpperCase(ParamStr(1)) = '/?') then
  336.   begin
  337.     Exit;
  338.   end;
  339.   for i := 1 to ParamCount do
  340.   begin
  341.     S := ParamStr(i);
  342.     if (Pos('--IN=',UpperCase(S)) = 1) then
  343.     begin
  344.       S := Copy(S, 6, MaxInt);
  345.       P := Pos(#32, S);
  346.       if (P > 0) then System.Delete(S, P, MaxInt);
  347.       InFn := Trim(S);
  348.     end
  349.     else if (Pos('--OUT=',UpperCase(S)) = 1) then
  350.     begin
  351.       S := Copy(S, 7, MaxInt);
  352.       P := Pos(#32, S);
  353.       if (P > 0) then System.Delete(S, P, MaxInt);
  354.       OutFn := Trim(S);
  355.     end
  356.     else if (Pos('--SOL=',UpperCase(S)) = 1) then
  357.     begin
  358.       S := Copy(S, 7, MaxInt);
  359.       P := Pos(#32, S);
  360.       if (P > 0) then System.Delete(S, P, MaxInt);
  361.       S := Trim(S);
  362.       case UpperCase(S) of
  363.         'LOWEST': Sol := [solLowest];
  364.         'HIGHEST': Sol := [solHighest];
  365.         'BOTH': Sol := [solLowest, solHighest];
  366.         else
  367.         begin
  368.           writeln('Ilegal parameter: ',ParamStr(i));
  369.           Exit;
  370.         end;
  371.       end;
  372.     end
  373.     else if (Pos('--OPT=',UpperCase(S)) = 1) then
  374.     begin
  375.       S := Copy(S, 7, MaxInt);
  376.       P := Pos(#32, S);
  377.       if (P > 0) then System.Delete(S, P, MaxInt);
  378.       S := Trim(S);
  379.       case UpperCase(S) of
  380.         '1': Options := [nfoFirstValueIsNrOfLines];
  381.         '2': Options := [nfoFirstValueIsNrOfLines, nfoSecondValueIsCount];
  382.         else
  383.         begin
  384.           writeln('Ilegal parameter: ',ParamStr(i));
  385.           Exit;
  386.         end;
  387.       end;
  388.     end
  389.     else
  390.     begin
  391.       writeln('Illegal parameter: ',ParamStr(i));
  392.       Exit;
  393.     end;
  394.   end;
  395.   if (InFn = '') then
  396.   begin
  397.     writeln('InFn is empty');
  398.     Exit;
  399.   end;
  400.   if (OutFn = '') then
  401.   begin
  402.     OutFn := InFn;
  403.     Ext := ExtractFileExt(OutFn);
  404.     OutFn := Copy(OutFn, 1, Length(OutFn) - Length(Ext));
  405.     OutFn := OutFn + '-solution' + Ext;
  406.   end;
  407.   Result := True;
  408.   {$IFDEF DEBUG}
  409.   writeln('InFn  = ',InFn);
  410.   writeln('OutFn = ',OutFn);
  411.   writeln('Sol   = ');
  412.   for ASol in Sol do writeln(#32, ASol);
  413.   writeln('Opt   = ');
  414.   for AOpt in Options do writeln(#32, AOpt);
  415.   {$ENDIF DEBUG}
  416.   {$ENDIF TEST}
  417. end;
  418.  
  419.  
  420. var
  421.   NFS: TNumberFileStream;
  422.   InFn, OutFn: String;
  423.   Solutions: TSolutions;
  424.   Options: TNumberFileOptions;
  425.  
  426. begin
  427.   if ParseCommandLine(InFn, OutFn, Solutions, Options) then
  428.   begin
  429.     NFS := TNumberFileStream.Create;
  430.     try
  431.       try
  432.         NFS.RequiredSolutions := Solutions;
  433.         NFS.Options := Options;
  434.         NFS.ReadAssignmentFromFile(InFn);
  435.         NFS.DisplaySolution;
  436.         NFS.SaveSolutionToFile(OutFn);
  437.       except
  438.         on E: EStreamError do
  439.         begin
  440.           write('An unhandled exception has occurred of type ',E.ClassName);
  441.           writeln(', with message:');
  442.           writeln(E.Message);
  443.         end;
  444.       end;
  445.     finally
  446.       NFS.Free;
  447.     end;
  448.   end
  449.   else
  450.     SyntaxHelp;
  451. end.
  452.  

Bart
« Last Edit: October 22, 2016, 06:57:09 pm by Bart »

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Need help with finding the lowest number
« Reply #17 on: October 22, 2016, 08:19:02 pm »
Quote
What filter did you use for the PROGRAM and USES?
That filter is called "Do-it-yourself-Filter" and it had a big downside: it's often very variable or let's say unstable, maybe it needs a big rewrite...

Quote
The C people have a A++ grade in that field.
:D

@Bart:
Thanks a lot for the great TProcess-idea... I don't know why I didn't see this at first...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Need help with finding the lowest number
« Reply #18 on: October 23, 2016, 10:22:12 am »
Alas, the example is not complete.....
To reproduce Bart's code you first take the screenshot and still need to feed it to OCR software.
After that there is a small chance it will compile.

That information was missing. >:(
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Need help with finding the lowest number
« Reply #19 on: October 23, 2016, 10:37:06 am »
Here's my solution, btw ;)
Code: Pascal  [Select][+][-]
  1. program lowest;
  2. {$ifdef fpc}{$mode delphi}{$endif}
  3. uses generics.collections;
  4.  
  5. var L:Tlist<integer>;
  6. begin
  7.   L := TList<integer>.Create;
  8.   try
  9.     L.AddRange([15, 51, 68, -8, 2, 16, 13]);
  10.     L.Sort;
  11.     writeln(L[0]);
  12.   finally
  13.     L.Free;
  14.   end;
  15. end.

Code: [Select]
pi@raspberrypi:~ $ ./lowest
-8

My first solution was a stack-based forth-like compiler, but, I did not get that to work  >:D :o

I hope the example is too late to be useful.
« Last Edit: October 23, 2016, 10:48:39 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Need help with finding the lowest number
« Reply #20 on: October 23, 2016, 11:04:35 am »
What about an in-memory database and select distinct order by? That may also solve it.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Need help with finding the lowest number
« Reply #21 on: October 23, 2016, 12:13:35 pm »
The main problem is the reading of the text file and knowing which char in the file actually is a number and belongs to the values we need to investigate.
Sorting is relatively easy once you get the first task done.

Therefore Thaddy's "lowest" program won't do for this particular assignment.
Thaddy's later suggestion of feeding the numbers into a database and do a quesry on that, however is a nice and valuable suggestion that can probably make the program more robust and hardened.

I think it is a must-have, and I would like to assign this part of the task (replacing the FList: TList with an in-memory database) to Thaddy.
Methods involved are:
  • AddToList
  • Count
  • FindLowest
  • FindHighest
  • DisplaySolution
  • SaveSolutionToFile

The rest of the framework cannot be altered, it was written by our best paid developer, who unfortunately also has a bad temper.

Business rules must apply to keep management happy.
When databases come into play, an new layer of abstraction is mandatory.

Deadline is today 19:00 (after that the kitchen is calling).
Failing to deliver will cost our company many valuable clients and possibly millions of $$.

I excpect to see your implementation soon.
Also be aware that your reward (free coffee) depends on LOC's submitted per day (since this is also the main standard by which we price our products).

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Need help with finding the lowest number
« Reply #22 on: October 23, 2016, 12:37:38 pm »
Unfortunately that was not in the original specification. I have to therefor politily ask to renegotiate the contract for the extra work involved.
I hope you appreciate that the time limit that you require is strictly against the Formula One time table for the COTA which alas demands my attention and preparation.

It would be possible, though, if one specified the business rules required, to have a solution in due time.

Respectful of the fact you initially supplied sufficient input to sketch the problem and its resolve, I duly need to inform you that under current conditions I can not satisfy the assignment under the terms that you ask,

Regards,

etc, etc. <stamp sign this, Hillary, plz>
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Need help with finding the lowest number
« Reply #23 on: October 23, 2016, 12:54:04 pm »
Respectful of the fact you initially supplied sufficient input to sketch the problem and its resolve, I duly need to inform you that under current conditions I can not satisfy the assignment under the terms that you ask,

This will not do.
Your contract has been terminated immediately.
Who the hell do you think you are  >:D >:D >:D >:D
I'll get a real developer who can write a robust dll in C# we can link in.

This is probably the cheap (only 54 LOC!!) solution you would have come up with:

Code: Pascal  [Select][+][-]
  1. program simplenf;
  2.  
  3. {$R *.res}
  4.  
  5.  
  6. var
  7.   InF,OutF : Text;
  8.   Num, LineNr, ExpLines, Lowest, Highest : Integer;
  9.   FirstIsNrOfLines, Done: Boolean;
  10. begin
  11.   FirstIsNrOfLines := (ParamStr(1) = '1');
  12.   Done := False;
  13.   ExpLines := -1;
  14.   Highest := -MaxInt;
  15.   Lowest := MaxInt;
  16.   Assign(InF,'in.txt');
  17.   Assign(OutF,'simpleout.txt');
  18.   Reset(InF);
  19.   LineNr := 1;
  20.   Rewrite(OutF);
  21.   writeln(OutF, 'Numbers found: ');
  22.   writeln('Numbers found: ');
  23.   while (not SeekEof(InF)) and (not Done) do
  24.   begin
  25.     if SeekEoln(InF) then
  26.     begin
  27.       Inc(LineNr);
  28.       if FirstIsNrOfLines and (ExpLines > -1) and (LineNr > ExpLines) then
  29.         Done := True;
  30.       Readln(InF); { Go to next line }
  31.     end;
  32.     if not Done then
  33.     begin
  34.       Read(InF,Num);
  35.       if FirstIsNrOfLines and (ExpLines = -1) then
  36.         ExpLines := Num
  37.       else
  38.       begin
  39.         if (Num > Highest) then Highest := Num;
  40.         if (Num < Lowest) then Lowest := Num;
  41.         Write(OutF, Num, ' ');
  42.         Write(Num, ' ');
  43.       end;
  44.     end;
  45.   end;
  46.   writeln(OutF);
  47.   writeln(OutF, 'Lowest : ',Lowest);
  48.   writeln(OutF, 'Highest: ',Highest);
  49.   writeln;
  50.   writeln('Lowest : ',Lowest);
  51.   writeln('Highest: ',Highest);
  52.   Close(InF);
  53.   Close(OutF);
  54. end.
  55.  

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Need help with finding the lowest number
« Reply #24 on: October 23, 2016, 12:57:56 pm »
The preparations involve:

4 fillets of plaice (fresh, you know how to fillet a fish?)
1 Salmon fillet off the bone and skin (may come from my freezer)
1 glass of white wine (a decent glass, not what Dutch docters count as one unit)
100 grams of north sea (gray) shrimps
1 DL of fish stock (may come from my freezer)
1 DL of Creme Fraiche (30% fat)
Cloave of garlic
Small onion (sweet)
Loads of persil (in french: parsley) and dill. [editted]
Salt, pepper.
Small potatoes.

Verdicchio di Castelli di Jesi to taste.

You see now why it is impossible?


[edit]
forgot some rucola concoction (AKA salad) to satisfy vitamins demanded by wife
[edit2] you can use lemon sole or Dover sole instead of plaice. That's only due to me first cooking it based on a flawed first-generation lcd screen on which I also feared my daughter had rashes that could not be spotted in real life. She had the same distinctive red spots. Even at the same place!
Plaice is, however, under-estimated.
« Last Edit: October 23, 2016, 07:24:11 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Need help with finding the lowest number
« Reply #25 on: October 23, 2016, 06:06:42 pm »
You see now why it is impossible?

Yes, you insist on using fish, while the principal developer of our company (the one with the bad temper) is a vegetarian, as was clearly pointed ou to you during the initial negotiation of your contract.

A vegetarian does not eat animals, and therefore also does not eat fish or molluscs, something that many people choose to ignore.
This can lead to embarrassing situations like this one.

I can only say: I expected more of you.

Despite all of this I whish you "smakelijk eten" as we say in my country of origin  O:-)

Bart

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Need help with finding the lowest number
« Reply #26 on: October 23, 2016, 06:36:02 pm »
Loads of persil and dill.

I think that should be either parsley or basil? Here Persil is what you might use to wash your socks...

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Need help with finding the lowest number
« Reply #27 on: October 23, 2016, 07:08:36 pm »
depends. It's parsley in this case. I made a persillade with it. Hence the slip.

Anyway, Bart's problem can be solved with a protein rich diet (Nuts available all over this forum) and eating (flora) vegetables that require copious amounts of (fauna excrement) dung to grow, to cure the vitamin B and iron deficiency., like spinach..
My eldest (step) daughter is a vegan (no, not Vulcan). Discussions still undecided. But her chickens eat worms. And the chickenshit goes to the spinach. (not in any recipe but to grow)
Vegans are known to have a temperament because of these two essentials, vitamin B and protein, are missing in the diet. Of course iron is actually the only.... ;)
« Last Edit: October 23, 2016, 07:17:11 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Need help with finding the lowest number
« Reply #28 on: October 23, 2016, 07:16:15 pm »
(Nuts available all over this forum)

ROFL!

But her chickens eat worms.

So do my chickens.
I once saw one of my chickens trying to eat a mouse.

Unfortunately three times now, a hedgehog has tried to eat one of my chickens, starting at it's paws (while it was alive!).
While I love hedgehog's, I have driven him/her over 15 miles away and let it go there.

Bart
« Last Edit: October 23, 2016, 07:17:50 pm by Bart »

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Need help with finding the lowest number
« Reply #29 on: October 23, 2016, 07:19:49 pm »
Problem is, here in Krommenie, we have hedgehogs all over the place and I have two dogs.
Due to climate change there is actually a problem. They should have gone to sleep by now. The dogs and the hedgehogs.
Back to F1 and fossil fuel, tnx Bart and the dinner was fabulous!
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018