This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic Brain Teasers => TI-BASIC
Author Message
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 29 Dec 2009 12:19:23 pm    Post subject:

In Ans is a string or a number (real or complex). Make a program that puts 0 or 1 in Ans depending on whether initially Ans was a string or a number. Note that this should work for any string or number.

I'm going to keep the size of mine hidden for now.
Mine is 30 bytes (after subtracting the length of the title from the memory menu size). ;P


Last edited by Guest on 29 Dec 2009 04:39:13 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 30 Dec 2009 01:40:04 pm    Post subject:

19 bytes say any string and only zero will produce 1.
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 30 Dec 2009 03:37:21 pm    Post subject:

Yeah, I have a version that works like yours (with 0 being treated as a string) that is 18 bytes (19 bytes without subtracting the length of the program name).

I guess I might as well give the size for my robust version that works for "any string or number," which is 30 bytes (you can confirm that I haven't improved it since yesterday by highlighting the line after the "I'm going to keep..." line in my original post, which was last edited yesterday, if you really care Razz).
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 31 Dec 2009 04:51:17 am    Post subject:

I have tried to solve this and haven't reach far...

But in the process I provoked some odd errors and curious behaviours... Neutral
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 31 Dec 2009 12:17:12 pm    Post subject:

I've gotten a version that works for any string or number in 23 bytes (returning 0 for a string and 1 for a number).

Last edited by Guest on 31 Dec 2009 12:17:59 pm; edited 1 time in total
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 31 Dec 2009 01:25:05 pm    Post subject:

After reading your reply, I have a version that is 23 bytes large and returns 1 for a number and 0 for a string. However, strictly speaking, it doesn't work for any number or string...although exception is really insignificant. I'll PM you or something about the exception.
Back to top
Builderboy2005


Advanced Newbie


Joined: 19 Apr 2009
Posts: 51

Posted: 01 Jan 2010 12:11:36 pm    Post subject:

I am completely at a loss as to how to achieve this. I was able to get a basic technique that only worked for non-decimal non-zero non-negative numbers, but that was a very hacky way and used over 300 bytes. It would seem you can only use operators that can take either a string or a umber as arguments? The only ones i have found are the + operator, and the = and != operators. Am i on the right track? If not, could somebody bump me in the right direction? Smile
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 01 Jan 2010 01:57:32 pm    Post subject:

You're on the right track. You can highlight the following facts (maybe just the first would be enough) that give hints about the way I made my versions. You pretty much just have to know these in order to make this routine the way I did.

Useful fact: You can store a string to a list variable (normally for attaching a formula to a list).

Another useful fact: You can store to the list LA simply by storing to the A character alone. For example: {0,1}->A .

Also, the (small) exception I was talking about in my 23-byte version, and possibly in DarkerLine's 23-byte version too: The fact that the + operator can be applied to strings and numbers is useful. However, an error is returned when one attempts to use the + operator with the "empty string" (which can be created by entering a quote on the home screen and then pressing enter). It's kind of a really insignificant and cheap exception though. =P I did not use the + operator in by 30-byte version that works for any number and any string (well, it works for any number and string as far as I know) .


Last edited by Guest on 01 Jan 2010 03:08:46 pm; edited 1 time in total
Back to top
Builderboy2005


Advanced Newbie


Joined: 19 Apr 2009
Posts: 51

Posted: 01 Jan 2010 04:19:00 pm    Post subject:

Ahhhh, I knew both of those two facts, but failed to put them together! That is unimaginably clever!
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 01 Jan 2010 08:21:05 pm    Post subject:

This is unimaginably clever! I can't figure this out at all. Those who have fiured it out are amazing. Great job!

After an hour of screaming at my calculator Smile I've only come up with an 8 byte thing of code that works for every input except for the number zero...
Back to top
calcdude84se


Member


Joined: 09 Aug 2009
Posts: 207

Posted: 01 Jan 2010 11:19:03 pm    Post subject:

Until that was explained, I, also, was at a total loss. Smile
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 03 Jan 2010 02:36:32 pm    Post subject:

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.)


The 23-byte version that doesn't work for the empty string (the string that can be created by entering a quote on the home screen and pressing enter) - likely similar to DarkerLine's:
Quote:

DelVar AAns->A
Ans=Ans+Ans or A


The 18-byte version that doesn't work for 0 - likely similar to Weregoose's and ztrumpet's:
Quote:

DelVar AAns->A
not(A


Sorry for any confusion there may have been for "Make a program that puts 0 or 1 in Ans depending on whether initially Ans was a string or a number." My wording was unclear. I meant that if initially Ans is a string, then the resulting Ans could be a 0 or a 1 (it didn't have to be a 0), and if initially Ans is a number, then the resulting Ans would be 0 if the 1 indicated a string, and the resulting ans would be 1 if 0 indicated a string (the resulting Ans for an integer didn't have to be 1 - the resulting Ans for an integer would be 1 minus the resulting Ans for a string).
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 03 Jan 2010 03:15:48 pm    Post subject:

My smaller program was one byte larger than your smaller program for one reason: it's hard to use not( on a complex number.

Last edited by Guest on 01 Jul 2010 09:57:50 am; edited 1 time in total
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 03 Jan 2010 03:22:52 pm    Post subject:

Ah, I didn't know about that...thanks for informing me. I didn't really test my 18-byte and 23-byte ones anyway, though, because they already had at least one exception.
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 03 Jan 2010 04:23:34 pm    Post subject:

Very nice brf! Insorak (on Omnimaga) had that small solution also. Great job!
Back to top
IAmACalculator
In a state of quasi-hiatus


Know-It-All


Joined: 21 Oct 2005
Posts: 1571

Posted: 04 Jan 2010 07:11:02 am    Post subject:

There's also the lame 68k version:
getType(ans(1))


Last edited by Guest on 01 Jul 2010 09:57:32 am; edited 1 time in total
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 07 Jan 2010 08:35:22 am    Post subject:

bfr wrote:
Here's my 30-byte solution that works for any input:
Quote:

DelVar AFor(B,1,1
Ans->A
Ans->B
A=B


This also can detect whether Ans is a list or a number.
More generally, it can detect if Ans is number or something else.
Really clever.

A little off topic now. [whiteout]max(, min(, arithmetic and comparison can be used to both numbers and lists...[/whiteout]
I am trying to do a routine that detects a number or a list (not formula lists) but smaller than this. If I had found a smaller solution, I would have opened the teaser.


Last edited by Guest on 12 Jul 2010 01:00:06 am; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement