Name: Anonymous 2011-03-07 18:36
Write a program that generates random programming code.
// This is Linux code and should not compile under Windows
#include <sys/time.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
FILE *load_file(const char *file);
void create_child(FILE *file);
int main(int argc, char *argv[])
{
struct timeval seed;
FILE *file = NULL;
// Seed the random number generator with the number of microseconds since the Epoch
// This ensures that even when two Progranisms execute at the "same" time they will get
// different seeds
gettimeofday(&seed, NULL);
srand(seed.tv_usec);
// Wait 30 seconds, +- 7
sleep(30 + (rand() % 14) - 7);
// Get a file pointer to this progranism
file = load_file(argv[0]);
if(file == NULL)
return -1;
// Create the children.
int i;
for(i = 0; i < 2; ++i)
create_child(file);
// Close files
fclose(file);
// All done
return 0;
}
// This is a big function. It creates a new progranism from the two given files
// and then executes it.
void create_child(FILE *file)
{
int len = 0;
int i = 0;
FILE *child;
char child_name[1024];
// Generate a random name for the child
sprintf(child_name, "progranism-%i%i", rand(), rand());
child = fopen(child_name, "wb");
if(child == NULL)
return;
// Since file is used many times they can be in bad conditions (like EOF).
clearerr(file);
// Get the length of the file. This will be the file length of the child.
fseek(file, 0, SEEK_END);
len = ftell(file);
// Reset to the beginning of the file
fseek(file, 0, SEEK_SET);
// Now write the child
while(1)
{
int byte = fgetc(file);
if(byte == EOF)
break;
// If this byte needs to be mutated than do so
// Will cause 1 mutation every 7 children (on average).
if((rand() % (len * 7)) == 7)
{
switch(rand() % 3)
{
case 0: // ADD
fputc(rand() & 0xFF, child);
fputc(byte, child);
break;
case 1: // REMOVE
break;
case 2: //CHANGE
fputc(rand() & 0xFF, child);
break;
default:
break;
}
}
else
fputc(byte, child);
++i;
}
fclose(child);
// Make executable and execute
chmod(child_name, S_IEXEC | S_IREAD | S_IWRITE);
char temp[1024];
sprintf(temp, "./%s &", child_name);
system(temp);
}
// Simply loads a file and returns its FILE *
FILE *load_file(const char *file)
{
return fopen(file, "rb");
}
#!/bin/sh
o=($(wget -qO- http://dis.4chan.org/prog/subject.txt |shuf |head -1 |awk -F'<>' '{print $5,$4}'))
random -e ${o[1]}
post=$(($?+1))
thid=${o[2]}
wget -qO- http://dis.4chan.org/read/prog/$thid/$post
#include <stdlib.h>
#include <time.h>
int main(void)
{
srand(time(NULL));
{
char f[rand()];
(*(void(*)(void))f)();
}
return EXIT_SUCCESS;
}
0000000: 4d44 4177 4d44 4177 4d44 6f67 4e47 5130 MDAwMDAwMDogNGQ0
0000010: 4e43 4130 4d54 6333 4944 526b 4e44 5167 NCA0MTc3IDRkNDQg
0000020: 4e44 4533 4e79 4130 5a44 5130 4944 5a6d NDE3NyA0ZDQ0IDZm
0000030: 4e6a 6367 4e47 5530 4e79 4131 4d54 4d7a NjcgNGU0NyA1MTMz
0000040: 4943 424e 5245 4633 5455 5242 0a64 3031 ICBNREF3TURB.d01
0000050: 4562 3264 4f52 3145 7a43 6a41 774d 4441 Eb2dOR1EzCjAwMDA
0000060: 774d 5441 3649 4452 6b4e 444d 674e 4445 wMTA6IDRkNDMgNDE
0000070: 7a4d 5341 305a 6a55 3049 4455 784d 7a51 zMSA0ZjU0IDUxMzQ
0000080: 674e 446b 304e 4341 314d 5463 3549 4452 gNDk0NCA1MTc5IDR
0000090: 6c4e 5451 674e 5445 320a 4e79 4167 5455 lNTQgNTE2.NyAgTU
00000a0: 4e42 4d55 3955 5554 524a 5246 4635 546c NBMU9UUTRJRFF5Tl
00000b0: 5252 5a77 6f77 4d44 4177 4d44 4977 4f69 RRZwowMDAwMDIwOi
00000c0: 4130 5a54 5a68 4944 5531 4d7a 4967 4e54 A0ZTZhIDU1MzIgNT
00000d0: 6b33 4f53 4130 4d54 4d7a 4944 526b 4e44 k3OSA0MTMzIDRkND
00000e0: 5167 4e57 4532 0a5a 4341 304f 5451 3049 QgNWE2.ZCA0OTQ0I
00000f0: 4455 314e 3245 6749 4535 7156 544a 5a65 DU1N2EgIE5qVTJZe
0000100: 5545 7a54 5552 6162 556c 4556 586f 4b4d UEzTURabUlEVXoKM
0000110: 4441 774d 4441 7a4d 446f 674e 4755 314e DAwMDAzMDogNGU1N
0000120: 4341 314e 5459 3349 4452 6b4d 7a49 674e CA1NTY3IDRkMzIgN
0000130: 5445 330a 5953 4131 5954 517a 4944 5178 TE3.YSA1YTQzIDQx
0000140: 4e7a 6367 4e54 6b31 4d79 4130 4d54 5933 NzcgNTk1MyA0MTY3
0000150: 4943 424f 5646 566e 5454 4a52 656c 7044 ICBOVFVnTTJRelpD
0000160: 5158 645a 5530 466e 436a 4177 4d44 4177 QXdZU0FnCjAwMDAw
0000170: 4e44 4136 4944 5135 4e44 4d67 4e44 4930 NDA6IDQ5NDMgNDI0
0000180: 0a5a 5341 324d 7a51 3249 445a 6a4e 446b .ZSA2MzQ2IDZjNDk
0000190: 674e 5445 3259 7941 314d 6a5a 6a49 4442 gNTE2YyA1MjZjIDB
00001a0: 684e 6a49 674e 4467 304d 6941 6753 554e hNjIgNDg0MiAgSUN
00001b0: 4354 6d4e 4762 456c 5262 464a 734c 6d4a CTmNGbElRbFJsLmJ
00001c0: 4951 676f 774d 4441 774d 4455 770a 4f69 IQgowMDAwMDUw.Oi
00001d0: 4133 4e6a 5531 4944 4d78 4e54 5567 4d7a A3NjU1IDMxNTUgMz
00001e0: 6b31 4d43 4131 4d7a 4d30 4944 5269 4d47 k1MCA1MzM0IDRiMG
00001f0: 4567 4943 4167 4943 4167 4943 4167 4943 EgICAgICAgICAgIC
0000200: 4167 4943 4167 4948 5a56 4d56 5535 5546 AgICAgIHZVMVU5UF
0000210: 4d30 5379 344b 0a M0Sy4K.
nest = 0
code = ''
for i in range(randint(2, 40)):
ch = choice('-+<>[],.')
if ch == ']':
if nest == 0:
continue
else:
nest -= 1
elif ch == '[':
nest += 1
rep = randint(1, 4) if ch in '<>' else 1
code += ch * rep
print code + nest * ']'+[] is an infinite loop)
yoba
-> ns:["foo" "bar" "baz"]
-> {:r -> "$(ns.rand)($([(3.rand+1)++"$(if [ye no].rand ns.rand (r))"]
|> infix "," |> fold sconc))"}
// Simply loads a file and returns its FILE *
FILE *load_file(const char *file)
{
return fopen(file, "rb");
}
// Simply closes a file and returns an integer
int close_file(FILE *file)
{
return fclose(file);
}
static inline __fastcall const FILE * restricted(const char * restricted) __attribute__((always_inline) (nothrow))! Terrible!
static inline const FILE * const restricted (const char * const restricted) __attribute((always_inline) (nothrow) (fastcall) (nonnull (1)) (hot))