Unobfuscated code contest #1

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

Unobfuscated code contest #1

Postby Beer Hunter » Mon Oct 25, 2004 6:20 am

The task is to draw a filled polygon to the console using ASCII art. You are given the following:
Code: Select all
struct Point { int x, y; };
struct Polygon { std::vector<Point> points; };
void draw_polygon(const Polygon& polygon);
You need to implement draw_polygon.
  • The coordinates (0, 5) refer to a point exactly halfway across the first column and exactly halfway down the sixth row in the console. The coordinates will not extend beyond column #70 or row #20.
  • You must draw the edges using symbols such as /, \, -, |, * and so on. The rules are loose here, but the outline should look roughly 'right'.
  • You must fill the polygon with a symbol distinct from the ones you used to draw the edges.
  • The polygon might not be convex. In fact, it might even overlap itself. You must fill the 'odd-numbered' regions and not the 'even-numbered' regions. See this image for an idea of what to do.
  • Optimise for code clarity. This will be judged subjectively by the forum-goers.
  • The deadline is November 6.
Update:
  • There has been some confusion about my coordinate system. Please refer to this image for a visual explanation.
  • The contest has been split into three divisions.
    • An entry in the easy division only needs to deal with convex polygons.
    • An entry in the intermediate division also needs to deal with concave polygons.
    • An entry in the hard division also needs to deal with self-overlapping polygons.
    The deadline remains the same.
Update:
Deadline extended to 10 November.
Last edited by Beer Hunter on Thu Nov 04, 2004 10:07 pm, edited 2 times in total.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby Bugdude » Mon Oct 25, 2004 6:34 am

The polygon might not be convex. In fact, it might even overlap itself.


Awww, that's not nice. ;)
User avatar
Bugdude
Moderator
 
Posts: 2480
Joined: Sun Aug 29, 2004 1:58 am
Location: Living in sin

Postby leas5040 » Mon Oct 25, 2004 9:25 am

The coordinates (0, 5) refer to a point exactly halfway across the first column and exactly halfway down the sixth row in the console. The coordinates will not extend beyond column #70 or row #20.


Isn't that backwards? Shouldn't it be across the first row and down the sixth column?
"Given enough time, man can do anything with a bit of string and some Tinker toys." Bruce Bolden, Senior Instructor at the University of Idaho.
User avatar
leas5040
 
Posts: 1214
Joined: Mon Apr 12, 2004 9:51 pm
Location: Moscow, ID

Postby Invictus » Mon Oct 25, 2004 10:16 am

Bugdude wrote:
The polygon might not be convex. In fact, it might even overlap itself.


Awww, that's not nice. ;)


Convex is like a polygon that no edges overlap right? I foget my geometry.
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Bugdude » Mon Oct 25, 2004 10:30 am

Cold Flame wrote:
Bugdude wrote:
The polygon might not be convex. In fact, it might even overlap itself.


Awww, that's not nice. ;)


Convex is like a polygon that no edges overlap right? I foget my geometry.


It is a polygon such that if you draw a line between any two non-neighboring vertices it passes through the interior of the polygon.

This polygon isn't convex.
Image

Edit: Damn it's late, my brain isn't working correctly :(
Last edited by Bugdude on Mon Oct 25, 2004 10:41 am, edited 2 times in total.
User avatar
Bugdude
Moderator
 
Posts: 2480
Joined: Sun Aug 29, 2004 1:58 am
Location: Living in sin

Postby Invictus » Mon Oct 25, 2004 10:32 am

Do we have to use a vector? I think an array of "Point"s would be much better.

Code: Select all
struct Vertex {int x, y;};
struct Polygon {Vertex *vertecies;};
void draw_polygon(Polygon *polygon, unsigned int numverts);

User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Invictus » Mon Oct 25, 2004 10:38 am

Bugdude wrote:
Cold Flame wrote:
Bugdude wrote:
The polygon might not be convex. In fact, it might even overlap itself.


Awww, that's not nice. ;)


Convex is like a polygon that no edges overlap right? I foget my geometry.


It is a polygon such that if you draw a line between any two non-neighboring vertices it passes through the interior of the polygon.

This polygon isn't concave.
Image


Ok... a hexagon that is even on all sides is convex right?
EDIT: I mean like a nut or a bolt. (Just because they're even they could still be concave.) right?
Last edited by Invictus on Mon Oct 25, 2004 11:14 am, edited 1 time in total.
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Bugdude » Mon Oct 25, 2004 10:39 am

Cold Flame wrote:Do we have to use a vector? I think an array of "Point"s would be much better.


How would an array be better than a vector?
User avatar
Bugdude
Moderator
 
Posts: 2480
Joined: Sun Aug 29, 2004 1:58 am
Location: Living in sin

Postby Invictus » Mon Oct 25, 2004 11:01 am

Bugdude wrote:
Cold Flame wrote:Do we have to use a vector? I think an array of "Point"s would be much better.


How would an array be better than a vector?


Speed, efficiency, accessability... but I will use a vector if an array is not allowed.

Acctually if you really wanna use an STL class, a list, queue, or stack would be much better because the operation does not require accessing any specific elements. You are reading the vertecies from top to bottom so a vector is possibly the worst data type I can think of for this specific task.
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Invictus » Mon Oct 25, 2004 12:13 pm

draw_polygon() isnt the only function we can use it is? I can make other function can't I? Would be absolutely pointless if we couldn't so I am assuming we can.

- Can I use an array or not?
User avatar
Invictus
 
Posts: 3054
Joined: Tue Oct 21, 2003 12:59 pm

Postby Bugdude » Mon Oct 25, 2004 7:21 pm

Cold Flame wrote:
Bugdude wrote:
Cold Flame wrote:Do we have to use a vector? I think an array of "Point"s would be much better.


How would an array be better than a vector?


Speed, efficiency, accessability... but I will use a vector if an array is not allowed.

Vectors are equal to arrays on those factors.
Cold Flame wrote:Acctually if you really wanna use an STL class, a list, queue, or stack would be much better because the operation does not require accessing any specific elements. You are reading the vertecies from top to bottom so a vector is possibly the worst data type I can think of for this specific task.

No a vector is just dandy in this case as you will not be editing the list of points so the vector will not be growing or shrinking. Also, being able to randomly access the contents of the vector might come in handy for this task.
User avatar
Bugdude
Moderator
 
Posts: 2480
Joined: Sun Aug 29, 2004 1:58 am
Location: Living in sin

Re: Unobfuscated code contest #1

Postby Darobat » Mon Oct 25, 2004 7:40 pm

Beer Hunter wrote:The coordinates (0, 5) refer to a point exactly halfway across the first column and exactly halfway down the sixth row in the console. The coordinates will not extend beyond column #70 or row.

Aw, cant the coordinates be normal, like 0,0 is the top left corner. 5,10 is 5 across and 10 down. That would make more sense. Aslo, "halfway across the first column"? Columns run vericaly so do you mean halfway down or what? Your coordinate system is confusing.

Also, how should we get the input? Should it be read from a text file or what? Should it ask the user for points? I think those are all my questions
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby MXP » Mon Oct 25, 2004 8:25 pm

You're not writing the system that gets the input. You're only writing the function that deals with the input after it has already been acquired.

By "halfway across the first column" it is meant that the x-coordinate exists in the middle of the cell, not at a vertex of the cell.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Darobat » Mon Oct 25, 2004 9:07 pm

Well thats even more confusing... :?
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby Kybo Ren » Mon Oct 25, 2004 9:08 pm

No, it just means you will have to store an array with the vertices of each character and find the character whose area contains the point.
Kybo Ren
C++ Beginner
 
Posts: 2049
Joined: Wed Feb 11, 2004 9:28 pm

Next

Return to Contests

Who is online

Users browsing this forum: No registered users and 0 guests