Skip to content

Instantly share code, notes, and snippets.

@artificialstarlight
Last active December 30, 2018 19:43
Show Gist options
  • Save artificialstarlight/38b986a6847a4d5c9019130f0b40ff5c to your computer and use it in GitHub Desktop.
Save artificialstarlight/38b986a6847a4d5c9019130f0b40ff5c to your computer and use it in GitHub Desktop.
This code outputs n numbers of the look and say sequence given an integer input. (FIXED)
DelVar L1 //deletes variables
DelVar L2
0->C //initialize count variable
Input “ENTER INTEGER “, N //gets input from user and stores it in the variable N
If N=0 //If N is 0, append 1 to list one and display it, and end the program
Then
{1}->L1
Disp L1
Stop
End
If N=1 //If N is 1, append 1,1 to list one and display it, and end the program
Then
{1,1}->L1
Disp L1
Stop
End
{1,1->L1
For (I,2,N)
0->L1(1+dim(L1
1->C //update count variable
0->dim(L2 //create list two with size of zero
For (J,2,dim(L1) //for loop to process previous term to find the next term
If L1(J)=/=L1(J-1) //if current character doesn't match
Then
C->X //store C into variable X
X->L2(1+dim(L2 //put X into list two
L1(J-1)->L2(1+dim(L2 //append list one(j-1) into list two
1->C //update count variable
End //end first for loop
Else
C+1->C //else c += c
End //end if statement
End //end second for loop
L2->L1 //put list 2 into list 1
Disp L1 //Display list 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment