Digit Sequence

How it Works

The algorithims below are the heart of this program.
sequenceNum takes an arguement num, in this case it is userDefined
sequenceNum is a recursive function that runs the sequencing until the amount of cycles requested is met
the actual sequencing is preformed within the for loop, loading the array with the count
of each digit in num by calling the function numCount. If the count of the digit (starting from digit 9)
does not return zero, multiple variables are set for parsing, displaying, and calling recursion.

sequence and requestSequence are used as controls to prevent an infinite loop and effectively enable recursion.
Abstraction as the recursive function eliminates many lines of code and makes for a more efficient program.

Overall the sequence takes the number and returns the count of each digit read.
If 1 is the first term, the second is 11 because there is a single digit of 1.
Term three is 21 because there are two counts of 1. The fourth term is 1211
because there is one count of 2, and one count of 1.

public void sequenceNum(int num)
{
  int[] numInput = new int[1000];
  String nextInput = "";
  String recursiveInput = "";
  int recursiveOutput = 0;

  for(int i=9; i>0; i--)
  {
   numInput[i] = numCount(str(num), i);
   if(numInput[i] != 0 || (numInput[i-1] !=0 && numInput[i+1] !=0))
   {
     nextInput = str(numInput[i]) + str(i);
     recursiveInput = recursiveInput + nextInput;
    recursiveOutput = int(recursiveInput);
   }
  }
    exportString = " || Input: " +num+ " || Output: "+ recursiveInput + " || Index: " + int(sequence+1);

    fill(25,200,255);
    textFont(slim);
    y=y+20;
    text(" || Input: " +num+ " || Output: "+ recursiveInput + " || Index: " + int(sequence+2),0,y);
  if(sequence != requestSequence)
  {
    sequence++;
    sequenceNum(recursiveOutput);
  }
}
public int numCount(String agrs, int num)
{
  int count = 0;
  for(int i = 0;i<(agrs).length();i++)
  {
    if(parseInt(agrs.substring(i,i+1)) == num)
      count = count+1;
  }
  return count;
}


Source Code