Author Topic: Figure out if Ans is a Number or a String  (Read 9099 times)

0 Members and 1 Guest are viewing this topic.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Figure out if Ans is a Number or a String
« 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

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Figure out if Ans is a Number or a String
« Reply #1 on: January 01, 2010, 11:25:30 pm »
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
« Last Edit: January 02, 2010, 01:20:47 am by cooliojazz »
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline Insorak

  • LV3 Member (Next: 100)
  • ***
  • Posts: 76
  • Rating: +4/-0
  • Omnimaga n00b
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #2 on: January 02, 2010, 04:02:49 pm »
Hmm...

Code: [Select]
: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...
« Last Edit: January 02, 2010, 04:08:19 pm by Insorak »
(re)working on Anti-RPG: 3% completion

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #3 on: January 02, 2010, 04:15:38 pm »
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.

Offline Insorak

  • LV3 Member (Next: 100)
  • ***
  • Posts: 76
  • Rating: +4/-0
  • Omnimaga n00b
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #4 on: January 02, 2010, 04:32:40 pm »
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. >_<
(re)working on Anti-RPG: 3% completion

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #5 on: January 02, 2010, 04:33:39 pm »
Nope. :)

To intilize A to 500 without changing Ans:
For(A,500,0:End
;D

Offline Insorak

  • LV3 Member (Next: 100)
  • ***
  • Posts: 76
  • Rating: +4/-0
  • Omnimaga n00b
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #6 on: January 02, 2010, 04:37:54 pm »
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.
« Last Edit: January 02, 2010, 04:45:02 pm by Insorak »
(re)working on Anti-RPG: 3% completion

Offline miotatsu

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 332
  • Rating: +11/-1
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #7 on: January 03, 2010, 08:49:50 am »
:DelVar A
:Prompt A
:0<abs(A
^best i got

Offline bfr

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 819
  • Rating: +4/-0
    • View Profile
    • bfr's website
Re: Figure out if Ans is a Number or a String
« Reply #8 on: January 03, 2010, 03:45:35 pm »
Here's my 30-byte solution that works for any input:
Quote

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.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #9 on: January 03, 2010, 04:21:07 pm »
That's awesome!  You've done a very good job!  That's very, very smart.  Way to go!

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #10 on: January 03, 2010, 05:18:49 pm »
Genius, just explodes my mind that this can be done through all the little exploits that exist on the calculator.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #11 on: January 03, 2010, 05:48:03 pm »
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?

Offline bfr

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 819
  • Rating: +4/-0
    • View Profile
    • bfr's website
Re: Figure out if Ans is a Number or a String
« Reply #12 on: January 03, 2010, 08:34:29 pm »
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

Offline miotatsu

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 332
  • Rating: +11/-1
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #13 on: January 03, 2010, 10:11:41 pm »
this is very impressive, it really shows me how much there still is for me to learn about this wonderful language

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Figure out if Ans is a Number or a String
« Reply #14 on: January 03, 2010, 10:21:09 pm »
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!