Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
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
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 17 Oct 2008 12:00:10 am    Post subject:

The program takes the digits of a number from a list, and the base of the number from a variable, and returns the number.

Inputs:
B - the base of the input number
Ans - a list containing the digits of the input number in reverse order

Output:
Ans - the value of the number inputted

Example:
With 5 in B, and {1,2,3,4} in Ans, return 586 = 1 + 2*5 + 3*25 + 4*125.

Goal: 20 bytes


Last edited by Guest on 11 Dec 2008 03:22:29 pm; edited 1 time in total
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 17 Oct 2008 08:42:19 pm    Post subject:

20 bytes:

Quote:

sum(AnsB‾ıB^(cumSum(Ans/Ans
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 17 Oct 2008 09:48:04 pm    Post subject:

This is what I had:
Quote:
[font="Courier New"]:sum(Ans/BB^cumSum(Ans or 1
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 18 Oct 2008 08:37:48 am    Post subject:

bfr wrote:
20 bytes:

Quote:

sum(AnsB‾ıB^(cumSum(Ans/Ans

[post="128005"]<{POST_SNAPBACK}>[/post]

That would give an error if any of the digits are zero. Wink
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 18 Oct 2008 10:33:13 am    Post subject:

Good catch, calcmaniac84.
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

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

17 bytes, assuming everything is a 1 byte token.
Quote:

"B^(n-1->u
sum(Ansu(1,dim(Ans


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


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 18 Oct 2008 12:26:55 pm    Post subject:

That returns a list, btw

EDIT: Nevermind, your new code doesn't return a list anymore. That still doesn't give the right answer, though, because you're doing: [digit]*B*1+[digit]*B*2... etc. instead of [digit]*B*0+[digit]*B*1

Without cumSum(, something like that would be a pretty nice solution though


Last edited by Guest on 18 Oct 2008 12:32:31 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 12:31:16 pm    Post subject:

my wireless pooped out right in the middle of fixing that with an edit Sad or I would have beat you to it.
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 18 Oct 2008 12:33:40 pm    Post subject:

elfprince13 wrote:
14 bytes, assuming everything is a 1 byte token.
Quote:

"B^n->u
sum(Ansu(1,dim(Ans

[post="128033"]<{POST_SNAPBACK}>[/post]

That returns the answer times B. Somewhere, you need to include a B-1. Also, the way we usually count program sizes is by taking its size from the Mem Mgmt menu and subtracting the length of the program title, so your program takes 27 bytes, by that standard.


Last edited by Guest on 22 Jul 2010 12:29:22 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 10:50:11 pm    Post subject:

haha, yeah, I just didn't have a calculator or emulator with me so I was doing that in my head, and I don't know how many bytes all the tokens I used are. I really just felt a need to exploit that cool u/v/w() thing DarkerLine posted.

also, you missed my edit with the fixed version.
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 20 Oct 2008 06:33:36 pm    Post subject:

Using the sequence functions in that way only really helps if you're using seq( multiple times with the same expression but different start and end values. It is very cool, though - a useful substitute for seq( in sum situations.

However, in this situation, seq( is more efficient than the sequence functions. You could do
Quote:
:sum(Ans/BB^seq(X,X,1,dim(Ans
and that would be 27 bytes, compared to 30 with your program.

The real point of this challenge was to use [font="Courier new"]cumSum(Ans or 1
as a replacement for seq(X,X,1,dim(Ans, which gives the smallest size at 20 bytes.

Last edited by Guest on 22 Jul 2010 12:28:36 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: 20 Oct 2008 11:03:08 pm    Post subject:

In general, cumSum(Ans=Ans) is more effective than cumSum(Ans or 1); although it's the same size, it won't fail for complex inputs. I suppose it doesn't really matter here, though.
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 GMT - 5 Hours

 

Advertisement