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
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 30 Sep 2007 12:04:03 am    Post subject:

Alright, a brand new challenge for our newest forum. :)

Given a string stored in Ans that contains only capital letters and spaces, write a program that would encrypt the string with a suitable version of Atbash for Roman letters. (Google if you don't know what it is.)

Use as few string variables as possible.

thornahawk
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 30 Sep 2007 12:39:31 am    Post subject:

My first attempt uses Ans, Str1, Str2, and X. It's 101 bytes. I'll post it if I can't get it smaller.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 30 Sep 2007 01:48:31 am    Post subject:

I first took the straightforward approach, and ended up using five lines and no string variables (other than Ans)—this turned out to be [s]145[/s] 147 bytes. I'll work out a smaller version and then show both as hidden text in my next post.

[EDIT] – I now have a [s]100[/s] 101-byte version that uses two string variables (Str1 and Str2).

[EDIT×2] – I also now have a [s]118[/s] 120-byte version that uses only Str1 (along with the necessary looping variables).

[EDIT×3] – Oh jeez, and spaces? *reworks code*

[EDIT×4] – Fixed.

[FINAL EDIT] – I devised a neat hack that allowed me to cut off a few more bytes and speed up the process. Two of my routines through the use of this trick have essentially degenerated into the same program, so I'm back down to two entries. One is at four lines and 108 bytes, using only X and Ans, while the other comes in at 99 bytes from 7 lines and uses Str1, Str2, X, and Ans. These are what I'll present when all is said and done here.


Last edited by Guest on 23 Sep 2010 11:59:55 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: 30 Sep 2007 11:52:19 am    Post subject:

I've got a routine that uses no strings, other than Ans, and the real variable I, and weighs 88 bytes, plus the title.

[EDIT] - The technique I used is basically an extension of my solution for the previous teaser. The same string can be used for more than one purpose...


Last edited by Guest on 24 Sep 2010 12:00:36 am; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 30 Sep 2007 06:43:59 pm    Post subject:

Weregoose: I think my shortest version is the same as yours. It's 99 bytes, 7 lines, and uses those strings.

I don't want to let myself waste more time working on this, so I'm going to post my solution:

Quote:
Ans->Str1
" ABCDEFGHIJKLMNOPQRSTUVWXYZ ->Str2
".
For(X,1,length(Str1
Ans+sub(Str2,29-inString(Str2,sub(Str1,X,1)),1
End
sub(Ans,2,X-1


I'm not sure if I'm supposed to post the solution "invisible" or not, so I did just in case.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 30 Sep 2007 08:15:43 pm    Post subject:

magicdanw wrote:
Weregoose: I think my shortest version is the same as yours. It's 99 bytes, 7 lines, and uses those strings.
It's close, but there are some key differences actually. You can even save one more byte by (highlight) plugging a space in the middle of the string rather than having two on the sides. Also, I didn't use X like you did at the bottom, so I guess because of that you place above me size-wise. Now, I'm curious about those 88 bytes. :)

My first routine:
Spoiler wrote:
For(X,1,length(Ans
sub(Ans+sub(" ZYX…A",inString(" ABC…Z",sub(Ans,1,1)),1),2,length(Ans
End
Ans


Last edited by Guest on 24 Sep 2010 12:00:51 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: 30 Sep 2007 08:27:42 pm    Post subject:

Here's my routine:
Quote:
"A…M N…Z"+Ans
For(I,28,length(Ans
Ans+sub(Ans,28-inString(Ans,sub(Ans,I,1)),1
End
sub(Ans,I,I-28


As advertised, it's the same optimization as in my answer to the previous teaser.


Last edited by Guest on 23 Sep 2010 11:59:35 pm; edited 1 time in total
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 30 Sep 2007 09:05:18 pm    Post subject:

Very elegant solutions. Very Happy What I had, admittedly, took about 10 bytes or so of space more than the solutions posted here; I must make a public confession now, though: what I had was nothing more than an appropriate modification of the ROT13 program that was posted in Goose's site. :)

thornahawk
Back to top
adriweb


Newbie


Joined: 28 Aug 2007
Posts: 22

Posted: 16 Oct 2007 06:24:22 am    Post subject:

thornahawk wrote:
what I had was nothing more than an appropriate modification of the ROT13 program that was posted in Goose's site. Smile
Ohhhh ^^ lol

Great routine, DarkerLine !
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