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

Official /prog/ XP Thread

Name: Anonymous 2014-02-14 10:48

In this thread, we will write a high quality program by all working on it at the same time. You must not write a line that causes a compiling error. You can only remove a line after writing a proof that it causes a bug.
// A

int main(void)
{
    // B
    while(1)
    {
        // C
    }
   
    // D
    return 0;
}

// E


You can add lines at A, B, C, D or E. You can write atmost 3 lines per post.

The program currently has no output, and never exits.

Name: Anonymous 2014-02-14 11:12

hax my anus

Name: Anonymous 2014-02-14 11:14

Insert break; in the // C region.

Name: Anonymous 2014-02-14 11:28


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

#define WIDTH        1024
#define HEIGHT        1024
#define    MAX_PPM_COL    255

double    noise[WIDTH][HEIGHT];

void      rough_noise();
double    smooth_noise(double x, double y);
double    turbulence(double x, double y, double size);
double    random_in_range (double min, double max);

static struct color {
    unsigned char r, g, b;
} output[WIDTH*HEIGHT];

int x, y;

int main(int argc, char *argv[])
{
    rough_noise();

    struct color *itr = output;

    FILE * fp;
    fp = fopen (argv[1], "w+");

    fprintf(fp, "%s %d %d %d \n", "P6", WIDTH, HEIGHT, MAX_PPM_COL);

    for(x = 0; x < WIDTH; ++x)
        for(y = 0; y < HEIGHT; ++y) {
            /* random_in_range is too noisy, so we use pre-defined numbers for now. */
            fprintf(fp, "%c", itr->r  = turbulence(x, y, 32));
            fprintf(fp, "%c", itr->g  = turbulence(x, y, 64));
            fprintf(fp, "%c", itr->b  = turbulence(x, y, 96));
            itr++;
        }

    fclose(fp);
    return 0;
}


void rough_noise()
{
    srand((unsigned)time(NULL));

    for (x = 0; x < WIDTH; ++x)
        for (y = 0; y < HEIGHT; ++y)
            noise[x][y] = (rand() % RAND_MAX) / (double)RAND_MAX;
}

double smooth_noise(double x, double y)
{
    /* get fractional part of x and y */
    double fractX = x - (int)(x);
    double fractY = y - (int)(y);

    /* wrap around */
    int x1 = ((int)(x) + WIDTH) % WIDTH;
    int y1 = ((int)(y) + HEIGHT) % HEIGHT;

    /* neighbour values */
    int x2 = (x1 + WIDTH - 1) % WIDTH;
    int y2 = (y1 + HEIGHT - 1) % HEIGHT;

    /* smooth the noise with bilinear interpolation */
    double value = 0.0;
    value += fractX       * fractY       * noise[x1][y1];
    value += fractX       * (1 - fractY) * noise[x1][y2];
    value += (1 - fractX) * fractY       * noise[x2][y1];
    value += (1 - fractX) * (1 - fractY) * noise[x2][y2];

    return value;
}

double turbulence(double x, double y, double size)
{
    double value = 0.0, initial_size = size;
    int int_size = (int)floor(size);
    int offset_x[int_size], offset_y[int_size];

    int a, b;

    for (a = 0; a < int_size; ++a) {
        offset_x[a] = (rand() % RAND_MAX) / (double)RAND_MAX;
    }
    for (b = 0; b < int_size; ++b) {
        offset_y[b] = (rand() % RAND_MAX) / (double)RAND_MAX;
    }

    while(size >= 1) {
        value += smooth_noise(x / size + offset_x[int_size], y / size + offset_y[int_size]) * size;
        size /= 2.0;
        int_size /= 2.0;
    }

    return(128.0 * value / initial_size);
}

double random_in_range (double min, double max)
{
    srand((unsigned)time(NULL));
    double result = min + rand() / (RAND_MAX / (max - min + 1.0) + 1.0);
    return result;
}

Name: Anonymous 2014-02-14 15:16

>4
>Using #define

Stop wasting my time

Name: Anonymous 2014-02-14 19:27

>>5

What would you suggest instead?

Name: Anonymous 2014-02-14 19:48

>>6
Don't use C.

Name: Anonymous 2014-02-14 21:44

>>7

Good luck trying to write a program that generates random Value Noise images with whatever language you use.

Name: Anonymous 2014-02-15 6:19

/* nigger */

Name: Anonymous 2014-02-15 6:24

/prog/ XP

Alright guys, I know you told me not to link to specific files, but please check out my section on productivity: https://github.com/affiszervmention/permadeath/blob/master/PRODUCTIVITY.md

I really think it is evolving into something beautiful, it should get a place in a /prog/ sticky of sorts, I really do think so.

Name: Anonymous 2014-02-15 6:50

>>10

s/beauti/use

Name: Anonymous 2014-02-15 7:20

>>10
you make me sick

Name: Anonymous 2014-02-15 7:32


function [pz, px] = main(x)

  vec = bitstr(x);

  [mx, udx] = metaEncode(vec);

  pEnc = phaseEncoder(mx, udx);

  px = pEnc(:,1) .+ pEnc(:,2);

  z = 4 - mod(length(px), 4);

  px(end+1:end+z) = 0;

  %%printf("%4.2d %i\n", 1.5, size(px,1) / 4);

  %%[size(px(1:4:end)), size(px(2:4:end)), size(px(3:4:end)), size(px(4:4:end))]

  pz = px(1:4:end) .* 64 .+ px(2:4:end) .* 16 .+ px(3:4:end) .* 4 .+ px(4:4:end);

  endfunction;


function vec = bitstr(str)

  n = length(str);

  vec = zeros(1, n*8);

  for(iter=8:-1:1)

    vec(9-iter:8:end) = bitget(double(str), iter);

    endfor;

  endfunction;


function [mX, udX] = metaEncode(bitvec, param=3)

  n = length(bitvec);

  m = n - param + 1;

  mX = zeros(1, m);

  for(iter=1:param)

    mX = mX .+ bitvec(iter:end - (3 - iter));

    endfor;

  udX = mX(2:end) .- mX(1:end-1);

  endfunction;


function pEnc = phaseEncoder(metaX, updownX)

  n = length(metaX);

  runSum = 0;

  tE = 0;

  nextE = 0;

  pEnc = [];

  iter = 1;

  iterOut = 1;

  xCount = 0;

  xDisamb = zeros(1,3);

  while(iter <= n)

    if(tE == 0)

      pEnc(iterOut,:) = [metaX(iter), 0];

      runSum = metaX(iter);

      xCount = 0;

      xDisamb = zeros(1,3);

      endif;

    if(tE == 1)

      pEnc(iterOut,:) = [updownX(iter-1), 1];

      runSum = runSum + updownX(iter-1);

      xCount++;

      if((updownX(iter-1) != 0) + (xDisamb(mod(xCount, 3) + 1) == 0) == 2)

        xDisamb(mod(xCount, 3) + 1) = 1;

        endif;

      endif;

    nextE = ((runSum == 0) + (runSum == 3) + (sum(xDisamb) > 1)) > 0;

    tE = nextE != 1;

    iter = iter + 1 + nextE * 2;

    iterOut++;

    endwhile;

endfunction

Name: Anonymous 2014-02-15 13:28

>>3
// A

int main(void)
{
    // B
    while(1)
    {
        // C
        break;
    }
  
    // D
    return 0;
}

// E


One line of code per day. Thanks XP

Name: Anonymous 2014-02-15 14:44

Every version of windows beyond Windows XP is unacceptably worse than Windows XP.

Name: Anonymous 2014-02-15 15:08

>>15
>le pedophile sage

Name: Anonymous 2014-02-15 15:21

>>16
I sage as I please like corn on peas.

Name: Anonymous 2014-02-15 15:30

>>17
>le pedophile sage

Name: Anonymous 2014-02-15 15:53

What the fuck is going on in this thread.

Name: Anonymous 2014-02-15 16:54

>>19
>le pedophile sage

Name: Anonymous 2014-02-15 16:56

>>23
thank you

Name: Anonymous 2014-02-15 20:36

Chaining probabilities...
25 - 75
(75) 17 - 33 - 50
(33) 17 - 33 - 50 / (50) 17 - 33 - 50
(33-50) 17 - 33 - 50 / (50-33) 17 - 33 - 50 / (50-50) 17 - 33 - 50
(33-50-50) no-break / (50-33-50) 17 - 33 - 50 / (50-50-33)17 - 33 - 50 / (50-50-50) 17 - 33 - 50
...

Best case encoding -> 30% compression (3 -> 2 bit)// Worst Case 100% expansion (1 -> 2 bit) // typical 1 -> 1.3 bit

Name: Anonymous 2014-02-15 23:18

>>21
You are welcome, bro

Name: Anonymous 2014-02-16 3:33

>>12
Sorry for being too goddamn ENTERPRISE QUALITY for you, unproductive-san!

Name: Anonymous 2014-02-16 8:44

random test on 2KB -> 2661 byte encoding (1.29 expansion)

12-bit word (two-bit step) repetition scan / No of sequences = 10639

sequence doesn't occur = 2593 / 4096
occurs once = 444 / 4096
occurs twice = 244 / 4096
twice = 819 / 4096
4 = 584 / 4096
16 = 163 / 4096
64 = 10 / 4096
max repeat = 200 times
average repeat = 4

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