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