How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the Icon and Unicon programming language
How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
procedure main(args)
m := integer(!args) | 20
nextNum := create put(A := [], 1 | 1 | |A[A[*A]]+A[-A[*A]])[*A]
p2 := 2 ^ (p := 1)
maxv := 0
every n := 1 to (2^m) do {
if maxv <:= (x := @nextNum / real(n)) then maxm := n
if x >= 0.55 then mallows := n # Want *this* n, not next one!
if n = p2 then {
write("Max between 2^",p-1," and 2^",p," is ",maxv," at n = ",maxm)
p2 := 2 ^ (p +:= 1)
maxv := 0
}
}
write("Mallows's number is ",\mallows | "NOT found!")
end
You may also check:How to resolve the algorithm Combinations step by step in the Julia programming language
You may also check:How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Ring programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Ada programming language
You may also check:How to resolve the algorithm Algebraic data types step by step in the Prolog programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Processing programming language