mIRC Home    About    Download    Register    News    Help

Print Thread
#146853 09/04/06 06:31 PM
Joined: Jan 2006
Posts: 15
B
BatSaly Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2006
Posts: 15
Please,
I have need of some script that generate succession of 30 in number 0 and 1. And in this succession it musn't have pieces that are repeated 3 times in turn. It musn't have pieces exemplarily like this: 000, 111, 010101, 100110011001 and ...and so on and so forth smile

#146854 10/04/06 12:15 AM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Now just explain that in english.

#146855 10/04/06 02:03 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
So you want to take 1073741824 unique binary numbers, remove any that have the same sequence 3 times in a row? Is that right? Or maybe you want binary numbers with 30 digits that don't have the same sequence 3 times in a row?

Please give an example of what you want.

-genius_at_work

#146856 10/04/06 11:53 AM
Joined: Jan 2006
Posts: 15
B
BatSaly Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2006
Posts: 15
No, I just want to generate a row of 0 and 1. Not other figures. The combinations like 000, 010101, 100110011001 are forbidden. There is element "01" 3 times in 010101 and this is forbidden.And i don't know how to make it in mirc scripting frown
In Pascal the code is like this:
Code:
 program genstr;
type strarr = array[1..30] of integer;
var i,j,k : integer;
    br, start: integer;
    B : strarr;

function min (r: integer; s: integer):integer;
begin;
if r >= s then min := s
else min := r;
end;

function noseq (var A: strarr; usedlen:integer;el:integer ): boolean;
var i, j, k, t, q, br, l, flag: integer;
helparr : array [1..10] of integer;
begin
    A[usedlen] := el;           
    q:= usedlen div 3;          
    for j:= 1 to q do           
        for i:= 1 to j do       
        begin
             br:= 0;            
             for l := 1 to j do helparr [l] := 2;     

             flag := 0;
             for k := i to usedlen do           
             begin
                  if (k mod q) = 0 then t:= q
                  else t := k mod q;        
                  if k mod q = 1 then       
                  begin
                       if flag = q then     
                       begin
                            br := br+1;
                            if br= 2 then noseq := false    
                            else br := 0;
                       end
                  else flag := 0;       
                  end;
                  if A[k]= helparr[t] then flag := flag + 1;
                  helparr [t] := A[k];
             end;
             if br < 2 then noseq := true;
        end;

end;

procedure newel (var A:strarr;var i:integer;start: integer; el:integer);
begin
if noseq (A, i, el) = true then
   begin
        A[i] := el;
        i:= i+1;
        if i < start then newel (A, i , start, (random(256)mod 2));
   end
else
    begin
    if noseq(A, i, ((el + 1) mod 2)) = true then
       begin
            A[i]:= (el + 1) mod 2;
            i := i+ 1;
            if i < start then newel (A, i , start, (random(256) mod 2));
       end
    else
        begin
        i:=i - 1;
        newel(A, i , start, (A[i] mod 2));
        end
    end;
end;

begin
br := 0;
i := 1;
write ('String generation is on');writeln('');
repeat
      k:=( random (256) mod 2);
      start := i;
      newel(B, i, start, k);
      br:= br + 1;
until  (i > 29) or (br > 1000 );
if br > 1000 then write (' Can not generate str')
else begin
     for j := 1 to 30 do write (B[j]);
    end;
end. 

#146857 10/04/06 12:02 PM
Joined: Jan 2006
Posts: 15
B
BatSaly Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2006
Posts: 15
Quote:
Or maybe you want binary numbers with 30 digits that don't have the same sequence 3 times in a row?

-genius_at_work

This is right laugh but the row of digits must be only with 0 and 1. Some other like 2, 3, 4, 5, 6, 7, 8, 9 are unneeded.

#146858 10/04/06 12:51 PM
Joined: Jan 2006
Posts: 15
B
BatSaly Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2006
Posts: 15
or some like this in C:
Code:
 #include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef unsigned short USHORT;

#define BIN_LEN   30
#define FALSE      0
#define TRUE      !FALSE

int SearchThreeRepeats( USHORT i, char *BinStr )
{
  USHORT p = 1;
  char   Buf[(BIN_LEN / 3) + 1],
         OldBuf[(BIN_LEN / 3) + 1] = "";
  USHORT j;

  for ( j = 0; j < BIN_LEN; j += i ) {
    strncpy( Buf, BinStr + j, i );
    Buf[i] = 0;

    if ( strcmp( OldBuf, Buf ) == NULL )
      p++;
    else
      p = 1;

    strcpy( OldBuf, Buf );

    if ( p == 3 )
      return( TRUE );
  }
  return( FALSE );
}

int CheckRepeatTriad( char *BinStr )
{
  USHORT i;
  for ( i = 1; i <= BIN_LEN / 3; i++ ) {
    if ( SearchThreeRepeats( i, BinStr ) )
      return( TRUE );
  }
  return( FALSE );
}

int main(int argc, char* argv[])
{
  USHORT i;
  char   BinStr[BIN_LEN + 1] = "";
  char   c[2];

  randomize();

  do {
    while ( TRUE ) {
      for ( i = 0; i < BIN_LEN; i++ ) {
        itoa( rand() % 2, c, 2 );
        BinStr[i] = c[0];
      }
      BinStr[BIN_LEN] = 0;
      if ( ! CheckRepeatTriad( BinStr ) )
        break;
    }
    printf( "Binary String = %s\nNew String (Y/N)?\n", BinStr );

  } while ( getch() != 'Y' );

  return 0;
} 



(sorry for posting other codes :tongue:)

#146859 10/04/06 02:17 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
This should be simple to create. If someone hasn't already done it when I get off work, I will.

-genius_at_work

#146860 10/04/06 08:46 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias make.bin {
  var %bin = $+($rand(0,1),$rand(0,1)) 
  var %size = 30
  var %i = 3
  while (%i <= %size) {
    var %new = $rand(0,1)
    if ($invalid.binary($+(%bin,%new))) {
      var %failsize = $v1 
      var %new = $iif(%new,0,1)
      if ($invalid.binary($+(%bin,%new))) {
        if ($v1 > %failsize) { var %failsize = $v1 }
        dec %i %failsize
        var %bin = $left($+(%bin,%new),$calc(-1 * %failsize))
        var %new
      }
    }
    var %bin = $+(%bin,%new)
    inc %i
  }
  return %bin
}
alias -l invalid.binary {
  var %max = $int($calc($len($1) / 3))
  var %c = 1
  while (%c <= %max) {
    if (($right($1,%c) == $left($right($1,$calc(%c * 2)),%c)) && ($right($1,%c) == $left($right($1,$calc(%c * 3)),%c))) { return %c }
    inc %c
  }
}


usage //echo $make.bin

* code was tested to work
* but i dont garrentee it works as specified, i couldnt be shagged writting a checking script, but since the invalid.binary routine should check it at 30 chars anyway I would assume its valid results.

Someone might like to validate it if they can be shagged.

#146861 10/04/06 11:25 PM
Joined: Nov 2004
Posts: 842
Hoopy frood
Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
Quote:

Someone might like to validate it if they can be shagged.


Quote:

[00:23:03] 100110110010011001101011001101
[00:23:07] 100101001100101001001101100110
[00:23:11] 001001101001010011001101101011
[00:23:13] 110110101100110110011011010010
[00:23:15] 101101100101100101101100100110
[00:23:18] 011001101011001100101101100110
[00:23:19] 001011011001001010010110101101
[00:23:21] 001001101100100110010010100101
[00:23:41] 110110011011010110011010110011
[00:23:42] 001010010011010110010100100110
[00:23:42] 011001010011011010110011001011
[00:23:42] 011001100101001101011010010110
[00:23:43] 101101001100101001100100101100
[00:23:43] 001010010100110010100110010010
[00:23:44] 010100110110100100110110010110
[00:23:44] 110010100110110011011010110010
[00:23:45] 110110100110110010110110011011
[00:23:45] 001001100100110010110011001010
[00:23:46] 001100110110010011001001010010


Works flawlessly for me ...


What do you do at the end of the world? Are you busy? Will you save us?
#146862 11/04/06 01:18 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Looks like my work here is done.. :P

-genius_at_work

#146863 11/04/06 06:05 PM
Joined: Jan 2006
Posts: 15
B
BatSaly Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2006
Posts: 15
Hehe laugh Thank you very! It's very good work.

#146864 11/04/06 08:12 PM
Joined: Jan 2006
Posts: 15
B
BatSaly Offline OP
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2006
Posts: 15
and by the way... in my test sometimes there aren't 30 digits. frown
Code:
 alias makebin { 
  var %zzz = $make.bin
  if $len( %zzz ) == 30 { 
    echo 12 $len( %zzz ) -> %zzz
  } 
  else $makebin
} 

#146865 12/04/06 12:34 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Your test makes no sence for a start so is inconclusive as a result.
Your echoing in color 12 if it matches 30 characters.
If not your acttually running the generation of a new binary number and then attempting to execute it as a command.

Try this code.
Code:
alias makebin {
  if (!$0) { .timer.makebin -m 100000 1 makebin - }
  else {
    var %zzz = $make.bin
    echo -s $calc(100000 - $timer($ctimer).reps) : %zzz : $len(%zzz) 
    if ($len(%zzz) != 30) { .timer.makebin off }
  }
}


This should not lag or freeze up mirc and should attempt 100,000 generations, stopping if it locates one thats not 30 in length.

* PS: i ran this and it did the whole 100,000 with out error (well ok truth its still doing em but i cant be bothered waiting)


Link Copied to Clipboard