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
Zaphod Beeblebrox


Member


Joined: 02 Jul 2007
Posts: 119

Posted: 17 Oct 2008 05:56:09 pm    Post subject:

Write a program that given a value N, will return x, such that XX=10N.

My best program so far is 45 bytes, after subtracting the name.

EDIT: Find the closest approximation of x, not necessarily exactly x. And also, it should support values of N > 100.


Last edited by Guest on 17 Oct 2008 05:59:40 pm; edited 1 time in total
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 17 Oct 2008 06:18:23 pm    Post subject:

This is all I have:


Nln(10
solve(Ans-Yln(Y),Y,1+Ans


which is fine unless you wanted the *other branch* of the inverse of xx, or something that works for complex number inputs as well.

(edit)

...or it turns out that this is also OK:


solve(N-Ylog(Y),Y,1+N


thornahawk


Last edited by Guest on 17 Oct 2008 08:05:27 pm; edited 1 time in total
Back to top
Zaphod Beeblebrox


Member


Joined: 02 Jul 2007
Posts: 119

Posted: 17 Oct 2008 08:51:13 pm    Post subject:

Well, I was thinking you do the algorithm yourself, rather than having the calculator do it for you. This was (supposed to be) an exercise in creating your own algorithm and optimizing it. Oh well. I guess I didn't say that.

For example:
Quote:
{0,N->L1
Repeat N=Xlog(X
mean(L1->X
Ans->L1(1+(N<=Anslog(Ans
End


Last edited by Guest on 17 Oct 2008 08:54:26 pm; edited 1 time in total
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 18 Oct 2008 11:51:04 am    Post subject:

Quote:
prompt N
"X^X-EN->Y1
N->X
While (X^X-EN) > E-5
X-Y1(X)/nDeriv(Y1,X,X)->X
End
X


Last edited by Guest on 18 Oct 2008 11:54:45 am; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 18 Oct 2008 11:52:19 am    Post subject:

You should probably be aware that EN causes an error message.

Last edited by Guest on 22 Jul 2010 12:34:59 pm; edited 1 time in total
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 18 Oct 2008 11:53:01 am    Post subject:

Edit: Check my later post for a program that works way better.

32+2=34 bytes:
Quote:
[font="Courier New"]:1
:Repeat N=Anslog(Ans
:Ans+log(eX)-1(N-Anslog(Ans
:End

I used Newton's method and some clever logarithm manipulation.

Edit: I'm not sure if this always converges (it depends on what's in Ans). You might need to spend 2 or 4 bytes setting Ans at the beginning.

Edit: this works a little better, but it still overflows for larger N. 35 bytes.
Quote:
[font="Courier New"]:N
:Repeat N=Anslog(Ans
:abs(Ans+log(eAns)-1(N-Anslog(Ans
:End


Last edited by Guest on 18 Oct 2008 01:16:59 pm; edited 1 time in total
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 18 Oct 2008 11:57:47 am    Post subject:

urgh, that sucks, so we have to do 10^N instead of EN? I haven't programmed Basic in too long.

Ed, that mean's yours is broken too Razz
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 18 Oct 2008 11:59:05 am    Post subject:

elfprince, that's the base of the natural log, not the scientific notation exponent operation.
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 18 Oct 2008 12:04:36 pm    Post subject:

Ed H wrote:
32 bytes:
Quote:
:Repeat N=Anslog(Ans
:Ans+log(eX)-1(N-Anslog(Ans
:End

I used Newton's method and some clever logarithm manipulation.

[s]You're in calculator land now Smile log( is base-10, but ln( is Log. (I did the same thing, only it took me 20 minutes to figure out why it wouldn't work)[/s]
[edit] I lied Neutral I just worked it out and it's fine. (I must have fixed what my error originally was when I reworked it)


Last edited by Guest on 22 Jul 2010 12:35:38 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 18 Oct 2008 12:05:41 pm    Post subject:

It does work, actually: log is what you want in this case. Except it crashes if Ans doesn't happen to be a positive number.

Last edited by Guest on 18 Oct 2008 12:06:08 pm; edited 1 time in total
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 18 Oct 2008 12:07:36 pm    Post subject:

Edit: Hmm, my program doesn't converge or work on a lot of inputs. I'm not quite sure how to fix this. It seems to work alright if I put abs( in all my logs, but then I get overflow errors for large N, such as 9000.

@simplethinker:
Try it first, simplethinker. I do take into account the fact that log is base-10 and ln is base-e. I don't remember exactly the steps I followed in getting to that expression, but I plan on posting them later.

@Darkerline:
Ah yes, that is a rather serious error... I wonder if it will always converge if Ans starts at 1?


Last edited by Guest on 22 Jul 2010 12:34:22 pm; edited 1 time in total
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 18 Oct 2008 01:01:47 pm    Post subject:

I have 42 bytes.
Quote:
:[s]N[/s] 2
:Repeat not(abs(N-Anslog(Ans
:Ans-log(eAns)-¹Anslog(Ans)ln(n-¹Anslog(Ans
:End
:Ans

I used log(log(x^x=10^N)) instead of log(x^x=10^N). This also works for negative numbers as well.
I'm working on expanding this to an arbitrary number of log('s so if N can be inputted into the calculator then it should be able to return x.

Also, here's the derivation of Ed H's formula:

[edit]Dang, it only works for |N|>.1
[another edit] It stops working somewhere in .14<=|N|<=.15


Last edited by Guest on 18 Oct 2008 01:18:56 pm; edited 1 time in total
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 18 Oct 2008 01:13:06 pm    Post subject:

I found what was wrong with my program. I entered in an X instead of an Ans - funny thing, then, that it still worked for N up to like, 500! But now it converges almost instantly, and works for up to 1E98. Unfortunately, still no negatives.

Here is the actual program, at 34 bytes.
Quote:
[font="Courier New"]:N
:Repeat N=Anslog(Ans
:Ans+log(eAns)-1(N-Anslog(Ans
:End


Thanks for deriving my formula, by the way. I tend to do a lot of things in my head, and then forget how I did it later. >_>


Last edited by Guest on 18 Oct 2008 01:16:15 pm; edited 1 time in total
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 18 Oct 2008 01:23:33 pm    Post subject:

I just realized that using log(log( is kind of pointless. The problem with using log( 10^N=x^x) is with |N|<1.
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 18 Oct 2008 01:43:52 pm    Post subject:

Here's a version that converges for everything, in 48 bytes:
Quote:
[font="Courier New"]:{0,N
:While variance(abs(ans
:abs(Ans(2
:{Ans,Ans+log(eAns)-1(N-Anslog(Ans
:End
:Ans(2

The outputs may be negative... which makes it hard to determine whether the program got it right. Hmm...


Last edited by Guest on 18 Oct 2008 01:45:15 pm; edited 1 time in total
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 18 Oct 2008 11:28:14 pm    Post subject:

Without using solve( , I couldn't do better than this:


N+1
Repeat not(abs(Ans−F \\ this complication is needed so it does not break on negative/complex N
Ans→F
log(℮Ans)ֿ¹(N+Anslog(℮
End
Ans


Again, this is only the main branch of the inverse of log10(xx). Something more elaborate would be needed if you wish to see the other branches.

thornahawk


Last edited by Guest on 18 Oct 2008 11:32:49 pm; 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