Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
43
Task/Recamans-sequence/PL-I/recamans-sequence.pli
Normal file
43
Task/Recamans-sequence/PL-I/recamans-sequence.pli
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
recaman: procedure options(main);
|
||||
declare A(0:30) fixed;
|
||||
|
||||
/* is X in the first N terms of the Recaman sequence? */
|
||||
find: procedure(x, n) returns(bit);
|
||||
declare (x, n, i) fixed;
|
||||
do i=0 to n-1;
|
||||
if A(i)=x then return('1'b);
|
||||
end;
|
||||
return('0'b);
|
||||
end find;
|
||||
|
||||
/* generate the N'th term of the Recaman sequence */
|
||||
generate: procedure(n) returns(fixed);
|
||||
declare n fixed;
|
||||
if n=0 then
|
||||
A(0) = 0;
|
||||
else do;
|
||||
declare (sub, add) fixed;
|
||||
sub = A(n-1) - n;
|
||||
add = A(n-1) + n;
|
||||
/* A(n-1) - n not positive? */
|
||||
if sub <= 0 then
|
||||
A(n) = add;
|
||||
/* A(n-1) - n already generated? */
|
||||
else if find(sub, n) then
|
||||
A(n) = add;
|
||||
else
|
||||
A(n) = sub;
|
||||
end;
|
||||
return(A(n));
|
||||
end generate;
|
||||
|
||||
declare i fixed;
|
||||
put skip list('First 15 members:');
|
||||
do i=0 to 14;
|
||||
put edit(generate(i)) (F(3));
|
||||
end;
|
||||
|
||||
put skip list('First repeated term: ');
|
||||
do i=15 repeat(i+1) while(^find(generate(i), i)); end;
|
||||
put edit('A(',i,') = ',A(i)) (A,F(2),A,F(2));
|
||||
end recaman;
|
||||
Loading…
Add table
Add a link
Reference in a new issue