ScrambleString(string[]).. Help please.
#1

So basically, I want a function which takes a string, mixes the letters up together and throws them around, making "doomsday" to "dodsaymo" or something.

Don't post the function. Just hints and tips on what functions I need to make this.
Reply
#2

Just a quick question: Are you applying for 3rd party dev on LS-RP?
Reply
#3

save it as 2 strings, use a loop and string1[i+1] = 'h'; // what ever letter you want, i guess that a hint
Reply
#4

How could you guess lol
Reply
#5

Quote:
Originally Posted by chrism11
Посмотреть сообщение
save it as 2 strings, use a loop and string1[i+1] = 'h'; // what ever letter you want, i guess that a hint
Okey. That'd be enough. don't post anymore hints lol.
Reply
#6

That would be my solution
  • 1. Get the length of the string
  • 2. Get an random index with the length, random(length)
  • 3. Saving this char in a variable
  • 4. Shifting the other character to the right to free the left most position and fill the position where we took our char from
  • 5. Now we put the char in his new position, the left most
  • 6. Repeating step 2 - 5 and decreasing the length by one and increasing the start position (where we put the char in)
  • 7. Repeating step 2 - 6 till the length is lower than 2 (its nonsense to swap 1 char with itself)
If you use an second array you can skip step 3 - 5 and put the char directly in his new position in the second array
Reply
#7

Quote:
Originally Posted by introzen
Посмотреть сообщение
Okey. That'd be enough. don't post anymore hints lol.
Hey, can you publish the function here please?
Reply
#8

Well you could do something like this:
pawn Код:
new originalstring[size]; // originalstring contains the string to be scrambled
new scrambledstring[size]; // this will contain the scrambled string
new rand;
for(new i = 0, j = strlen(originalstring); i != j; i++)
{
  do
  {
    rand = random(j);
  }
  while(scrambledstring[rand] != 0);
  scrambledstring[rand] = originalstring[i];
}
Reply
#9

There are sorting algorithms, why not use one of those and take a weird sorting algorithm?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)