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

Code off

Name: Anonymous 2009-07-28 13:59

Welcome to the first annual /prog/ Code off !

The language will be C.

Compeptitors include (in no particular order):

Mr. Ribs
Xarn
FV
Anonymous
W. T. Snacks

Rumor has it, that there may be a special guest appearance from either The Sussman or
Leah Culver.

What's the point of this, you ask?

It's to determine who is an EXPERT PROGRAMMER.

Marking criteria:

Optimization
Elegance

Bonus marks:
indentation

Good luck!

Name: Anonymous 2009-07-29 4:44

#include <Carbon/Carbon.h>

CGImageRef LoadJPEGImageAtFileSystemPath(const char *path)
{
    CFURLRef url;
    CGDataProviderRef dataProvider;
    CGImageRef image = NULL;
    url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
        (const UInt8 *)path, strlen(path), false);
    if (dataProvider = CGDataProviderCreateWithURL(url))
    {
        image = CGImageCreateWithJPEGDataProvider(dataProvider, NULL,
            true, kCGRenderingIntentPerceptual);
        CGDataProviderRelease(dataProvider);
    }
    CFRelease(url);
    return image;
}
void InitializeDisplaySystem()
{
    ProcessSerialNumber psn = {0, kCurrentProcess};
    TransformProcessType(&psn, kProcessTransformToForegroundApplication);
    SetFrontProcess(&psn);
}
WindowRef CreateWindowForImage(CGImageRef image)
{
    Rect bounds;
    size_t width, height;
    WindowRef window;
    GetAvailableWindowPositioningBounds(NULL, &bounds);
    width = CGImageGetWidth(image);
    height = CGImageGetHeight(image);
    if (bounds.right - bounds.left > width)
    {
        bounds.left = (bounds.left + bounds.right - width) / 2;
        bounds.right = bounds.left + width;
    }
    if (bounds.bottom - bounds.top > height)
    {
        bounds.top = (bounds.top + bounds.bottom - height) / 2;
        bounds.bottom = bounds.top + height;
    }
    CreateNewWindow(kPlainWindowClass, kWindowNoAttributes, &bounds,
        &window);
    return window;
}
void RenderTwoImagesBlendedTogetherIntoWindow(WindowRef window,
    CGImageRef firstImage, CGImageRef secondImage)
{
    CGContextRef context;
    CGRect drawArea = CGRectMake(0, 0, CGImageGetWidth(firstImage),
        CGImageGetHeight(firstImage));
    QDBeginCGContext(GetWindowPort(window), &context);
    CGContextSaveGState(context);
    CGContextDrawImage(context, drawArea, firstImage);
    CGContextSetAlpha(context, 0.5);
    CGContextDrawImage(context, drawArea, secondImage);
    CGContextRestoreGState(context);
    QDEndCGContext(GetWindowPort(window), &context);
}
OSStatus HandleExitEvent(EventHandlerCallRef inHandlerCallRef,
    EventRef inEvent, void *inUserData)
{
    QuitApplicationEventLoop();
    return noErr;
}
void DoEventLoop(WindowRef window)
{
    EventTypeSpec exitEvents[2] = {
        {kEventClassKeyboard, kEventRawKeyDown},
        {kEventClassMouse, kEventMouseDown}
    };
    InstallWindowEventHandler(window, HandleExitEvent, 2, exitEvents,
        NULL, NULL);
    RunApplicationEventLoop();
}
int main(int argc, char *argv[])
{
    CGImageRef image1, image2;
    WindowRef window;
    if (argc != 3) errx(1, "U MENA ARGS?");
    image1 = LoadJPEGImageAtFileSystemPath(argv[1]);
    image2 = LoadJPEGImageAtFileSystemPath(argv[2]);
    if (!image1 || !image2) errx(2, "images no load");
    InitializeDisplaySystem();
    window = CreateWindowForImage(image1);
    ShowWindow(window);
    RenderTwoImagesBlendedTogetherIntoWindow(window, image1, image2);
    DoEventLoop(window);
    return 0;
}

Name: Anonymous 2009-07-29 4:47

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

// i love you /prog/  <3

void FFF() {
  for(;;){
    putchar('F');
    FFF();
}}

void main() {
  puts("did i win the contest ?");
  char answer = getchar();
  if(answer == 121) {
    puts("oh thank you /prog/ , it is a great honor for me , i want to thank my family , friends , producer , my dog, the sussman , anal tourning , ronald macdonald, the snake , guido and the ginger and last but not least all the other fucks i forgot .");
    exit(0);

  }
  else {
    FFF();
  }
}

Name: Anonymous 2009-07-29 4:48

>>82
ohshit i forgot my "tags"

Name: Anonymous 2009-07-29 8:54

>>43
K&R might have the concepts needed for successful C, but the style is pig disgusting. It doesn't surprise me that people that aren't interested in succeeding in C don't read it.

Name: Anonymous 2009-07-29 8:57

>>84
Do they impose their style on you? No, they don't; just pretend it's Allman or some variation thereof.

Name: Anonymous 2009-07-29 9:14

>>84
Death to Allman! Long live K&R!

Name: Anonymous 2009-07-29 9:21

>>86
If by some wicked logic an if or for and an opening curly bracket make a complete whole to you, good for you. I prefer my }s to be lined up with {s, thank you.

Name: Anonymous 2009-07-29 9:46

cat >>87 | sed -e 's/opening/closing/'

Name: Anonymous 2009-07-29 11:40

>>87
EXPERT HEATHEN

Name: Anonymous 2009-07-29 13:18

>>81
We have got a real entry! Finally! And look, its Anonymous. Well, I guess this competition is almost over. (1 and a half hours left)

Name: Anonymous 2009-07-29 14:11

>>90
What's the matter?  The system(3) version too short for you?

Name: Anonymous 2009-07-29 14:29

>>91
It's too cross-platform for me.

Name: Anonymous 2009-07-29 14:49

10 MINUETS TO GO!

Name: Anonymous 2009-07-29 14:55

>>93
Nothing like using a dance as a measurement of time.

Name: Anonymous 2009-07-29 15:02

>>92
Well, that's just like, your opinion, man.

Name: Anonymous 2009-07-29 15:06

>>1
Xarn
U MENA CAIRNARVON?

Name: Anonymous 2009-07-29 15:19

I missed the jpeg one, but I want to see the next challenge.

Name: Anonymous 2009-07-29 15:42

By this thread I conclude that 2% of /prog/ users can write real code.

Name: Anonymous 2009-07-29 15:48

>>98
or 2% could be assed

Name: Anonymous 2009-07-29 15:59

Official Winner of Stage 1
>>81
ANONYMOUS
+--------------------------------------+
Official Code Off: STAGE 2

2D Graphics

This is the second of three challenges. To complete this stage you must program a 2D graphical application that initializes a new 'Square' on the screen each time the user left-clicks. Each square will move at a constant speed in a random direction. Upon contacting a window border, the square will bounce off and continue in a new direction.

Each contestant has 24 hours to complete. Code must be posted in this thread by 4pm eastern tomorrow. This stage is slightly easier than the first, so I expect more than one legitimate entry!

Name: Anonymous 2009-07-29 16:07

>>100
WTF thats supposed to be easier?

Name: Anonymous 2009-07-29 16:12

You know what type of program I would like to see?  A recipe index where you can take different formats from various websites, conversion, grocery list, pictures, etc.

Name: Anonymous 2009-07-29 16:13

I wonder what would happen if Leah Culver and The Sussman both submitted entries. I wonder who's would win... The Sussman represents old fashioned, classical, elegant programming and Leah Culver represents fast paced, cutting edge, enterprise programming. It would be a monumental event.

Name: Anonymous 2009-07-29 16:14

>>102
stop turning my /prog/ into rentacoder

Name: Anonymous 2009-07-29 16:15

>>103
I'd like to see the Sussman submit his entry to Leah Culver, if you know what I mean

Name: Anonymous 2009-07-29 16:15

>>103
I'd go with Culver if it was in C. Especially if it wasn't a math based problem.

Name: Anonymous 2009-07-29 16:19

>>100
I can't wait for double-shot-of-ENTERPRIZE's glitchy applet solution.

Name: Anonymous 2009-07-29 16:20

Name: Anonymous 2009-07-29 16:37

>>107
If hes posting applets then why doesnt he just host them online so we can SEE them work?

Name: Anonymous 2009-07-29 16:46

ITT: OP gets /prog/ to do his daily job for him.

Name: Sage 2009-07-29 16:53

>>110
Who's daily job is an image combiner one day and a 2d square bouncer the next?

Name: Anonymous 2009-07-29 17:37

>>100
Sage for TOO DIFFICULT FOR /prog/!

Name: Anonymous 2009-07-29 17:38

>>112
Im sorry, just for you ill make Stage 3 'Hello world!'

Name: Anonymous 2009-07-29 17:41

>>113
system.out.println("Hello World!");

Name: Anonymous 2009-07-29 17:43

>>114
You fail. You fucking fail at 'Hello World!'. System is capital, you dumbfuck

Name: Anonymous 2009-07-29 17:52

This thread makes me feel bad for the rest of prog.

Name: Anonymous 2009-07-29 17:53

>>111
Wait, you mean that's not what an IT professional does? Then school has taught me nothing!

Name: Anonymous 2009-07-29 18:13

Official Code Off: STAGE 3

Hello World

You must code a the classic hello world program that will output the exact text ``Hello, World!'' to standard output.

Name: Anonymous 2009-07-29 18:25

>>100
I doubt anyone will complete this. In C anyway.

Name: Anonymous 2009-07-29 18:29

>>118
Forget it, it's NP-Complete

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