How to resolve the algorithm EKG sequence convergence step by step in the Mathematica/Wolfram Language programming language

Published on 22 June 2024 08:30 PM

How to resolve the algorithm EKG sequence convergence step by step in the Mathematica/Wolfram Language programming language

Table of Contents

Problem Statement

The sequence is from the natural numbers and is defined by: The sequence is called the EKG sequence (after its visual similarity to an electrocardiogram when graphed). Variants of the sequence can be generated starting 1, N where N is any natural number larger than one. For the purposes of this task let us call:

If an algorithm that keeps track of the minimum amount of numbers and their corresponding prime factors used to generate the next term is used, then this may be known as the generators essential state. Two EKG generators with differing starts can converge to produce the same sequence after initial differences. EKG(N1) and EKG(N2) are said to to have converged at and after generation a(c) if state_of(EKG(N1).a(c)) == state_of(EKG(N2).a(c)).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm EKG sequence convergence step by step in the Mathematica/Wolfram Language programming language

The provided Wolfram code defines functions and calculates the next number in a sequence based on the last number and specific properties. Here's a breakdown of the code:

1. NextInSequence Function:

  • It takes a list seq as input, representing a sequence of numbers.
  • It calculates the last number of the sequence (last), the maximum number in the sequence (max), and a list of missing numbers (holes) in the sequence.
  • It selects the first number in holes that is not coprime with last. Coprime numbers are numbers that have no common factors other than 1. If no such number is found, it proceeds to the next step.
  • If no suitable number is found in holes, it starts from max and increments it until it finds a coprime number.
  • The function returns the new sequence with the next number appended to it.

2. EKGSequence Function:

  • It takes two integer arguments: start (the starting number) and n (the number of terms to generate).
  • It uses the Nest function to apply the NextInSequence function n - 2 times to the initial sequence {1, start}, generating the desired sequence.

3. Generating and Displaying Tables:

  • The code creates a table showing EKGSequence for different starting numbers (s). The table is displayed as a grid.

4. Length of Convergence:

  • It calculates the length of convergence between two EKGSequence sequences (starting at 5 and 7). It first finds the common sequence length (len) and then trims the sequences accordingly.
  • The code returns the length of the trimmed sequence plus 1, which represents the length of convergence between the two sequences.

Source code in the wolfram programming language

ClearAll[NextInSequence, EKGSequence]
NextInSequence[seq_List] := Module[{last, new = 1, holes, max, sel, found, i},
  last = Last[seq];
  max = Max[seq];
  holes = Complement[Range[max], seq];
  sel = SelectFirst[holes, Not[CoprimeQ[last, #]] &];
  If[MissingQ[sel],
   i = max;
   found = False; 
   While[! found,
    i++;
    If[Not[CoprimeQ[last, i]],
     found = True
     ]
    ];
   Append[seq, i]
   ,
   Append[seq, sel]
  ]
 ]
EKGSequence[start_Integer, n_] := Nest[NextInSequence, {1, start}, n - 2]

Table[EKGSequence[s, 10], {s, {2, 5, 7, 9, 10}}] // Grid

s = Reverse[Transpose[{EKGSequence[5, 1000], EKGSequence[7, 1000]}]];
len = LengthWhile[s, Apply[Equal]];
s //= Reverse[Drop[#, len]] &;
Length[s] + 1


  

You may also check:How to resolve the algorithm Call a function step by step in the VBA programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the zonnon programming language
You may also check:How to resolve the algorithm Sorting algorithms/Cocktail sort step by step in the Tcl programming language
You may also check:How to resolve the algorithm Write language name in 3D ASCII step by step in the Delphi programming language
You may also check:How to resolve the algorithm Split a character string based on change of character step by step in the Haskell programming language