mIRC Homepage

# generate script

Posted By: BatSaly

## generate script - 09/04/06 06:31 PM

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
Posted By: schaefer31

## Re: generate script - 10/04/06 12:15 AM

Now just explain that in english.
Posted By: genius_at_work

## Re: generate script - 10/04/06 02:03 AM

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
Posted By: BatSaly

## Re: generate script - 10/04/06 11:53 AM

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
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 &gt;= 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 &lt; 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 &lt; 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 &lt; 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 &gt; 29) or (br &gt; 1000 );
if br &gt; 1000 then write (' Can not generate str')
else begin
for j := 1 to 30 do write (B[j]);
end;
end. ```
Posted By: BatSaly

## Re: generate script - 10/04/06 12:02 PM

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 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.
Posted By: BatSaly

## Re: generate script - 10/04/06 12:51 PM

or some like this in C:
Code:
``` #include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

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 &lt; 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 &lt;= 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 &lt; 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:)
Posted By: genius_at_work

## Re: generate script - 10/04/06 02:17 PM

This should be simple to create. If someone hasn't already done it when I get off work, I will.

-genius_at_work
Posted By: DaveC

## Re: generate script - 10/04/06 08:46 PM

Code:
```alias make.bin {
var %bin = \$+(\$rand(0,1),\$rand(0,1))
var %size = 30
var %i = 3
while (%i &lt;= %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 &gt; %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 &lt;= %max) {
if ((\$right(\$1,%c) == \$left(\$right(\$1,\$calc(%c * 2)),%c)) &amp;&amp; (\$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.
Posted By: Jigsy

## Re: generate script - 10/04/06 11:25 PM

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 ...
Posted By: genius_at_work

## Re: generate script - 11/04/06 01:18 AM

Looks like my work here is done.. :P

-genius_at_work
Posted By: BatSaly

## Re: generate script - 11/04/06 06:05 PM

Hehe Thank you very! It's very good work.
Posted By: BatSaly

## Re: generate script - 11/04/06 08:12 PM

and by the way... in my test sometimes there aren't 30 digits.
Code:
``` alias makebin {
var %zzz = \$make.bin
if \$len( %zzz ) == 30 {
echo 12 \$len( %zzz ) -&gt; %zzz
}
else \$makebin
} ```
Posted By: DaveC

## Re: generate script - 12/04/06 12:34 AM

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)
© 2022 mIRC Discussion Forums