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
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 02 Oct 2007 11:02:56 pm    Post subject:

The challenge is as follows:

Given a positive integer in Ans, compute the Ansth Fibonacci number as a list of digits (this allows one to calculate much larger Fibonacci numbers than manipulating real variables would).

Theoretically, you could calculate even larger numbers by putting several digits in one list element, but that's a trivial modification to make, so the challenge won't involve it.

I've written a fairly unoptimized version taking up 127 bytes (plus the length of the title - as usual). I don't expect that this is the best possible...

Edit: using strings for the output is also possible (I got 186 bytes using strings my first try).

The 100th Fibonacci number is 354 224 848 179 261 915 075 - as a useful test case.


Last edited by Guest on 23 Sep 2010 11:58:19 pm; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 03 Oct 2007 09:41:18 pm    Post subject:

Grr...my current version is 152 bytes. DarkerLine, does your version give valid answers for 1 and 2? Does it always uses lists of size 999, or does it resize the lists as necessary? Mine resizes and gives answers for 1 and 2, but not doing so would use less space, I suppose...
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 03 Oct 2007 09:45:42 pm    Post subject:

Mine does both (but only because the first two Fibonacci numbers are the same - I initialize a list to {1} and then go through a loop that doesn't happen for 1 or 2)

Last edited by Guest on 03 Oct 2007 09:46:13 pm; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 03 Oct 2007 09:53:51 pm    Post subject:

Hmm...the last line of my program is an End statement. If I remove it, then the program gives incorrect output. Why should the End statement be necessary? BTW, I use the optimization of placing another command on the same line as a DelVar. Is this a problem when the second command is a While loop or an If statement?

Edit: I put the DelVars on separate lines, and still removing the last token (End) breaks the program. I don't see how this makes any sense...


Last edited by Guest on 03 Oct 2007 10:02:52 pm; edited 1 time in total
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 04 Oct 2007 07:49:31 am    Post subject:

I have 107 bytes, but it returns the string in reverse order (so if you put in n=12, then it returns {4,4,1})

@magicdanw: what is it an end to? a loop or an If:then? You need the last end for a loop.
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 04 Oct 2007 12:59:47 pm    Post subject:

Yes, it's a for loop. For some reason, I was certain that the calculator automatically figured out the End, like it figures out closing parenthesis.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 04 Oct 2007 03:25:08 pm    Post subject:

My new attempt is 71 bytes and uses no list variables other than Ans.

Edit: highlight the contents of the quote box to see this answer.

Quote:
Ans→N
{1
For(I,2,N
10fPart(Ans)+.101int(Ans
If int(Ans(1
augment({0},Ans
10fPart(Ans)+cumSum(ΔList(int(augment(Ans,{0
End
int(Ans


Edit 2: changed to be 70 bytes.


Last edited by Guest on 23 Sep 2010 11:58:00 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