19 lines
445 B
Text
19 lines
445 B
Text
>function RSstep (r,s) ...
|
|
$ n=cols(r);
|
|
$ r=r|(r[n]+s[n]);
|
|
$ s=s|(max(s[n]+1,r[n]+1):r[n+1]-1);
|
|
$ return {r,s};
|
|
$ endfunction
|
|
>function RS (n) ...
|
|
$ if n==1 then return {[1],[2]}; endif;
|
|
$ if n==2 then return {[1,3],[2]}; endif;
|
|
$ r=[1,3]; s=[2,4];
|
|
$ loop 3 to n; {r,s}=RSstep(r,s); end;
|
|
$ return {r,s};
|
|
$ endfunction
|
|
>{r,s}=RS(10);
|
|
>r
|
|
[ 1 3 7 12 18 26 35 45 56 69 ]
|
|
>{r,s}=RS(50);
|
|
>all(sort(r[1:40]|s[1:960])==(1:1000))
|
|
1
|