Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do you randomize wordS?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kharybdis




PostPosted: Wed Jan 02, 2008 8:11 pm   Post subject: How do you randomize wordS?

Ok. Say, for example, i have a word - Robot.

Can anyone give me any info on how i could go about randomizing the letters? But i don't need just help on how to do it with 5 letter words, but in general, for any word.

Knowing randint only works for numbers, how do you go about randomizing words ... so robot would instead be shown as obtor.

Would i have to use the ord value of each letter to randomize each individual word?
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Wed Jan 02, 2008 8:19 pm   Post subject: RE:How do you randomize wordS?

Hint:
Turing:
var word : string := "Robot"
put word (Rand.Int (1, length (word))
Tony




PostPosted: Wed Jan 02, 2008 8:26 pm   Post subject: Re: How do you randomize wordS?

Kharybdis @ Wed Jan 02, 2008 8:11 pm wrote:
Knowing randint only works for numbers...

Letter's position in a word (or an array... since a string is technically an array of characters) is a number...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Kharybdis




PostPosted: Thu Jan 03, 2008 9:01 pm   Post subject: Re: RE:How do you randomize wordS?

Clayton @ Wed Jan 02, 2008 8:19 pm wrote:
Hint:
Turing:
var word : string := "Robot"
put word (Rand.Int (1, length (word))


hey ty..... i can do it for any word.............. but right now i'm just tring to figure out how to put the whole thing as random.

Ty for hint.

However, two last questions. How do you specify if a position of string say word(3) has already been used? How do you assign rand.Int (1, length(word))) to something like a variable.

if (rand.int(1,length(word))) = index(word,letter) then
..... this is all i got.... i have no idea how to say if the position has been used to not use it again.
Clayton




PostPosted: Fri Jan 04, 2008 1:25 pm   Post subject: RE:How do you randomize wordS?

Remove the letter from the word.
Kharybdis




PostPosted: Fri Jan 04, 2008 2:10 pm   Post subject: Re: RE:How do you randomize wordS?

Clayton @ Fri Jan 04, 2008 1:25 pm wrote:
Remove the letter from the word.


but how....

All i got is :

Turing:
var word := "abc"
var letter := word(1) %this should be assigned to letter := the position randomized by Rand.Int (1, length(word))).

%for loop goes here - for the length of the word, do the loop each time and randomize one position, show it, delete that position from the word, randomize it again, and so on, until the word is completed. The word is shown completely randomized.

if (Rand.Int (1, length(word))) = index(word,letter) +1 then
put word
%dont know what to do next, but this is where the letter is supposed to be removed and where i am having trouble.
end if


And i have no idea at all how to do it so letter := the position randomized by Rand.Int (1, length(word))).
Tony




PostPosted: Fri Jan 04, 2008 2:24 pm   Post subject: RE:How do you randomize wordS?

hint:

If you have a 5 letter word -- abcde

And you remove a letter in the 3rd position -- c

What "word" would have all of the remaining letters?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Kharybdis




PostPosted: Fri Jan 04, 2008 2:44 pm   Post subject: Re: How do you randomize wordS?

But.. i still don't know how to assign
Turing:

(Rand.Int (1, length(word)))


as something that can be manipulated... how to assign it as a variable.

What i'm tryint to do is tell turing that when the position is randomized, that position is deleted from the word. I can't do it for just any individual word, but for all the words that can be entered.

Turing:
var word := "abc"

for i : 1..length(word)

put word (Rand.Int (1, length(word)))
word :=

end for
Sponsor
Sponsor
Sponsor
sponsor
Gooie




PostPosted: Sat Jan 05, 2008 12:58 am   Post subject: Re: How do you randomize wordS?

Kharybdis @ January 4th, 2:44 pm wrote:
But.. i still don't know how to assign
Turing:

(Rand.Int (1, length(word)))


as something that can be manipulated... how to assign it as a variable.

What i'm tryint to do is tell turing that when the position is randomized, that position is deleted from the word. I can't do it for just any individual word, but for all the words that can be entered.

Turing:
var word := "abc"

for i : 1..length(word)

put word (Rand.Int (1, length(word)))
word :=

end for


They're already assigned to variables, a 'string' is only an array of 'char'. What do you need to do with the word? There are different solutions for different problems.
Tony




PostPosted: Sat Jan 05, 2008 2:09 am   Post subject: Re: RE:How do you randomize wordS?

@ Kharybdis
Tony @ Fri Jan 04, 2008 2:24 pm wrote:
hint:

If you have a 5 letter word -- abcde

And you remove a letter in the 3rd position -- c

What "word" would have all of the remaining letters?

it's abde

more specifically, since we are using the letter at the 3rd position, what we have left is 1..2 + 4..5
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Kharybdis




PostPosted: Sat Jan 05, 2008 12:36 pm   Post subject: Re: How do you randomize wordS?

i got the answer before you posted tony, but that clarifies it even more.

TY everyone!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: