Maximum difference between adjacent elements of list: Difference between revisions

Content added Content deleted
m (β†’β€Ž{{header|Pascal}}: added for Free Pascal. Where to find ISO 7185 ( before 1990 ? ))
m (move 𝘴𝘢𝘣section β†’β€ŽFree Pascal: introduced in preceding revision 549A2 to its 𝘰𝘸𝘯 section, mark as translation of Pascal)
Line 220: Line 220:
{ 7 V{ { 1 8 } { 2 9 } { 10 3 } } }
{ 7 V{ { 1 8 } { 2 9 } { 10 3 } } }
</pre>
</pre>

=={{header|Free Pascal}}==
{{trans|Pascal}}
<lang pascal>
program maximumDifferenceBetweenAdjacentElementsOfList(output);
type
tmyReal = extended;
tmyList = array of tmyReal;
const
input: tmyList = (1, 8, 2, -3, 0, 1, 1, -2.3, 0, 5.5, 8, 6, 2, 9, 11, 10, 3);
procedure OutSameDistanceInList(Dist:tmyReal;const list: tmyList);
var
currentDistance : tmyReal;
i : integer;
begin
for i := 0 to High(List) - 1 do
begin
currentDistance := abs(list[i] - list[succ(i)]);
if currentDistance = dist then
writeln('idx : ',i:4,' values ',list[i],' ',list[i+1]);
end;
writeln;
end;

function internalDistance(const list: tmyList): tmyReal;
var
i: integer;
maximumDistance, currentDistance: tmyReal;
begin
maximumDistance := 0.0;
for i := 0 to High(List) - 1 do
begin
currentDistance := abs(list[i] - list[succ(i)]);
if currentDistance > maximumDistance then
begin
maximumDistance := currentDistance;
end;
end;
internalDistance := maximumDistance;
end;

var
list: tmyList;
foundDistance : tmyReal;
begin
list := input;
if length(list) > 0 then
Begin
foundDistance := internalDistance(list);
OutSameDistanceInList(foundDistance,list);
end;
{$IFDEF WINDOWS}
readln;
{$ENDIF}
end.</lang>
{{out}}
<pre>
idx : 0 values 1.0000000000000000E+000 8.0000000000000000E+000
idx : 12 values 2.0000000000000000E+000 9.0000000000000000E+000
idx : 15 values 1.0000000000000000E+001 3.0000000000000000E+000 </pre>


=={{header|Go}}==
=={{header|Go}}==
Line 407: Line 467:
writeLn(internalDistance(list));
writeLn(internalDistance(list));
end.</lang>
end.</lang>
==={{header|Free Pascal}}===
transformed for freepascal
<lang pascal>
program maximumDifferenceBetweenAdjacentElementsOfList(output);
type
tmyReal = extended;
tmyList = array of tmyReal;
const
input: tmyList = (1, 8, 2, -3, 0, 1, 1, -2.3, 0, 5.5, 8, 6, 2, 9, 11, 10, 3);
procedure OutSameDistanceInList(Dist:tmyReal;const list: tmyList);
var
currentDistance : tmyReal;
i : integer;
begin
for i := 0 to High(List) - 1 do
begin
currentDistance := abs(list[i] - list[succ(i)]);
if currentDistance = dist then
writeln('idx : ',i:4,' values ',list[i],' ',list[i+1]);
end;
writeln;
end;

function internalDistance(const list: tmyList): tmyReal;
var
i: integer;
maximumDistance, currentDistance: tmyReal;
begin
maximumDistance := 0.0;
for i := 0 to High(List) - 1 do
begin
currentDistance := abs(list[i] - list[succ(i)]);
if currentDistance > maximumDistance then
begin
maximumDistance := currentDistance;
end;
end;
internalDistance := maximumDistance;
end;

var
list: tmyList;
foundDistance : tmyReal;
begin
list := input;
if length(list) > 0 then
Begin
foundDistance := internalDistance(list);
OutSameDistanceInList(foundDistance,list);
end;
{$IFDEF WINDOWS}
readln;
{$ENDIF}
end.</lang>
{{out}}
<pre>
idx : 0 values 1.0000000000000000E+000 8.0000000000000000E+000
idx : 12 values 2.0000000000000000E+000 9.0000000000000000E+000
idx : 15 values 1.0000000000000000E+001 3.0000000000000000E+000 </pre>


=={{header|Perl}}==
=={{header|Perl}}==