
-----------------------------------
carrie
Thu Nov 18, 2004 7:27 pm

scrambling words
-----------------------------------
i have a school project in school and i need ur help on some ideas on how to scramble up words randomly (basically something like a game) i have an idea but i'm just not sure it's ryt i think u have to store it as a temp var wat do u guys think?? :oops:  :oops: i just suck at this thing i wish i was better  :oops:  :oops:

-----------------------------------
zylum
Thu Nov 18, 2004 8:55 pm


-----------------------------------
you mean scramble the letters in a word or scramble words in a sentence?

-----------------------------------
carrie
Thu Nov 18, 2004 9:12 pm


-----------------------------------
oh um scramble letters in a word

-----------------------------------
carrie
Thu Nov 18, 2004 9:27 pm


-----------------------------------
please help me!!

-----------------------------------
Mr. Glib
Thu Nov 18, 2004 10:10 pm


-----------------------------------
please help me!!

Carrie, it might be more helpful to us if we had a better understanding of the problem at hand. My interpretation of your dire straights is that you need some code to scramble a word. Does it matter how long the word is?

Here's what I suggest you do...

1)have the user input the word to a string var

2)figure out the length of the string var using the length function

3)take apart the string var using substrings

4)at random put the individual characters back together to form a garbled word.


var word : string
get word


var wordLength : int
wordLength := length (word)
var words : array 1 .. wordLength of string

for i : 1 .. wordLength
    words (i) := word (i .. i)
end for


var x, y: int
var temp:string
for i : 1 .. 10
    for j : 1 .. wordLength
        x := Rand.Int (1, wordLength)
        y := Rand.Int (1, wordLength)
        temp := words (x)
        words (x) := words (y)
        words (y) := temp
    end for
end for


-----------------------------------
HyperFlexed
Fri Nov 19, 2004 10:47 am


-----------------------------------
var word : string                        % Stores user's unput
var scramNum : int                       % Which letter will be moved
const scrambleTimes : int := 100         % Number of times string will be mixed

% Get user's input
get word : *
put ""

% Scramble string according to value of 'scrambleTimes'
for i : 1 .. scrambleTimes
    % Select substring to be moved
    scramNum := Rand.Int (1, length (word))
    % Reinitialize word by moving scramNum to the end
    if scramNum not= 1 then
        word := word (1 .. scramNum - 1) + word (scramNum + 1 .. *) + word (scramNum)
    else
        word := word (2 .. *) + word (1)
    end if
end for

% Output is a beautiful thing
put word

-----------------------------------
HyperFlexed
Fri Nov 19, 2004 10:51 am


-----------------------------------
please help me!!

Carrie, it might be more helpful to us if we had a better understanding of the problem at hand. My interpretation of your dire straights is that you need some code to scramble a word. Does it matter how long the word is?

Here's what I suggest you do...

1)have the user input the word to a string var

2)figure out the length of the string var using the length function

3)take apart the string var using substrings

4)at random put the individual characters back together to form a garbled word.


var word : string
get word


var wordLength : int
wordLength := length (word)
var words : array 1 .. wordLength of string

for i : 1 .. wordLength
    words (i) := word (i .. i)
end for


var x, y: int
var temp:string
for i : 1 .. 10
    for j : 1 .. wordLength
        x := Rand.Int (1, wordLength)
        y := Rand.Int (1, wordLength)
        temp := words (x)
        words (x) := words (y)
        words (y) := temp
    end for
end for


Why would you use the variable wordlength? why not go...

var words : array 1 .. length (word) of string

and better yet, put all your variables at the top. Just make your array flexible.

-----------------------------------
carrie
Fri Nov 19, 2004 4:07 pm


-----------------------------------
oh sorry for not explaining clearly... :oops:  :oops:  :oops: 
well i have this school project and it's a game where i have to program a group of words scrambled and then the player needs to arrange the words wat i need help with is how to scramble them randomly and yup that's basically it...oh and also the get statement...how can u use font.draw for the input on the get statement...*i hope that makes sense*

-----------------------------------
carrie
Fri Nov 19, 2004 8:34 pm


-----------------------------------
pleas someone help me???

-----------------------------------
zylum
Fri Nov 19, 2004 10:34 pm


-----------------------------------
oh um scramble letters in a word

i thought you said you needed the letters in the word to be scrambled... now you say you want to scrable a group of words? wtf?

anyways, you basically do the same thing mr. glib did... put all the words in the array, loop through each element and give it a new random position...


var words : array 1..numberOfWords of string
var temp : string
var idx : int


%put words in an array here

for i : 1..upper(words)
    idx := Rand.Int(1, upper(words))
    temp := words(idx)
    words(idx) := words(i)
    words(i) := temp
end for

-----------------------------------
HyperFlexed
Sat Nov 20, 2004 2:07 am


-----------------------------------
oh sorry for not explaining clearly... :oops:  :oops:  :oops: 
well i have this school project and it's a game where i have to program a group of words scrambled and then the player needs to arrange the words wat i need help with is how to scramble them randomly and yup that's basically it...oh and also the get statement...how can u use font.draw for the input on the get statement...*i hope that makes sense*

If you can't write this program by yourself, then I think that Font.Draw is the last thing you should be thinking about. Basics first. Fancy later.

-----------------------------------
Mr. Glib
Sat Nov 20, 2004 4:37 pm


-----------------------------------
 
Why would you use the variable wordlength? why not go...

var words : array 1 .. length (word) of string

and better yet, put all your variables at the top. Just make your array flexible.

Because I like more variables!  :D  :wink:
