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

Username:   Password: 
 RegisterRegister   
 scrambling words
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
carrie




PostPosted: Thu Nov 18, 2004 7:27 pm   Post subject: 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?? Embarassed Embarassed i just suck at this thing i wish i was better Embarassed Embarassed
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Thu Nov 18, 2004 8:55 pm   Post subject: (No subject)

you mean scramble the letters in a word or scramble words in a sentence?
carrie




PostPosted: Thu Nov 18, 2004 9:12 pm   Post subject: (No subject)

oh um scramble letters in a word
carrie




PostPosted: Thu Nov 18, 2004 9:27 pm   Post subject: (No subject)

please help me!!
Mr. Glib




PostPosted: Thu Nov 18, 2004 10:10 pm   Post subject: (No subject)

carrie wrote:
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.

code:

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




PostPosted: Fri Nov 19, 2004 10:47 am   Post subject: (No subject)

code:
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




PostPosted: Fri Nov 19, 2004 10:51 am   Post subject: (No subject)

Mr. Glib wrote:
carrie wrote:
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.

code:

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...

code:
var words : array 1 .. length (word) of string


and better yet, put all your variables at the top. Just make your array flexible.
carrie




PostPosted: Fri Nov 19, 2004 4:07 pm   Post subject: (No subject)

oh sorry for not explaining clearly... Embarassed Embarassed Embarassed
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*
Sponsor
Sponsor
Sponsor
sponsor
carrie




PostPosted: Fri Nov 19, 2004 8:34 pm   Post subject: (No subject)

pleas someone help me???
zylum




PostPosted: Fri Nov 19, 2004 10:34 pm   Post subject: (No subject)

carrie wrote:
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...

code:

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




PostPosted: Sat Nov 20, 2004 2:07 am   Post subject: (No subject)

carrie wrote:
oh sorry for not explaining clearly... Embarassed Embarassed Embarassed
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




PostPosted: Sat Nov 20, 2004 4:37 pm   Post subject: (No subject)

HyperFlexed wrote:

Why would you use the variable wordlength? why not go...

code:
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! Very Happy Wink
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  [ 12 Posts ]
Jump to:   


Style:  
Search: