How do you randomize wordS?
Author |
Message |
Kharybdis
|
Posted: 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
|
|
|
Clayton
|
Posted: 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
|
Posted: 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... |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Kharybdis
|
Posted: 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
|
Posted: Fri Jan 04, 2008 1:25 pm Post subject: RE:How do you randomize wordS? |
|
|
Remove the letter from the word. |
|
|
|
|
|
Kharybdis
|
Posted: 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
|
Posted: 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? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Kharybdis
|
Posted: Fri Jan 04, 2008 2:44 pm Post subject: Re: How do you randomize wordS? |
|
|
But.. i still don't know how to assign
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
|
|
|
Gooie
|
Posted: 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
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
|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Kharybdis
|
Posted: 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! |
|
|
|
|
|
|
|