
-----------------------------------
Jurica
Mon Nov 10, 2008 4:23 pm

String Problem
-----------------------------------
Alright having problems with string now, tried to do it but couldn't figure it out. I've done some of it but not all of it.

Question: Write a Turing program that accepts a word typed at the keyboard.  Your program will then create the pattern illustrated like this one:

word
o__ r
r__ o              Ignore the ___'s.
drow

var word : string

% Tells you to enter a word
put "Enter word: " ..
get word
% Determines how much letters are in the words
put word, " has ", length (word), " letters."
put ""
% Top row

% Right row

% Bottom row

% Left row
for i : 1 .. length (word)
    put word (i)
end for

-----------------------------------
OneOffDriveByPoster
Mon Nov 10, 2008 4:34 pm

Re: String Problem
-----------------------------------
You can use code tags:[code]word
o  r
r  o
drow[/code]
gets you
word
o  r
r  o
drow

Anyhow, the first and last rows are obvious.
The middle rows will follow a pattern:  (2nd letter) ((length - 2) spaces) (2nd-to-last letter), etc.

-----------------------------------
Jurica
Mon Nov 10, 2008 4:38 pm

RE:String Problem
-----------------------------------
Said there were 3 errors, and 2 warnings.

-----------------------------------
Jurica
Mon Nov 10, 2008 4:45 pm

RE:String Problem
-----------------------------------
Okay, got it. But they put a random word, so it won't be the letter word that will be there, can be anything.

-----------------------------------
OneOffDriveByPoster
Mon Nov 10, 2008 4:48 pm

Re: RE:String Problem
-----------------------------------
Okay, got it. But they put a random word, so it won't be the letter word that will be there, can be anything.What I said applies to any input string.  You need a loop for the middle rows.  Follow the pattern and you will know what to put inside the loop.

-----------------------------------
Jurica
Tue Nov 11, 2008 3:37 pm

RE:String Problem
-----------------------------------
Okay, I finished it. The code to do it is:


var word : string
var current_line : int := 5
word := "word"
put ""
% Tells you to enter a word
put "Please enter a word: " ..
get word
% Determines how much letters are in the words
put "The word '", word, "' has ", length (word), " letters."
put ""
% Top Row
put word
% Left Row
for i : 2 .. length (word)-1
    put word (i)
end for
% Bottom Row
for decreasing i : length (word) .. 1
    put word (i) .. 
end for
% Right Row
for decreasing a : length (word)-1 .. 2
    locate (current_line, length (word))
    put word (a)
    current_line := current_line + 1
end for 


-----------------------------------
Jurica
Tue Nov 11, 2008 3:38 pm

RE:String Problem
-----------------------------------
Opps, made a mistake. Here's the right one:


% Variables 
var word : string 
var current_line : int := 5

% Tells you to enter a word 
put "Please enter a word: " .. 
get word 

% Determines how much letters are in the words 
put "The word '", word, "' has ", length (word), " letters." 
put "" 

% Top Row 
put word 

% Left Row 
for i : 2 .. length (word)-1 
    put word (i) 
end for 

% Bottom Row 
for decreasing i : length (word) .. 1 
    put word (i) .. 
end for 

% Right Row 
for decreasing a : length (word)-1 .. 2 
    locate (current_line, length (word)) 
    put word (a) 
    current_line := current_line + 1 
end for 

