Palindrome Pseudo code

BlitzPlus Forums/BlitzPlus Beginners Area/Palindrome Pseudo code

methodman3000(Posted 2013) [#1]
This is an attempt to write pseudocode for this problam. Would this work or am I missing some major gaps?

From Doug Cooper's Oh Pascal
Write a program that asks for a five-letter Palindrome (a word that is spelled the same backwards and forwards then prints the letters out in this pattern.

12345 ;original word
23452 ;start at 2nd character as much as 5 characters replace start and follow
34523;start 3rd character as much as 5 characters join 3 and 4 character
45234 start 4th character as much as 5 characters mark 1st place with "empty set" follow with next two characters.
12345 ; print original word

Indention Indent to start character
Expand to 5 characters
1. set tabstop 1character print word
2. Set tabstop to 2nd character repeat until 5 characters
3. set tabstop to 3 element repeat until 5 width = charactersIn Succession
4 set for tabstop (4) width 5 print
5, Get back original word.


Does any of this make a lick of sense. or am I missing and overlooking some important useful things. Wouldn't I convert a string into a list then choose the starting element and the width (does it automatically go back to the tab stop or is there an explicit setting and option I need to involk?

Input "civic" "c", "i", "v", "i", "c", ;are spaces and , equivalent or do they have different properties unique.
Print Original string "Civic"
start with 2nd posistion "i" and add characters at 3,4,5,2,3
start with position "v" and join characters i,c,c,i
Start with position 4 and join cccivi
Return entire word.

What else do I need to know?


Yasha(Posted 2013) [#2]
This looks like another case where Pascal concepts don't map directly to BlitzPlus. For a start, BlitzPlus doesn't have a builtin list type, so there's no standard way to convert a string to one (using lists is entirely possible, but they're not present by default).

The business with tabstops looks like it's doing something similar to the Mid function, which extracts a substring from an input string, with no intermediate conversion necessary.


Floyd(Posted 2013) [#3]
This is, I suppose, an exercise in learning certain fundamentals. You get some text input, then manipulate it to achieve certain results. So you want to learn equivalent concepts in Blitz.

After getting some text you would have it stored in a string. Then use the string functions to transform it in various ways.
You will find them all listed in the String section of the documentation: http://blitzbasic.com/bpdocs/command_list_2d_cat.php?show=String

For example, if you had a string s$ = "ABCDE", then Left(s,2) would be "AB" and Right(s,3) would be "CDE". The pieces can be combined with the + string concatenation operator.

The Pascal example seems to be rotating the string to the left. You could make a function like this:

s$ = "ABCDE"

Print s
Print RotateLeft( s, 2 )  ; Shift everything two places left, moving the first two characters to the end.

WaitKey


Function RotateLeft$( a$, count )
	Return Right( a, Len( a ) - count ) + Left( a, count )
End Function



methodman3000(Posted 2013) [#4]
I have several questions involving this
If I wanted to check if the word was a palindrome could I say a$abcde"
a$ =Input("ABCDE")
print ;1st and 2nd places == 5th and 4th surpress the output
If not true ("Reenter Palindrome")
Print Rotate Left(a,2;shift everything two places left moving the first two characters to the end.
Rotate Left(a,3;shift everything three places to the right moving the second character adding the third character at the end.
Rotate Left a,4 shift everything 4 places to the left moving the second character, adding the 4th character to the end.

I know this isn't accurate but the maneuvering ability is damaged in my head which is the whole intelligence out of this exercise thanks I'll work on it.


bluemoon(Posted 2013) [#5]
This function checks odd numbered palandromes.


	Function checkPal$(s$)
	
		strLen=Len(s$)
		
		If strLen Mod 2 = 1 Then ;is it odd mumbered length string
		
			leftHalf$=Left$(s$,strLen/2+1) ;get half the string + 1
			DebugLog leftHalf$
		
			halfway = strLen/2+1 ;value of half string + 1 
		
			For x = strLen To halfway Step -1 ;count backward from len of string to half string len + 1
				rightHalf$=rightHalf$+Mid$(s$,x,1)  ;collect the pieces 
			Next
		
			DebugLog rightHalf$
			
			If leftHalf$ = rightHalf$ Then
				Return s$+" is a palandrome."
				Else
				Return s$+" is no palandrome."
			End If 
		
		End If
			
	End Function