TI-BASIC:Scramble A String

From Learn @ Cemetech
Jump to navigationJump to search

Scramble Routine.gif

Routine Summary

Scrambles a string


Str1 - The string you want to scramble


Ans - The scrambled string

Variables Used

Ans, Str1, L, θ, L₁, L₂

Calculator Compatibility

TI-83/84/+/SE Authors

seb83, Edward H, Timothy Foster Download

file scramble_prgm.zip

This routine takes a string stored in Str1 and scramble it. The results is contained in Ans. For example, "ABCDE12345" could be scrambled to "B34AC1DE25".

:cumSum(1 or Ans→L₂

With your string stored in Str1, it creates L₁={1,2,3,4,...,length(Str1)}. After that, L₂ is created randomly to sort L₁ in function of L₂. L₁ now could look like {5,3,4,1,2} if you entered a 5 character string. In the For( loop, it takes one by one the character of Str1 accordingly to L₁ to store it to Ans. Your scrambled string is now in Ans.

For the TI-84+ and higher with a MathPrint or color OS, use this code instead:


Related Routines