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: 13 Oct 2008 02:42:50 pm    Post subject:

Given a positive integer in A and a digit number in B (starting from the left-most digit - for example, in the number 264, 2 is the first digit), give the Bth digit of A.

I have 22 bytes, after subtracting 2 bytes for the program name

EDIT: I decided to edit out the hidden solution. I'll put it back once a few other people post


Last edited by Guest on 14 Oct 2008 10:03:32 pm; edited 1 time in total
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 13 Oct 2008 03:41:41 pm    Post subject:

22 bytes:
Quote:
:int(10fPart(A10^(B-int(log(E2A
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 13 Oct 2008 03:47:39 pm    Post subject:

Yeah, that's basically what I did:

Quote:

int(10fPart(A10^(B-2-int(log(A

Where 10^ is the token accessed by pressing 2ND LOG.
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 13 Oct 2008 06:57:26 pm    Post subject:

I had the same exact thing as bfr.

Here's an interesting way to do it:
Quote:
[font="courier new"]:int(10fPart(Asub(10^(B-int(log(A


Doesn't take any less space, though.
Back to top
Neekstar


Advanced Newbie


Joined: 14 Dec 2006
Posts: 75

Posted: 13 Oct 2008 09:05:07 pm    Post subject:

I had the same thing, only took about five minutes to get.
Back to top
JoostinOnline


Active Member


Joined: 22 Aug 2007
Posts: 559

Posted: 14 Oct 2008 09:20:30 pm    Post subject:

Neekstar wrote:
I had the same thing, only took about five minutes to get.
[post="127832"]<{POST_SNAPBACK}>[/post]

Way to be modest Rolling Eyes
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 16 Oct 2008 09:52:59 pm    Post subject:

To reverse the digits of a positive integer (142 becomes 241), you can also similarly do:

Quote:

sum(seq(10^(B)int(10fPart(Ans10^(B-1-int(log(Ans))))),B,int(log(Ans)),0,-1

I don't like those repeated int(log(Ans and all of those closing parentheses, but I don't see any other apparent optimizations.  I also have this slight feeling that the entire routine could be changed to be smaller...


which is 45 bytes


Last edited by Guest on 16 Oct 2008 09:56:07 pm; edited 1 time in total
Back to top
TheStorm


Calc Guru


Joined: 17 Apr 2007
Posts: 1233

Posted: 16 Oct 2008 10:44:39 pm    Post subject:

bfr I think this would be better but I'm not sure since you have to store it to A rather than just having it in ans.
Quote:

int(log(Ans
sum(seq(10^(B)int(10fPart(A10^(B-1-Ans))),B, ans,0,-1
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 16 Oct 2008 11:42:04 pm    Post subject:

Here's a 41-byte program to reverse the digits of a positive integer input.
Quote:
[font="Courier New"]:int(10fPart(Ans10^(-seq(X,X,1,1+log(Ans
:sum(Ans10^(dim(Ans)+cumSum(0Ans-1
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