How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the Oforth programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the Oforth 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 Oforth programming language

Source code in the oforth programming language

tvar: R
ListBuffer new 1 over add R put

tvar: S
ListBuffer new 2 over add S put

: buildnext 
| r s current i |
   R at ->r 
   S at ->s
   r last  r size s at  + dup ->current  r add 
   s last 1+  current 1-  for: i [ i s add ]
   current 1+ s add ;

: ffr(n)
   while ( R at size n < ) [ buildnext ]
   n R at at ;

: ffs(n)
   while ( S at size n < ) [ buildnext ]
   n S at at ;

  

You may also check:How to resolve the algorithm Truth table step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Determine if a string has all unique characters step by step in the Perl programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the 11l programming language
You may also check:How to resolve the algorithm Ramer-Douglas-Peucker line simplification step by step in the C++ programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the AWK programming language