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

Published on 12 May 2024 09:40 PM

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

Source code in the autohotkey programming language

R(n){
	if n=1
		return 1
	return R(n-1) + S(n-1)
}

S(n){
	static ObjR:=[]
	if n=1
		return 2
	ObjS:=[]
	loop, % n
		ObjR[R(A_Index)] := true
	loop, % n-1
		ObjS[S(A_Index)] := true
	Loop
		if !(ObjR[A_Index]||ObjS[A_Index])
			return A_index
}


Loop
	MsgBox, 262144, , % "R(" A_Index ") = " R(A_Index) "`nS(" A_Index ") = " S(A_Index)


  

You may also check:How to resolve the algorithm Trigonometric functions step by step in the BASIC programming language
You may also check:How to resolve the algorithm Combinations with repetitions step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Subtractive generator step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Call a function in a shared library step by step in the BASIC programming language
You may also check:How to resolve the algorithm Undefined values step by step in the PHP programming language