Code off
1
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!
81
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;
}
82
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();
}
}
83
Name:
Anonymous
2009-07-29 4:48
>>82
ohshit i forgot my
"tags"
84
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.
85
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.
86
Name:
Anonymous
2009-07-29 9:14
>>84
Death to Allman! Long live K&R!
87
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.
88
Name:
Anonymous
2009-07-29 9:46
cat >>87 | sed -e 's/opening/closing/'
89
Name:
Anonymous
2009-07-29 11:40
90
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)
91
Name:
Anonymous
2009-07-29 14:11
>>90
What's the matter? The system(3) version too short for you?
92
Name:
Anonymous
2009-07-29 14:29
>>91
It's too cross-platform for me.
93
Name:
Anonymous
2009-07-29 14:49
10 MINUETS TO GO!
94
Name:
Anonymous
2009-07-29 14:55
>>93
Nothing like using a dance as a measurement of time.
95
Name:
Anonymous
2009-07-29 15:02
>>92
Well, that's just like,
your opinion , man.
96
Name:
Anonymous
2009-07-29 15:06
>>1
Xarn
U MENA CAIRNARVON?
97
Name:
Anonymous
2009-07-29 15:19
I missed the jpeg one, but I want to see the next challenge.
98
Name:
Anonymous
2009-07-29 15:42
By this thread I conclude that 2% of /prog/ users can write real code.
99
Name:
Anonymous
2009-07-29 15:48
>>98
or 2% could be assed
100
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!
101
Name:
Anonymous
2009-07-29 16:07
>>100
WTF thats supposed to be easier?
102
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.
103
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.
104
Name:
Anonymous
2009-07-29 16:14
>>102
stop turning my
/prog/ into rentacoder
105
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
106
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.
107
Name:
Anonymous
2009-07-29 16:19
>>100
I can't wait for double-shot-of-ENTERPRIZE's glitchy applet solution.
108
Name:
Anonymous
2009-07-29 16:20
109
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?
110
Name:
Anonymous
2009-07-29 16:46
ITT: OP gets /prog/ to do his daily job for him.
111
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?
112
Name:
Anonymous
2009-07-29 17:37
>>100
Sage for TOO DIFFICULT FOR /prog/!
113
Name:
Anonymous
2009-07-29 17:38
>>112
Im sorry, just for you ill make Stage 3 'Hello world!'
114
Name:
Anonymous
2009-07-29 17:41
>>113
system.out.println("Hello World!");
115
Name:
Anonymous
2009-07-29 17:43
>>114
You fail. You fucking fail at 'Hello World!'.
System is capital, you dumbfuck
116
Name:
Anonymous
2009-07-29 17:52
This thread makes me feel bad for the rest of prog.
117
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!
118
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.
119
Name:
Anonymous
2009-07-29 18:25
>>100
I doubt anyone will complete this. In C anyway.
120
Name:
Anonymous
2009-07-29 18:29
>>118
Forget it, it's NP-Complete
Newer Posts