How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the Mathematica / Wolfram Language programming language

Published on 22 June 2024 08:30 PM

How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the Mathematica / Wolfram Language programming language

Table of Contents

Problem Statement

The definition of the sequence is colloquially described as: Note that indexing for the description above starts from alternately the left and right ends of the list and starts from an index of one. A less wordy description of the sequence is: The sequence begins: Interesting features of the sequence are that:

The sequence is so named because John Conway offered a prize of $10,000 to the first person who could find the first position,   p   in the sequence where It was later found that Hofstadter had also done prior work on the sequence. The 'prize' was won quite quickly by Dr. Colin L. Mallows who proved the properties of the sequence and allowed him to find the value of   n   (which is much smaller than the 3,173,375,556 quoted in the NYT article).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the Mathematica / Wolfram Language programming language

This Wolfram code explores the Mallows number sequence, a sequence of integers where each term is defined recursively as the sum of the previous term and the term before that.

  1. Initialization: The first two terms of the sequence, a[1] and a[2], are defined as 1.

  2. Recursive Definition: For any integer n greater than 2, the term a[n] is calculated as the sum of a[a[n-1]] and a[n-a[n-1]]. This recursive definition creates a sequence where each term depends on the previous terms in a complex way.

  3. Looping and Printing: The code uses the Map function to iterate over a range of values from 1 to 19 and print the maximum value of the sequence a[n]/n for each power of 2 in that range. The Table function is used to generate the values of a[n]/n for different values of n within each power of 2 range.

  4. Finding the Mallows Number: The code also finds the "Mallows number," which is the smallest value of n such that a[n]/n is less than or equal to 0.55. This is done using a While loop that decrements the value of n until the condition is met.

The output of the code will show the maximum values of a[n]/n for different powers of 2, as well as the Mallows number, which is approximately 2^20 or 1,048,576.

Source code in the wolfram programming language

a[1] := 1; a[2] := 1;
a[n_] := a[n] = a[a[n-1]] + a[n-a[n-1]]

Map[Print["Max value: ",Max[Table[a[n]/n//N,{n,2^#,2^(#+1)}]]," for n between 2^",#," and 2^",(#+1)]& , Range[19]]
n=2^20; While[(a[n]/n//N)<0.55,n--]; Print["Mallows number: ",n]


  

You may also check:How to resolve the algorithm User input/Text step by step in the Ceylon programming language
You may also check:How to resolve the algorithm Harshad or Niven series step by step in the C programming language
You may also check:How to resolve the algorithm Calendar step by step in the Clojure programming language
You may also check:How to resolve the algorithm Trigonometric functions step by step in the Raku programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the EMal programming language