mIRC Home    About    Download    Register    News    Help

Print Thread
while loop #100266 11/10/04 05:51 PM
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
this one was working before but now it is not
what is should do:

If a line is hello you
it should make all letters to dots
so ..... ...
but $rand(0,6) normal
.e..o y..

Code:
alias hnt {
  %a = 1
  %b = $len($1-)
  %hnt = $null
  %hnts = $rand(0,6)
  while (%a <= %b) {
    if ($mid($1-,%b,1) != $chr(32)) {
      if (%hnts >= 1) {
        %hnt = . $+ %hnt
        dec %b 
        dec %hnts
      }
      elseif (%hnts <= 1) {
        %hnt = $mid($1-,%b,1) $+ %hnt
        %hnts = $rand(0,6)
        dec %b
      }
    }
    elseif ($mid($1-,%b,1) == $chr(32)) { 
      %hnt = $chr(32) $+ %hnt 
      dec %b
    }
    return %hnt
  }
}


it was working before, I tried to change something but appereantly fcked it up


---
signatures own
Re: while loop #100267 11/10/04 06:05 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
I remade it, but every so often it goes into an infinite loop and you have to ctrl+break it, but i'll post it anyway because someone else might know what's wrong with it.

Here's some of the results for //echo -a $hnt(hello world!):

Quote:
he.lo world!
h..lo.wo..d.
h.llo world!
h.l.o.w..l.!


Code:
alias hnt {
  var %i = 1, %l = $len($1), %r = $rand(0,6), %n, %ret
  if (%r == 0) { return $1 }
  while ($count(%ret,.) < $iif(%r > %l,%l,%r)) {
    %i = 1
    while (%i < %l) {
      if ($rand(1,2) == 1) && (%n != %r) && ($mid($iif(%ret,$v1,$1),%i,1) != .) {
        %ret = $+($mid($iif(%ret,$v1,$1),1,%i),.,$mid($iif(%ret,$v1,$1),$calc(%i + 2)))
        inc %n
      }
      inc %i
    }
  }
  return %ret
}


Edit:

Heh, my bad, I did the opposite of what you wanted ($rand(0,6) were .s, not letters), here's the one you want (and it doesn't seem to go into an infinite loop smile):

Code:
alias hnt {
  var %i = 1, %l = $len($1), %r = $rand(0,6), %n, %ret
  .echo -q $regsub($1,/./g,\.,%ret)
  while ($regex(%ret,/[^\.]/g) < $iif(%r > %l,%l,%r)) {
    %i = 1
    while (%i < %l) {
      if ($rand(1,2) == 1) && (%n != %r) {
        %ret = $+($iif(%i > 1,$mid(%ret,1,$calc(%i - 1))),$mid($1,%i,1),$mid(%ret,$calc(%i + 1))))
        inc %n
      }
      inc %i
    }
  }
  return %ret
}

Last edited by tidy_trax; 11/10/04 06:21 PM.

New username: hixxy
Re: while loop #100268 11/10/04 06:09 PM
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
its not supposed to go into a infinite loop:) but I dont know nothing about $count so cant say whats wrong, thanks for the help lets hope for more replys:)


---
signatures own
Re: while loop #100269 11/10/04 06:33 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
I edited my post and it works now.


New username: hixxy
Re: while loop #100270 11/10/04 06:36 PM
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
I tried it ~10 times, and got once in a infinite loop


---
signatures own
Re: while loop #100271 11/10/04 06:38 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
The second one?

That doesn't happen with me:

Quote:
h.l...w...d.
h..lo ......
...l.....l..
h.... ..r.d.
..l.o ......
h...........
....o..or...
h.l.. ..rld.
he..........
.e..........
.e..o.......
.e.l........
h.llo.......
h.ll. ......
he.l. ......
h..l........
............
....o..o.l..
he.l. ..r.d.
h.... wo....


New username: hixxy
Re: while loop #100272 11/10/04 06:53 PM
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
Triggered with: //echo -a $hnts21(lalalala) (changed alias name to alias hnts21 for i already had alias hnt)

.a..l...
la......
la.ala..
.a......
........
* Break: command halted (line 26, ownstuff.nns)
.ala.al.

is what I get after using it some times.


---
signatures own
Re: while loop #100273 12/10/04 05:17 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi eendje,

sorry I have been afk for so long, I still don't have internet crazy

Usage: $hint(string)
Code:
 
alias hint {
  var %a, %b = $regsub($$1-,/./g,.,%a), %b = $r(0,6), %c
  bset -t &a 1 %a
  bset -t &b 1 $1-
  while %b {
    %c = $r(1,$bvar(&b,0))
    bcopy &a %c &b %c 1
    dec %b
  }
  return $bvar(&a,1-).text
}

In certain situations, the number of substitutions of different characters could be less than the random generated number, so maybe you could change $r(0,6) to $r(0,7) to balance the odds.

Though, since it's a random number anyway, it doesn't really matter.

Here are some results:

.e.........
he.l..w....
.e..o...r.d
.e.l. w.r.d
...........
.e..o......
...lo..o..d
.e......r..
..... w.r.d
...........
h...o....l.

Cya!

Edited code

Last edited by FiberOPtics; 12/10/04 05:39 PM.

Gone.
Re: while loop #100274 12/10/04 07:31 PM
Joined: Apr 2003
Posts: 42
E
eendje Offline OP
Ameglian cow
OP Offline
Ameglian cow
E
Joined: Apr 2003
Posts: 42
yes very cool:P dunno why mine doesnt work no more.
one problem on your script. it doesnt skip $chr(32). sometimes it does, sometimes it doesnt, I dont know how to make the if since your using some blabla code i dont know;P


---
signatures own
Re: while loop #100275 13/10/04 02:04 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Try this:
Code:
alias hintq {
  var %a, %b = $regsub($1-,/\S/g,.,%a), %r = $r(0,6), %c
  bset -tc &a 1 %a
  bset -tc &b 1 $1-
  while %r {
    %c = $pos($bvar(&a,1-).text,.,$r(1,%b))
    bcopy &a %c &b %c 1
    dec %r | dec %b
  }
  return $bvar(&a,1-).text
}

Last edited by qwerty; 13/10/04 02:23 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: while loop #100276 13/10/04 02:34 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

I didn't make it skip spaces, because your examples in the quote from tidy trax didn't make a distinction between spaces and other characters.

I'd end up making the thing that qwerty made, so copy his version.

Greets


Gone.