Difference between revisions of "TI-BASIC:Scramble A String"
(Initial automated import) |
KermMartian (talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Template:TI-BASIC:Routine | {{Template:TI-BASIC:Routine | ||
− | |picture= | + | |picture=Scramble_Routine.gif{{!}}200px |
|summary=Scrambles a string | |summary=Scrambles a string | ||
|input=''Str1'' - The string you want to scramble | |input=''Str1'' - The string you want to scramble | ||
Line 6: | Line 6: | ||
|variable=Ans, Str1, L, θ, L₁, L₂ | |variable=Ans, Str1, L, θ, L₁, L₂ | ||
|compatibility=TI-83/84/+/SE | |compatibility=TI-83/84/+/SE | ||
− | |author= | + | |author= |
|authors=seb83, Edward H, Timothy Foster | |authors=seb83, Edward H, Timothy Foster | ||
− | |url= | + | |url= |
|download=[file scramble_prgm.zip] | |download=[file scramble_prgm.zip] | ||
}} | }} |
Latest revision as of 19:40, 25 February 2016
Routine Summary
Scrambles a string
Inputs
Str1 - The string you want to scramble
Outputs
Ans - The scrambled string
Variables Used
Ans, Str1, L, θ, L₁, L₂
Calculator Compatibility
TI-83/84/+/SE Authors
seb83, Edward H, Timothy Foster Download
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".
:rand(length(Str1→L₁ :cumSum(1 or Ans→L₂ :SortA(L₁,L₂ :sub(Str1,L₂(1),1 :For(N,2,length(Str1 :Ans+sub(Str1,L₂(N),1 :End
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:
:randIntNoRep(1,length(Str1→L₁ :sub(Str1,Ans(1),1 :For(N,2,length(Str1 :Ans+sub(Str1,L₁(N),1 :End