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
AHBAD_ALVIN


Advanced Newbie


Joined: 18 Sep 2010
Posts: 74

Posted: 21 Sep 2010 08:13:31 pm    Post subject:

Here's a classic brainteaser for all you people who still want to use basic over ASM...

Let's see who can make a working version first. They win my respect as a maybe-not-as-noobish-BASIC-programmer.
See if you can make a parser that can transorm a string in base 19 numbers (0123456789ABCDEFGHI) and change it into a string in base 13 (0123456789ABC)

It's actually a bit a of a challenge if you haven't tried it before. I suggest using a string full of the base 19 and one of the base 13 characters, and heavy use of the instruction sub()

Good, luck, see who can get it first! (I'll post the answer in 2 days if you guys can't get it)


Last edited by Guest on 21 Sep 2010 08:14:21 pm; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 21 Sep 2010 10:19:17 pm    Post subject:

[spoiler] Input Str2
length(Str2→Z
"0123456789ABCDEFGHI→Str1
"*
→Str3
0
For(X,0,Z-1
Ans+19^X(inString(Str1,sub(Str2,Z-X,1))-1
End
While Ans
Ans/13→Z
sub(Str1,1+round(13fPart(Ans),1),1)+Str3→Str3
int(Z
End
sub(Str3,1,length(Str3)-1

[/spoiler]

*EDIT* 3 bytes smaller. Input is now used.

The routine takes a valid base 19 string via user Input and returns a base 13 string in Ans.
The round() command had to be used to prevent Domain errors due to inaccuracy in the floating point number arithmetic.

This solution most likely does not represent the smallest solution possible, but I believe it to be competitive.
As it currently stands, this solution takes [s]145[/s] 142 bytes of memory by the convention in the rules.

If you don't mind a "*" character in the result, replacing the last line with Str3 will make the routine 130 bytes.Razz


Last edited by Guest on 22 Sep 2010 02:36:15 am; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 22 Sep 2010 01:15:25 am    Post subject:

[spoiler]Input Str1
13→X
"0123456789ABCDEFGHI→Str2
length(Str1
sum(seq(19^(Ans-X)(inString(Str2,sub(Str1,X,1))-1),X,1,Ans→A
"
For(B,1,log(AX+1)/log(X
sub(Str2,1+int(round(XfPart(A/X^[escape]Cool[/escape])),1)+Ans
End
sub(Ans,1,B-1
[/spoiler]
139 bytes. If you don't mind a space character at the end of your result, you can replace the last line with Ans, dropping it down to 131 bytes.


Last edited by Guest on 22 Sep 2010 01:16:31 am; edited 1 time in total
Back to top
AHBAD_ALVIN


Advanced Newbie


Joined: 18 Sep 2010
Posts: 74

Posted: 22 Sep 2010 06:35:11 am    Post subject:

I proclaim [s]weregoose[/s] nitaku the winner so far. But can anyone make a SMALLER SCRIPT?

(which looks like it might be hard to do...)

Weregoose is actually in second, cause his is ONE BYTE larger when you make it simpler.


Last edited by Guest on 22 Sep 2010 06:22:42 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 22 Sep 2010 09:44:17 pm    Post subject:

I need to create a diversion!

Here are some values for testing for accuracy and the correct number of digits:

[font=courier new]C,D
8G,8H
61B,61C
4323,4324
2G29D,2G29E
1I0DCA,1I0DCB
16696B9,16696BA
H6879GF,H6879GG
BG7E2E9H,BG7E2E9I
8245CGHF5,8245CGHF6


I know mine is off by one in some of the middle cases (but the lengths should be perfectly stable throughout).

Last edited by Guest on 22 Sep 2010 10:06:35 pm; edited 1 time in total
Back to top
AHBAD_ALVIN


Advanced Newbie


Joined: 18 Sep 2010
Posts: 74

Posted: 25 Sep 2010 01:45:32 pm    Post subject:

mkay, nitacku wont his one. Nice, it actually beat mine (mine was very simular to weregoose's)

kk, you're a not-so-much-noobish-as-the-rest-BASIC-programmer!
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