How to resolve the algorithm Juggler sequence step by step in the Mathematica / Wolfram Language programming language
How to resolve the algorithm Juggler sequence step by step in the Mathematica / Wolfram Language programming language
Table of Contents
Problem Statement
Background of the juggler sequence: Juggler sequences were publicized by an American mathematician and author Clifford A. Pickover. The name of the sequence gets it's name from the similarity of the rising and falling nature of the numbers in the sequences, much like balls in the hands of a juggler.
A juggler sequence is an integer sequence that starts with a positive integer a[0], with each subsequent term in the sequence being defined by the recurrence relation: If a juggler sequence reaches 1, then all subsequent terms are equal to 1. This is known to be the case for initial terms up to 1,000,000 but it is not known whether all juggler sequences after that will eventually reach 1.
Compute and show here the following statistics for juggler sequences with an initial term of a[n] where n is between 20 and 39 inclusive:
If your language supports big integers with an integer square root function, also compute and show here the same statistics for as many as you reasonably can of the following values for n: 113, 173, 193, 2183, 11229, 15065, 15845, 30817, 48443, 275485, 1267909, 2264915, 5812827 Those with fast languages and fast machines may also like to try their luck at n = 7110201. However, as h[n] for most of these numbers is thousands or millions of digits long, show instead of h[n]:
The results can be (partially) verified against the table here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Juggler sequence step by step in the Mathematica / Wolfram Language programming language
This code, written in the Wolfram programming language, investigates the behavior of a sequence of integers generated using a specific rule. The sequence starts with an input integer, n
, and the subsequent terms are calculated using the next
function. The stats
function then analyzes the sequence and provides various statistics.
next
Function:
- This function takes an integer
n
as input. - If
n
is even, it calculates the floor (rounded down value) of the square root ofn
. - If
n
is odd, it calculates the floor ofn^(3/2)
. - The output of this function is the next term in the sequence.
stats
Function:
- This function takes an integer
n
as input and generates a sequence of integers using thenext
function. - It stops the generation when the sequence reaches
1
. - The function then performs the following:
- It stores the generated sequence in the variable
data
. - It calculates the maximum value in the sequence and its position using
Ordering
. - It returns a list of statistics:
n
, the length of the sequence, the maximum value, and the position of the maximum value.
- It stores the generated sequence in the variable
Table Generation:
- The code generates a table of statistics for a range of input integers (
n
) from 20 to 39. - For each
n
, it calls thestats
function and stores the results in a list. - The list of statistics is then used to create a table that is formatted using
TableForm
. - The table headings are set to "n", "length", "max", and "max pos".
Output:
The output of the code is a table that shows the statistics for each input integer. This table can be used to analyze the behavior of the sequence generated by the next
function.
Source code in the wolfram programming language
next[n_Integer] := If[EvenQ@n, Floor[Sqrt[n]], Floor[n^(3/2)]]
stats[n_Integer] :=
Block[{data = Most@NestWhileList[next, n, # > 1 &], mx},
mx = First@Ordering[data, -1];
{n, Length[data], data[[mx]], mx - 1}]
{TableForm[Table[stats@n, {n, 20, 39}],
TableHeadings -> {None, {"n", "length", "max", "max pos"}}]
You may also check:How to resolve the algorithm Loops/For step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Objeck programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the BASIC programming language
You may also check:How to resolve the algorithm Bulls and cows/Player step by step in the AutoHotkey programming language