mind_lamp


Исключительно моё

без единого исключения


Revelation
mind_lamp
My mind is wider than the universe: in fact, the universe can materialize less than a quarter of what my mind can create.

басня из двух строк
mind_lamp
Мораль сей басни такова:
Зайчиха обманула льва

Software "mind lamp", the very first version
mind_lamp
You will have to press Ctrl+C to stop this program. I compile it with GCC.

Theory behind mind lamps: http://www.mind-lamp.com/mind-lamp-research.php


#include <stdio.h>

void main(int argc, char *argv[])
{
    unsigned int a,b,d, c0=0, c1=0, save_rn[600],	// SAVE RANDOM NUMBERS
		srn_pos=0, mx=0, mn=0xffffffff, last=2, run, maxrun=0, maxrbit;
    char *p=malloc(65536*1024), *at;
    time_t t;
    __asm__ volatile("rdtsc" : "=a" (a), "=d" (d));

  while(1) {

    for (b=2048*1024; b!=0; --b)	  // RUN AROUND the memory pool, simply
	d=b*654321893, d=d<<23|d>>9, d*=0xfffefdfb,	// to SPEND TIME...
	*(p+(d&0x3ffffff))= d>>24;	    // MUST! spend a BIG amount of time
    b=a;			  // OTHERWISE the Bell Curve isn't good enough
    __asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
    b=a-b;				// GREAT! We've got a RANDOM NUMBER
    if (b&1) ++c1; else ++c0;	       //ONLY THE LEAST SIGNIFICANT BIT IS USED
    save_rn[srn_pos++]=b;		// BUT ALL 32 BITS are saved

    if (b<mn) mn=b;		    // to CHECK THE RANGE of our random numbers
    if (b>mx) mx=b;
    if ((b&1)==last)  { if (++run>maxrun) maxrun=run, maxrbit=last; }
	else run=0, last=b&1;

    printf("\r%8x %8x  %8d %8d",mn,mx,c0,c1);		//REGULAR SCREEN UPDATE

    if (c0==300 || c1==300) {	   // either FIRST or RIGHT runner HAS FINISHED
	if (c0>c1)
        printf("\r%8x %8x    ***%3d***%6d   ",mn,mx,c0,c1);
	else
	printf("\r%8x %8x    %6d   ***%3d***",mn,mx,c0,c1);
#if 1
			      // NOW let's find the minimal difference between
			      // the 599 (or less) random numbers we've saved
			      //(it must be big, and neighbors must be big too)
	do {                  
		for (d=0, b=1; b<srn_pos; b++) {	//Bubble-sort the array
		  c0=save_rn[b-1];
		  c1=save_rn[b  ];
		  if (c0>c1) save_rn[b-1]=c1,
			     save_rn[b  ]=c0, d=1;
		}
	} while (d);
			if ((save_rn[0  ]!=mn) ||
			    (save_rn[b-1]!=mx))
			printf(" Something bad has happened!\n"), exit(0);

	c0=c1=0, mn=mx;
	for (b=1; b<srn_pos; b++) {		 // Find the minimal difference
		d=save_rn[b]-save_rn[b-1];
		if (d<mn) { mn=d;
			if (b>1)	 c0=save_rn[b-1]-save_rn[b-2];
			if (b+1<srn_pos) c1=save_rn[b+1]-save_rn[b];
		}
	}

	t=time(NULL);				// PRINT maximal run and bit,
	at=ctime(&t);			 // minimal difference and 2 neighbors,
	at[19]=0;				// and finally date & time:
	printf("%6d %d %3dk,%4d,%3dk  %s\n",
				maxrun,maxrbit, c0>>10,mn,c1>>10, &at[4]);
#endif
	c0=c1=0, maxrun=srn_pos=mx=0, mn=0xffffffff, last=2;
    }
  }
}




Example output:

C:\GCC\bin>mlv1.exe
18b48aca 727dcfd9    ***300***   290        8 0  79k, 918,181k  Dec 02 12:14:46
17e44712 60c931b5    ***300***   292       10 0 183k, 102, 44k  Dec 02 12:18:00
180377d3 69925a54    ***300***   297        7 1 132k, 357,183k  Dec 02 12:21:16
17ebbca6 e28d5b45       274   ***300***     8 0  89k,  34, 12k  Dec 02 12:24:14
18c369fe 73f11288       299   ***300***     9 1 104k, 704,110k  Dec 02 12:28:00
17e32304 653bdd3d    ***300***   266       12 0 381k, 425,377k  Dec 02 12:31:07
1a04f057 fcfbc420    ***300***   294        9 0 276k, 656,274k  Dec 02 12:34:23
18a0c7b2 9667fd59    ***300***   271        9 1  51k, 629, 53k  Dec 02 12:37:16
 fd3547c cae2ca54    ***300***   268       11 1   3k, 109, 67k  Dec 02 12:40:15
1a8630a6 990576f1       277   ***300***     6 0   6k, 153, 94k  Dec 02 12:43:20
18f99ca6 72ff456a       264   ***300***     7 1 152k, 255, 25k  Dec 02 12:46:11
1aaf37a9 61fa3d33       243   ***300***     6 1 671k,  68,545k  Dec 02 12:49:01
19998451 7360f1b8    ***300***   284        8 0  18k, 119, 47k  Dec 02 12:51:59
193db6e1 6bcad604    ***300***   296        7 0  32k,  58, 67k  Dec 02 12:54:58
1a6e9c52 cce0bdfa       275   ***300***     8 1   6k,  51, 21k  Dec 02 12:57:56
1a681a74 cb07023c    ***300***   272        7 0  83k,  85,185k  Dec 02 13:00:54
18289ffd 6b8ec144    ***300***   291        8 0 240k, 187,123k  Dec 02 13:03:58
181bf9b0 97b25b83       280   ***300***    10 0  13k, 187,284k  Dec 02 13:07:24
1a12ee3a 86f19998    ***300***   265        9 1 277k, 459, 59k  Dec 02 13:10:18
1a5cdb9c 49085a32    ***300***   281        8 0  21k, 340, 98k  Dec 02 13:13:12
195e7568 650d5abb       295   ***300***     7 1  29k, 102, 58k  Dec 02 13:16:05
18992903 6010f81f    ***300***   274       10 0 1178k, 282,372k  Dec 02 13:19:07

1abb9253 46f57aaf       268   ***300***    10 1  56k, 153,  7k  Dec 02 13:22:01
1a815520 38e9eb8b    ***300***   289       12 0 348k, 578,285k  Dec 02 13:24:53
19ed992c 34d480fe    ***300***   299        7 0  91k, 187, 17k  Dec 02 13:27:43
18412a7c 344d5b12    ***300***   288        7 1 110k, 459,236k  Dec 02 13:30:23
1a5e7dc5 32708560       257   ***300***     7 1   2k, 136,270k  Dec 02 13:33:03
1803a055 62408a1e    ***300***   273       12 0  12k,2363,231k  Dec 02 13:36:08
17fb4354 58bebb2d    ***300***   261        9 0  58k, 374, 41k  Dec 02 13:39:07
1a9cb9e4 54b1ba0c       261   ***300***     7 0 198k, 187, 16k  Dec 02 13:42:06
18c63541 3a5043dc       277   ***300***    10 0  23k, 384,174k  Dec 02 13:44:55
1a961936 346880d1    ***300***   283        7 0  25k, 765, 56k  Dec 02 13:47:46
18128121 b1cba8fa       259   ***300***    12 1  12k, 129, 10k  Dec 02 13:50:37
1a6b4fd5 92593edf    ***300***   296        7 0 293k,1156,289k  Dec 02 13:54:48
2242e3c8 72beb161        74       76^C

My intention was to see the first (left) runner winning.

?

Log in

No account? Create an account