Recaman's sequence: Difference between revisions

→‎{{header|ALGOL W}}: Also display the largest sequence element encountered
(Add PL/M)
(→‎{{header|ALGOL W}}: Also display the largest sequence element encountered)
Line 77:
reference(AValue) array hashTable ( 0 :: HMOD - 1 );
integer array A ( 0 :: 14 );
integer le1000Count, firstN, duplicateN, duplicateValue, n, An, An1, prevN, maxS;
 
% adds an element to the hash table, returns true if an element with value An %
Line 106:
A( 0 ) := An1 := n := 0;
le1000Count := 0;
maxS := firstN := duplicateN := duplicateValue := -1;
while le1000Count < 1000 do begin
logical le0, duplicate;
Line 129:
else if An <= 1000 then le1000Count := le1000Count + 1;;
if n < 15 then A( n ) := An;
if An > maxS then maxS := An;
An1 := An
end while_le1000Count_lt_1000 ;
Line 147 ⟶ 148:
);
% number of elements required to include the first 1000 integers %
write( i_w := 1, "first element to include all 1..1000: ", n );
write( i_w := 1, "max sequence value encountered: ", maxS )
end
 
Line 156 ⟶ 158:
First duplicates: 20 24 (42)
first element to include all 1..1000: 328002
max sequence value encountered: 1942300
</pre>
 
3,059

edits