I need help figuring out the algorithm to display only a part of the string...

Code:
``` Prompt A,B            .Dimensions " →Str2 ------ For(C,2,A Str2+" "→Str2 End Str2→Str0 For(C,2,B Str0+Str2→Str0 End ------ 1→D           .X Axis for Display 0→E            .Y Axis for Display For(C,1,8 Output(C,sub(Str0,(E+(C-1)*B)+D,16 End ```

I need to display a certain 16×8 area in the string. Can any Smart Person Figure Out this? Also can someone please optimize the Marked area at the top of the code?
You are on track using the "sub(" command. If you use the third parameter in the sub command, which is length of the string, you may be able to find your solution. Use the link attached to read more about the sub command.

http://tibasicdev.wikidot.com/sub

oops i got the code wrong...
I edited the code above.
If your problem is what I think it is, then you must be getting an argument error. You are getting an argument error because the "output(" command cannot take strings in its parameters. You must first convert your string to a value, using the expr( command. The link is attached.

http://tibasicdev.wikidot.com/expr

well i need to fix the algorithm. the expr( command didnt work, the string has characters in it, not an expression.
DragonScholar71 wrote:
well i need to fix the algorithm. the expr( command didnt work, the string has characters in it, not an expression.

Of course if its not all digits, that won't work. You can always just optimize what you already have instead like this:

Code:
``` "<String>"→Str1 1→C For(Y,1,8 For(X,1,16 If " "≠sub(Str1,C,1 1→[A](Y,X End End ```

I didn't know you were planning on displaying the string directly since that code wasn't provided initially.
On a TI-84+CE (which is the one I have)…

Code:
```:ClrHome :“this is a string literal”->Str1 :Output(1,1,sub(Str1,11,6)) ```

Will produce:

Code:
```string⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ ```

On the homescreen (where the ⋅ symbol is an empty space).

If you’re still confused: “sub([Str1],[#2],[#3])” returns:
The first [#3] characters of [Str1], starting at the [#2]th character of [Str1]. Make sense?

Hope this helps!
Regarding the following part which you wanted optimized:

Code:
```For(C,2,A Str2+" "→Str2 End Str2→Str0 For(C,2,B Str0+Str2→Str0 End```

If you're trying to optimize for speed and don't care about the size, then something like this will be better:

Code:
```max(A,B→D not(fPart(.5min(A,B→E " For(𝑛,1,logBASE(D,2 Ans+Ans End For(𝑛,1,D-length(Ans Ans+" End If E Ans+Ans Ans→Str2 For(𝑛,2+2E,min(A,B),1+E Ans+Str2 End```

It works particularly well if the bigger dimension is a power of 2 (which is what you use in your example and I assume would be the most common) and the smaller dimension is an even number.
Its O(log n) instead of O(n) like yours so the improvements would be more apparent as the dimensions get bigger.

If you want to optimize for size, then just keep what you have and S H R I N K it.

Code:
```For(C,2,A Ans+" →Str0 End For(C,2,B Ans+Str0 End Ans→Str0```
The Optimization helped with the speed cause i don't care about the size. but the section that i was originally asking for help on is on the bottom and also is a display. Because for instance,

The string is this...
"AAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXXAAAAAAAAAAAAAAAAXXXXXXXXX"

(The Dimensions are 25x25)

I need to display this from the string...
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA

An 8x16 Area of all A's. and the code i have is...
:For(C,1,8
:Output(C,sub(Str0,>(E+(C-1)*B)+D<,16
:End

I need to fix the Algorithm that is pointed to.
I have some questions: Are you storing all maps in 1 string and are you wanting to scroll a 25x25 map but in a 16x8 window on the homescreen?

I'm not 100% sure what you're asking, but you just want to draw a section you could do:

:For(C,1,8
:Output(C,1,sub(Str0,(C-1+E)25+1+D,16
:End
Thanks, thats exactly what i needed! now i need help optimizing it for speed...
So The full code I have is...

Code:
``` ClrHome Input "1:New 0:Edit    ",θ If θ then Prompt A,B " →Str2 For(n,2,B Str2+" →Str2 End Str2→Str1 For(n,2,A Str1+Str2→Str1 End 1→X 1→Y 1→D 0→E Repeat G=105 D→N E→I% A For(n,1,8 Output(n,1,sub(Str1,(n-1+I%)Ans+1+N,16 End Output(Y,X,"_ Repeat Ans getKey End Ans→G If G>34 and not(G=45 or G=44):Then sub("ABC  DEFGHIJKLMNOPQRSTUVWXYZ<Inverse '='>/   ⋅ ",G-5iPart(.1G+4),1→C (E)A+1+D(Y+1)A+1+(X-3)→N C sub(Str1,1,N-1)+Ans+sub(Str1,N+1,length(Str1)-N→Str1 End Y+1(G=34→Y X-1(G=24→X X+1(G=26→X Y-1(G=25→Y If X>1 Then 16→X If D<A-16 D+1→D End If X<1 Then 1→X If D>1 D-1→D End If Y>8:Then 8→Y If E<B-16 E+1→E End Y<1:Then 1→Y If E>0 E-1→E End End ```

And I need to optimize it for speed, (P.S. I have a TI-84+ Newer model)
I am trying to execute this code on my calculator, but I keep getting a bunch of errors: (invalid dimension, undefined) are the main ones that I keep running into. I want to help but I want to see how this runs on my calculator first.
So here is my new and revised code...

Code:
``` Lbl AA ClrHome 0->M Menu("Map Maker       ","New",A,"Edit",B,"Exit",C Lbl B 1->M Lbl A If not(M    Then    Input "Xmax=",A    Input "Ymax=",B    " ->Str9    For(C,2,A       Str9+" ->Str9    End    Str9->Str0    For(C,2,B       Str0+Str9->Str0    End    6->dim(L1    Fill(0,L1 End L1(1)->A L2(2)->B L3(3)->D L4(4)->E L5(5)->X L6(6)->Y Repeat G=105    For(C,1,8       Output(C,1,sub(Str0,A(E+C-1)+1+D,16    End    Output(Y,X,"_    Repeat Ans       getKey    End    Ans->G    If G>34    Then       A(E-1)+D+AY+X->N       sub(Str0,1,N-1)+sub("ABC  DEFGHIJKLMNOPQRSTUVWXYZ   .? ",G-5iPart(.1G+4),1)+sub(Str0,N+1,length(Str0)-N->Str0    End    Y+1(G=34->Y    X-1(G=24->X    X+1(G=26->X    Y-1(G=25->Y    If Y>8    Then       8->Y       If E<B-8       E+1->E    End    If Y<1    Then       1->Y       If E>1       E-1->E    End    If X>16    Then       16->X       If D<A-16       D+1->D    End    If X<1    Then       1->X       If D>0       D-1->D    End End ```

I need help optimizing it for speed.

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.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum