Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: ztrumpet on January 01, 2010, 10:57:26 pm
-
Here's a challenge for all of you: In pure basic, figure out if Ans is a Number or a String.
It is possible, but I havn't figured out how. :P
If you figure it out, you win a cookie. :D
I have a solution for everything except the number zero. :( I can't figure out how to compleatly do it.
For more info, http://www.unitedti.org/forum/index.php?showtopic=9191
-
as long as ans /= B: B->A:Ans->A:If A=B:Ans is a string
Does that help?
EDIT: oops! i messed up i'll think about and redo it when i remember how it actually went, since i made this a while ago for a ramdom use of mine
-
Hmm...
:DelVar AAns-->A
:(A and 1)
is very short, and will give 1 in Ans if input was a number, or 0 if input was a string. I'm just trying to make zero work...
-
Insorak, that's exactly what I got. :D
Delvar AAns->A
not(not(A
I just wonder how to do it and have everything work.
-
I want to initialize A to something other than 0 before storing Ans to A. But that's obviously impossible, because initializing A changes Ans. >_<
-
Nope. :)
To intilize A to 500 without changing Ans:
For(A,500,0:End
;D
-
Would seem to work... but still not really what I was looking for.
Assume that A = i before program is run.
:Ans->A
:1 and imag(A
would work, giving 1 for all strings and 0 for all numbers.
Unfortunately, you can't increment a for loop to an imaginary value.
-
:DelVar A
:Prompt A
:0<abs(A
^best i got
-
Here's my 30-byte solution that works for any input:
DelVar AFor(B,1,1
Ans->A
Ans->B
A=B
One would probably want to close to have For(B,1,1:End instead if this routine were being used within a larger program. Also, I was hoping I could get rid of DelVar A and set A and B to different values using just For( by defining B in terms of A, but I'm not sure how to do that in a small way that always works (for positive and negative values of A, etc.)
See the original post (http://www.unitedti.org/forum/index.php?showtopic=9191&st=0&p=139646&#entry139646).
-
That's awesome! You've done a very good job! That's very, very smart. Way to go!
-
Genius, just explodes my mind that this can be done through all the little exploits that exist on the calculator.
-
Also, I was hoping I could get rid of DelVar A and set A and B to different values using just For( by defining B in terms of A, but I'm not sure how to do that in a small way that always works (for positive and negative values of A, etc.)
What about
For(B,A,A+1:End
Would that work?
-
I think it generally would, but:
- It would make the program be 31 bytes instead of 30
- The program would fail sometimes - for example, if A were a large value like 10^98 (E98) before the program ran
-
this is very impressive, it really shows me how much there still is for me to learn about this wonderful language
-
Before this, I never though there was even a remote chance that Basic would do something like type checking. Its something we have been telling beginers is impossible for a long time. Now we know differently!
-
How about between a list and string, or between a matrix and list... *wince*
-
How about between a list and string
Delvar LAAns->A
"->A
not(dim(LA
Edit: Fixed a bug
Edit2:
or between a matrix and list...
Delvar Adim(Ans->A
not(A
-
Well, all those solutions are better than the one I had by far. :P Just how do you people think of these things?!?!
-
Is it possible to tell if Ans is a matrix vs a string? Have fun with this one!
-
I am trying to do the list versus number. The string or number works too for list and number but maybe there is a smaller solution.
I will put the routines in TI-BD for archive. (EDIT: the number or string is already there ;) )