Hofstadter Figure-Figure sequences: Difference between revisions
Content added Content deleted
m (added whitespace and highlighting to the task's preamble, corrected a spelling error, added shaded boxes for the R and S sequences.) |
|||
Line 2: | Line 2: | ||
These two sequences of positive integers are defined as: |
These two sequences of positive integers are defined as: |
||
:<math>\begin{align} |
:::: <big><big><math> \begin{align} |
||
R(1)&=1\ |
R(1)&=1\ \\ |
||
S(1)&=2\ \\ |
|||
R(n)&=R(n-1)+S(n-1), \quad n>1. |
|||
\end{align}</math> |
\end{align} </math></big></big> |
||
⚫ | |||
⚫ | |||
<br> |
|||
⚫ | |||
⚫ | |||
Sequence <big><big><math> R </math></big></big> starts: |
|||
⚫ | |||
Sequence <big><big><math> S </math></big></big> starts: |
|||
⚫ | |||
;Task: |
;Task: |
||
# Create two functions named ffr and ffs that when given n return R(n) or S(n) respectively.<br |
# Create two functions named <big> '''ffr''' </big> and <big> '''ffs''' </big> that when given <big><big><math> n </math></big></big> return <big><big><math> R(n) </math></big></big> or <big><big><math> S(n) </math></big></big> respectively. <br>(Note that R(1) = 1 and S(1) = 2 to avoid off-by-one errors). |
||
# No maximum value for n should be assumed. |
# No maximum value for <big><big><math> n </math></big></big> should be assumed. |
||
# Calculate and show that the first ten values of R are: 1, 3, 7, 12, 18, 26, 35, 45, 56, and 69 |
# Calculate and show that the first ten values of <big><big><math> R </math></big></big> are: <br>1, 3, 7, 12, 18, 26, 35, 45, 56, and 69 |
||
# Calculate and show that the first 40 values of ffr plus the first 960 values of ffs include all the integers from 1 to 1000 exactly once. |
# Calculate and show that the first 40 values of <big> '''ffr''' </big> plus the first 960 values of <big> '''ffs''' </big> include all the integers from '''1''' to '''1000''' exactly once. |
||
;References: |
;References: |
||
* Sloane's [http://oeis.org/A005228 A005228] and [http://oeis.org/A030124 A030124]. |
* Sloane's [http://oeis.org/A005228 A005228] and [http://oeis.org/A030124 A030124]. |
||
* [http://mathworld.wolfram.com/HofstadterFigure-FigureSequence.html Wolfram |
* [http://mathworld.wolfram.com/HofstadterFigure-FigureSequence.html Wolfram MathWorld] |
||
* Wikipedia: [[wp:Hofstadter_sequence#Hofstadter_Figure-Figure_sequences|Hofstadter Figure-Figure sequences]]. |
* Wikipedia: [[wp:Hofstadter_sequence#Hofstadter_Figure-Figure_sequences|Hofstadter Figure-Figure sequences]]. |
||
<br><br> |
<br><br> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
Specifying a package providing the functions FFR and FFS: |
Specifying a package providing the functions FFR and FFS: |