Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: MRide on July 21, 2010, 11:18:01 am
-
I've written the following code in BASIC:
randInt(1,9->X
prgmNUM2STR
Str3->Str1
randInt(0,9->X
prgmNUM2STR
While Str3=Str1
randInt(0,9->X
prgmNUM2STR
End
Str3->Str2
randInt(0,9->X
prgmNUM2STR
While Str3=Str2 or Str3=Str1
randInt(0,9->X
prgmNUM2STR
End
Str1+Str2+Str3->Str1
I would like to convert this code into Axe. I know the randInt(s can be converted to rand^10->X, and I've replaced prgmNUM2STR with sub(NS).
If I'm using it correctly, I believe I can change Str3->Str1 into Copy(Str3,Str1,1) (I'm not entirely sure though.)
I am having the most trouble with Str1+Str2+Str3->Str1.
Also, If you know of a better way to generate a random three digit number where no two digits are the same, and store it as a string, that would be most appreciated.
-
A better way is like this: (I'll explain it in a moment, and note I'm storing the data at L1 rather than Str1)
rand^10+48->T->{L1
rand^9+48->S+(S>=T)->R->{L1+1
rand^8+48->S+(S>=T)->S+(S>=R)->{L1+2
0->{L1+3
It uses three variables for temporary purposes (R, S, and T) and the result is stored at L1
If you must use Str1, (you shouldn't have to) replace every L1 with Str1, add Zeros(4)->Str1 somewhere in your code, and remove the last line.
-
That code will not work, calcdude. The first routine will return a random number 0-9, the second, 0-8, the third ,0-7. In other words, they could still all end up being 7 or something.
[EDIT] Ignore this post.
-
that's what +(S>=T) and related are for. They pretty much skip over already-generated numbers.
-
Okay, I see it. I see how it works. Wow, that is really amazing. Wow, my bad.
-
Yes, this is great. Thanks, calcdude.
-
You're welcome. Glad to help! :)
-
That's some neat code Calcdude! Nice job! ;D