<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Some string manipulation routines</title>
		<link>http://tibasicdev.wikidot.com/forum/t-178449/some-string-manipulation-routines</link>
		<description>Posts in the discussion thread &quot;Some string manipulation routines&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Mon, 20 Apr 2026 06:26:14 +0000</lastBuildDate>
		
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-178449#post-570082</guid>
				<title>Re: Some string manipulation routines</title>
				<link>http://tibasicdev.wikidot.com/forum/t-178449/some-string-manipulation-routines#post-570082</link>
				<description></description>
				<pubDate>Wed, 26 Aug 2009 19:50:46 +0000</pubDate>
				<wikidot:authorName>DarkerLine</wikidot:authorName>				<wikidot:authorUserId>961</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Okay. Take a deep breath. Now rewrite the program to store things as a matrix instead of a string (or maybe a list of strings. Or something. Experiment!). Also, treating all of those different cases separately instead of all at once is just&#8230; wrong.</p> <p>Edit: here's a neat way to apply gravity to a single row, stored as a list (unfortunately, doesn't work in a function):</p> <div class="code"> <pre><code>:row=0*row→z :SortD z,row</code></pre></div> <p>For a matrix, the code would probably be like:</p> <div class="code"> <pre><code>:For r,1,rowDim(mat) : mat[r]→row : row=0*row→z : SortD z,row : row→mat[r] :EndFor</code></pre></div> <p>Edit: dammit, I don't think SortD is stable, so that isn't guaranteed to work. Oh well.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://tibasicdev.wikidot.com/forum/t-178449#post-569782</guid>
				<title>Some string manipulation routines</title>
				<link>http://tibasicdev.wikidot.com/forum/t-178449/some-string-manipulation-routines#post-569782</link>
				<description></description>
				<pubDate>Wed, 26 Aug 2009 03:50:51 +0000</pubDate>
				<wikidot:authorName>Rigel314</wikidot:authorName>				<wikidot:authorUserId>339594</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I am writing a game based on Puzzle Frenzy. It is almost pure basic, it uses Exec to fill and restore the screen, and it also depends on an ASM program called drawstr.<br /> I have elected to store all levels as strings.<br /> Every level's string can be up to 60 characters, representing 10 columns of 6 rows.<br /> It stores levels by column. Each column must be complete, so the length is divisible by 6.<br /> Level 2's string looks like: &quot;002300003200003200&quot;, it represents:</p> <p>000<br /> 000<br /> 233<br /> 322<br /> 000<br /> 000</p> <p>The game creates pictures at run-time and displays them according to the level string.<br /> I need a function that takes a level string as an input and moves all &quot;0&quot; characters, in a row, to the end of the row and returns the new level string.<br /> I also need a function that takes a level string and replaces all 3 or more of the same number in a row, or column, with &quot;0&quot;<br /> I have working functions for both, but they are very slow.<br /> For an average-sized level, each of these functions has about a 5 second calculation time.<br /> The game is playable, but no one would ever want to wait at least 10 seconds per move (both functions have to run at least once per move.)</p> <p>If it matters, I'm using a TI-89 Titanium: OS version 3.10, and Hardware version 3.</p> <p>I guess I'm asking for algorithmic optimization help. Maybe this goes on the optimization challenges page.<br /> If by some very unlikely event that no one is able to help me I will just use these inefficient routines and write this game in C. I wanted to try to push the limits of TIBasic, like I've been encouraged to do, but I'll need some help, not being as good as I thought after discovering this site.</p> <p>My &quot;0&quot; moving function:</p> <div class="code"> <pre><code>lvgrav(x) Func Local t,z,xy,c,y,s,e,yx &quot;&quot;»yx For z,1,6 &quot;&quot;»y For t,z,dim(x),6 y&amp;mid(x,t,1)»y EndFor &quot;&quot;»s &quot;&quot;»c dim(y)»xy For t,1,xy mid(y,t,1)»e If e&quot;0&quot; s&amp;e»s If e=&quot;0&quot; c&amp;&quot;0&quot;»c EndFor yx&amp;s&amp;c»yx EndFor &quot;&quot;»y For z,1,dim(x)/6 For t,z,dim(x),xy y&amp;mid(yx,t,1)»y EndFor EndFor Return y EndFunc</code></pre></div> <p>My three-in-a-row function:</p> <div class="code"> <pre><code>mvcalc(x) Func Local z,t,ul,c,e,y,f,s,yx,rplcchr Define rplcchr(sstr,enum,schr)=Func Return mid(sstr,1,enum-1)&amp;schr&amp;mid(sstr,enum+dim(schr),dim(sstr)-enum) EndFunc x»y dim(x)»ul For t,1,ul,6 mid(x,t,6)»f &quot;&quot;»e If inString(f,&quot;111&quot;)0 rplcchr(y,t+inString(f,&quot;111&quot;)-1,&quot;000&quot;)»y If inString(f,&quot;222&quot;)0 rplcchr(y,t+inString(f,&quot;222&quot;)-1,&quot;000&quot;)»y If inString(f,&quot;333&quot;)0 rplcchr(y,t+inString(f,&quot;333&quot;)-1,&quot;000&quot;)»y If inString(f,&quot;444&quot;)0 rplcchr(y,t+inString(f,&quot;444&quot;)-1,&quot;000&quot;)»y If inString(f,&quot;555&quot;)0 rplcchr(y,t+inString(f,&quot;555&quot;)-1,&quot;000&quot;)»y If inString(f,&quot;1111&quot;)0 rplcchr(y,t+inString(f,&quot;1111&quot;)-1,&quot;0000&quot;)»y If inString(f,&quot;2222&quot;)0 rplcchr(y,t+inString(f,&quot;2222&quot;)-1,&quot;0000&quot;)»y If inString(f,&quot;3333&quot;)0 rplcchr(y,t+inString(f,&quot;3333&quot;)-1,&quot;0000&quot;)»y If inString(f,&quot;4444&quot;)0 rplcchr(y,t+inString(f,&quot;4444&quot;)-1,&quot;0000&quot;)»y If inString(f,&quot;5555&quot;)0 rplcchr(y,t+inString(f,&quot;5555&quot;)-1,&quot;0000&quot;)»y If inString(f,&quot;11111&quot;)0 rplcchr(y,t+inString(f,&quot;11111&quot;)-1,&quot;00000&quot;)»y If inString(f,&quot;22222&quot;)0 rplcchr(y,t+inString(f,&quot;22222&quot;)-1,&quot;00000&quot;)»y If inString(f,&quot;33333&quot;)0 rplcchr(y,t+inString(f,&quot;33333&quot;)-1,&quot;00000&quot;)»y If inString(f,&quot;44444&quot;)0 rplcchr(y,t+inString(f,&quot;44444&quot;)-1,&quot;00000&quot;)»y If inString(f,&quot;55555&quot;)0 rplcchr(y,t+inString(f,&quot;55555&quot;)-1,&quot;00000&quot;)»y If f=&quot;111111&quot; rplcchr(y,t,&quot;000000&quot;)»y If f=&quot;222222&quot; rplcchr(y,t,&quot;000000&quot;)»y If f=&quot;333333&quot; rplcchr(y,t,&quot;000000&quot;)»y If f=&quot;444444&quot; rplcchr(y,t,&quot;000000&quot;)»y If f=&quot;555555&quot; rplcchr(y,t,&quot;000000&quot;)»y EndFor For t,1,6 &quot;&quot;»f For z,t,ul,6 f&amp;mid(x,z,1)»f EndFor If inString(f,&quot;111&quot;)0 Then For z,0,2 rplcchr(y,t+6*z+6*(inString(f,&quot;111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;222&quot;)0 Then For z,0,2 rplcchr(y,t+6*z+6*(inString(f,&quot;222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;333&quot;)0 Then For z,0,2 rplcchr(y,t+6*z+6*(inString(f,&quot;333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;444&quot;)0 Then For z,0,2 rplcchr(y,t+6*z+6*(inString(f,&quot;444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;555&quot;)0 Then For z,0,2 rplcchr(y,t+6*z+6*(inString(f,&quot;555&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;1111&quot;)0 Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;1111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;2222&quot;)0 Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;2222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;3333&quot;)0 Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;3333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;4444&quot;)0 Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;4444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;5555&quot;)0 Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;5555&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;11111&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;11111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;22222&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;22222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;33333&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;33333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;44444&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;44444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;55555&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;55555&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;111111&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;111111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;222222&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;222222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;333333&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;333333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;444444&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;444444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;555555&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;555555&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;1111111&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;1111111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;2222222&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;2222222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;3333333&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;3333333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;4444444&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;4444444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;5555555&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;5555555&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;11111111&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;11111111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;22222222&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;22222222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;33333333&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;33333333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;44444444&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;44444444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;55555555&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;55555555&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;111111111&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;111111111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;222222222&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;222222222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;333333333&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;333333333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;444444444&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;444444444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If inString(f,&quot;555555555&quot;)0 Then For z,0,4 rplcchr(y,t+6*z+6*(inString(f,&quot;555555555&quot;)-1),&quot;0&quot;)»y EndFor EndIf If f=&quot;1111111111&quot; Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;111111111&quot;)-1),&quot;0&quot;)»y EndFor EndIf If f=&quot;2222222222&quot; Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;2222222222&quot;)-1),&quot;0&quot;)»y EndFor EndIf If f=&quot;3333333333&quot; Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;3333333333&quot;)-1),&quot;0&quot;)»y EndFor EndIf If f=&quot;4444444444&quot; Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;4444444444&quot;)-1),&quot;0&quot;)»y EndFor EndIf If f=&quot;5555555555&quot; Then For z,0,3 rplcchr(y,t+6*z+6*(inString(f,&quot;5555555555&quot;)-1),&quot;0&quot;)»y EndFor EndIf EndFor Return y EndFunc</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>