program Primtester_2; // simple primtester between range for perfomance- and filehandling // has a function and procedure, no globals, locs = 62 // to teach the function with or without brake shows perfomance! var mylist: TStringlist; beforetime, aftertime: string; //timedelta: integer; function checkPrim(acti: integer): boolean; var j: Integer; isprim: boolean; begin isprim:= true; for j:= 2 to round(sqrt(acti)) do if ((acti mod j) = 0) then begin isprim:= false break end; result:= isprim; end; procedure testPrimNumbers(from_range, to_range: integer); var acti, count: integer; begin count:= 0; mylist:= TStringlist.create; for acti:= from_range to to_range do begin inc(acti) //writeln('debug count'+inttostr(acti)) if checkprim(acti) then begin inc(count) mylist.add(inttostr(count) +':'+inttoStr(acti)) //writeln(inttostr(count) +':'+ inttostr(acti)) end end //insert new lines to an existing file-list {mylist.LoadFromFile('primetest3.txt');} //add a string to the end of list {sl.Add('hell\*/bell');} end; //main script begin //irange:= strtoint(readln('how great is the range ?')); //check time performance beforetime:= now; testPrimNumbers(20, 10000); aftertime:= now; writeln('start: '+ beforetime) writeln('stop: ' + aftertime) mylist.add(memo2.text) mylist.savetoFile('primetest7.txt') memo2.lines.loadfromFile('primetest7.txt') mylist.free; //orthogonal and idempotent end.