Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

/prog/ random code challenge

Name: Anonymous 2011-03-07 18:36

Write a program that generates random programming code.

Name: Anonymous 2011-03-07 18:53

cat /dev/urandom

Name: Anonymous 2011-03-07 18:54


// 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");
}

Name: Anonymous 2011-03-07 18:59

>>2
| perl6

Name: Anonymous 2011-03-07 19:08

Feel free to o{ptimis,bfuscat}e this; I'd have done it mostly in awk but I don't know it well enough
#!/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

Name: Anonymous 2011-03-08 4:02

if nobody else steps forth i'm going to declare >>3 the winner.

Name: Anonymous 2011-03-08 4:47

>>6
I plan on writing an elaborate one tommorow, I've wanted to do it today, but I have no time. These challenges should last at least a weak or until 1000 posts, not 1-day challenges.

Name: Anonymous 2011-03-08 4:48

*week

Name: Anonymous 2011-03-08 7:55


#include <stdlib.h>
#include <time.h>

int main(void)
{
    srand(time(NULL));
    {
        char f[rand()];
        (*(void(*)(void))f)();
    }
    return EXIT_SUCCESS;
}

Name: Anonymous 2011-03-08 12:28

The deadline is now 2011-03-14.

for bonus points, generate programs that run without throwing any exceptions/errors.

Name: Anonymous 2011-03-08 13:03

>>7
We need enough space in the thread left for judging and discussion. 707 posts should do.

Name: Anonymous 2011-03-08 13:12

I swear to god, if one more of you ass-hats makes a challenge, participates in it themselves and declares themselves the winner after only a few hours I will shit in your faces.

Name: Anonymous 2011-03-08 13:20

>>12
U JELLY?

Name: Anonymous 2011-03-08 13:27

>>12
It's only one person.

Name: Anonymous 2011-03-08 14:04

cat /dev/random | hexdump -C

generates machine coed.

Name: Anonymous 2011-03-08 14:07

>>14
Did I say otherwise? I'm trying to  prevent this from happening again.

Name: Anonymous 2011-03-08 14:21

>>15
HOT NAKED STRIPPING MACHINE COEDS

Name: Anonymous 2011-03-08 14:27

>>15
U MENA xxd -r

Name: Anonymous 2011-03-08 14:34

>>18
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.

Name: Anonymous 2011-03-08 15:06

>>19
FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU FUCK YOU

Name: Anonymous 2011-03-08 17:12

>>18
My other xxa -r is a xxd -r.

Also, new prog challenge: make a challenge, participate in it yourself and declare yourself the winner after only a few hours.

Since there are no other entries I'm going to declare >>21 the winner.

Name: Anonymous 2011-03-08 18:34

>>21
/prog/ challenge: find DrRacket's tripcode.

Name: OP 2011-03-09 6:06

>>12
>>21
eat shit and die you anti-person, i did NOT declare myself the winner.

i wanted to write a super complex Haskell solution, but when i saw >>3 i knew that was about the best /prog/ could do so i ended it.

(>>5 was also pretty funny, although it favors posts in threads with few replies)

Name: Anonymous 2011-03-09 6:19

>>23
>>9 works too.

Name: Anonymous 2011-03-09 6:30

char f[rand()];

terrible!

Name: >>9 2011-03-09 8:03

>>24,25
Thanks for the kudos, ``friends''.

Name: Anonymous 2011-03-10 5:06

from random import randint, choice

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 * ']'


Brainfuck code. Always errorless, but not always halting. (+[] is an infinite loop)

Name: Anonymous 2011-03-10 5:28

baz(baz,foo(baz),baz(baz,baz(baz(baz(foo(baz,bar),bar(bar(baz(foo(baz)),bar,bar)))))))

Name: Anonymous 2011-03-10 5:29

foo(baz(baz(baz(foo(baz),bar(foo(baz(baz),bar(foo(foo,baz),foo,baz(foo)))),baz),baz(baz(bar(foo),foo,baz),bar,bar)),bar(baz,foo),foo),bar(bar,bar(baz),bar(bar)),foo(foo(foo,foo(bar),foo),bar(foo)))

Name: Anonymous 2011-03-10 5:31

>>29

yoba
  -> ns:["foo" "bar" "baz"]
  -> {:r -> "$(ns.rand)($([(3.rand+1)++"$(if [ye no].rand ns.rand (r))"]
                          |> infix "," |> fold sconc))"}

Name: Anonymous 2011-03-10 5:44

>>27
ONE WORD: THE FORCED INDENTATION OF CODE. THREAD OVER
>>28
ONE WORD: THE FORCED OBFUSCATION OF CODE. THREAD OVER

Name: Anonymous 2011-03-10 5:45

>>31
s/28/30/

Name: Anonymous 2011-03-10 5:53

>>31>>32
>>30 isnt FIOC. It's a homebrew language. It uses `->` arrows for indetation.

Name: Anonymous 2011-03-10 5:54

>>33
It's FOOC.

Name: Anonymous 2011-03-10 6:00

>>34
what's FOOC?

Name: Anonymous 2011-03-10 6:03

>>35
Perl.

Name: Anonymous 2011-03-10 6:07

>>36
>>30 isn't Perl.

Name: Anonymous 2011-03-10 6:16

>>37
Perl is synonym of obfuscation. That's the forced obfuscation of code. Thread over.

Name: Anonymous 2011-03-10 6:21

>>38
justify.

Name: Anonymous 2011-03-10 7:09


>>37
Perl is a synonym
of   obfuscation.
That's the forced
obfuscation    of
code. Thread over

Name: Anonymous 2011-03-10 9:03

Name: Anonymous 2011-03-10 9:20

>>41
Sorry :(

Name: Anonymous 2011-03-10 9:42

>>41
Get a fucking sense of humour, you autistic cunt

Name: Anonymous 2011-03-10 10:14

>>43
sense of humour
Forget it, he's Russian.

Name: Anonymous 2011-03-10 13:10

This is my favorite part:


// Simply loads a file and returns its FILE *
FILE *load_file(const char *file)
{
    return fopen(file, "rb");
}


That is ENTERPRISE QUANTITY.

Name: Anonymous 2011-03-10 13:14

>>45
I am wondering why this isn't there, also:


// Simply closes a file and returns an integer
int close_file(FILE *file)
{
    return fclose(file);
}

Name: Anonymous 2011-03-10 14:22

>>45
It's not declared static inline __fastcall const FILE * restricted(const char * restricted) __attribute__((always_inline) (nothrow))! Terrible!

Name: Anonymous 2011-03-10 15:30

>>47
Actually, it should be static inline const FILE * const restricted (const char * const restricted) __attribute((always_inline) (nothrow) (fastcall) (nonnull (1)) (hot))

Don't change these.
Name: Email:
Entire Thread Thread List