How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the SETL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the SETL programming language
Table of Contents
Problem Statement
These two sequences of positive integers are defined as:
The sequence
S ( n )
{\displaystyle S(n)}
is further defined as the sequence of positive integers not present in
R ( n )
{\displaystyle R(n)}
. Sequence
R
{\displaystyle R}
starts: Sequence
S
{\displaystyle S}
starts:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the SETL programming language
Source code in the setl programming language
program figure_figure;
init R := [1], S := [2];
print("R(1..10):", [ffr(n) : n in [1..10]]);
print("R(1..40) + S(1..960) = {1..1000}:",
{ffr(n) : n in {1..40}} + {ffs(n) : n in {1..960}} = {1..1000});
proc ffr(n);
loop while n > #R do
nextR := R(#R) + S(#R);
S +:= [S(#S)+1 .. nextR-1];
R with:= nextR;
S with:= nextR + 1;
end loop;
return R(n);
end proc;
proc ffs(n);
loop while n > #S do
ffr(#R + 1);
end loop;
return S(n);
end proc;
end program;
You may also check:How to resolve the algorithm Character codes step by step in the Prolog programming language
You may also check:How to resolve the algorithm Compile-time calculation step by step in the Oz programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the J programming language
You may also check:How to resolve the algorithm Exponentiation order step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Formatted numeric output step by step in the ARM Assembly programming language