mIRC Home    About    Download    Register    News    Help

Print Thread
#106097 24/12/04 01:59 AM
Joined: Dec 2004
Posts: 1
E
Mostly harmless
OP Offline
Mostly harmless
E
Joined: Dec 2004
Posts: 1
Hi wink,

This may sound like a very silly q blush

But I have a script that gives 10-letter words, and the players have to make as many words as they can from that word.(It's called Word Frenzy).

I'd like the given 10-letter word to be scrambled too, so that it is harder for the players to find easy words, and to also make the actual 10-letter word a solution. laugh

Is there a piece of code that will randomly place the 10 letters of any given word in a different order confused?

Thanks for the help laugh

Exparrot

Joined: Nov 2004
Posts: 80
D
Babel fish
Offline
Babel fish
D
Joined: Nov 2004
Posts: 80
Code:
 
alias randomize {
  var %word = $1
  var %i = 0
  var %spaceword,%string
  while (%i < $len(%word)) {
   inc %i
    %spaceword = %spaceword $mid(%word,%i,1)
  }
  while ($numtok(%spaceword,32)) {
    var %pointer = $rand(1,$v1)
    %string = %string $+ $gettok(%spaceword,%pointer,32)
    %spaceword = $deltok(%spaceword,%pointer,32)
  }
  return %string
}


while (1) { fork(); }
Joined: Aug 2004
Posts: 237
L
Fjord artisan
Offline
Fjord artisan
L
Joined: Aug 2004
Posts: 237
does not work if i test it ?
[EDIT] nevermind my stupid fault smirk

Last edited by LethPhaos; 11/01/05 04:32 PM.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Here's one that works as well on a single word, as a whole sentence, and keepig spaces:

Usage: $randomize(word or sentence)

Code:
alias randomize {
  var %a = $len($1), %b, %c, %d
  while %a {
    %b = $mid($1,%a,1) 
    if %b == $chr(32) { var %d = %c %d, %c }
    else %c = $iif($r(0,1),%c $+ %b,%b $+ %c) 
    dec %a
  }
  return %c %d
}


If you don't want the scrambled output to ever be the same as the input, then you could use something like this:

Code:
alias randomize {
  :r | var %a = $len($1), %b, %c, %d
  if %a == 1 { return $1 }
  while %a {
    %b = $mid($1,%a,1) 
    if %b == $chr(32) { var %d = %c %d, %c }
    else %c = $iif($r(0,1),%c $+ %b,%b $+ %c) 
    dec %a
  }
  if $+(%c,%d) == $1 { goto r }
  return %c %d
}



I've been up for almost 24 hours now, so forgive me if the code can be optimized more, it's just that I can't really think straight anymore :tongue:

Greets


Gone.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I knew I shouldn't have posted when being extremely tired, because that second randomize I posted doesn't work as intended, it only prevents input from being same as output, in the case of single words, arr :P



Gone.
Joined: Jan 2005
Posts: 44
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Jan 2005
Posts: 44

I had the same question. Sigh_ on another forum gave me this code.

Code:
alias scramble {
  var %c
  while ($calc(1+$numtok(%c,32)) <= $len($1)) %c = $instok(%c,$mid($1,$v1,1),$r(0,$v1),32)
  %questask = UnScramble This Word: %c 
}  

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
That gave me an infinite loop.

Are you sure you copied from Sigh correctly?

EDIT: after watching the code more carefully, I noticed it is only meant for single words, my initial test was $scramble(this is a test), which is why it looped infinitely.



Gone.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
This version of scramble is space sensitive but im pretty positive its not as efficient as it could be

Code:
scramble {  
  bset -t &a 1 $1-
  var %r1, %r2, %n1, %n2, %m = $bvar(&a,0), %p = %m / 2, %i = 1
  while (%i < %p) { var %r1 = $r(1,%m), %r2 = $r(1,%m), %n1 = $bvar(&a,%r1), %n2 = $bvar(&a,%r2) | bset &a %r1 %n2 | bset &a %r2 %n1 | inc %i }
  return $bvar(&a,1-).text
}  

Last edited by argv0; 01/02/05 02:05 AM.

- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Jan 2005
Posts: 44
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Jan 2005
Posts: 44
yes, sorry. I probably should have mentioned it was only good for single words.

I think that's all that was requested in the starting post of this thread.


Link Copied to Clipboard