Miscellaneous > Programming & Networking

A programming challenge all up in your face.

<< < (24/24)

piratePenguin:
Wow.. I just went through my old (old) programming crap and found the start I made to this challenge.. and it ain't bad! Dated 05-Feb-2006. Jesus I can't believe this!

http://piratepenguin.is-a-geek.com/~declan/crap/old-stuff/programming/c/curve_challenge/main.c or http://illhostit.com/files/cd815a8f0c8a59847303fe1067003ab0/main.c

It uses glib (linked lists FTW!), so install glib2.0-dev or whatever and compile with: 'gcc main main.c `pkg-config --cflags --libs glib-2.0` -lm'. (WTF: o with a hyphen (-) before it triggers that Forbidden message bug crap)

(it prints the INPUT, and records to stdout and to OUTPUT)

--- Quote ---[declan@localhost curve_challenge]$ ./main
line.p1.x: 0
line.p1.y: 0
line.p2.x: 10
line.p2.y: 10
num_circles: 1

circle->c.x: 5
circle->c.y: 5
circle->r: 1

The length of the curve is: 14.142136  [proper answer is apparently 15.2837]

 -- modify input --

[declan@localhost curve_challenge]$ ./main
line.p1.x: 0
line.p1.y: 5
line.p2.x: 10
line.p2.y: 5
num_circles: 1

circle->c.x: 5
circle->c.y: 6
circle->r: 1

The length of the curve is: 10.000000

 -- modify input --

[declan@localhost curve_challenge]$ ./main
line.p1.x: 0
line.p1.y: 0
line.p2.x: 0
line.p2.y: 10
num_circles: 1

circle->c.x: 0
circle->c.y: 5
circle->r: 1

The length of the curve is: 10.000000

--- End quote ---
Hehheh the tangent stuff works! (I think that's the *only* time it gets it right.. It wasn't complete and I don't feel like completing it, and the bits I don't have are probably the hardest - and why I never bothered to finish it)

Maybe it doesn't work with multiple circles either.. I should comment more heh.
--- Quote ---[declan@localhost curve_challenge]$ ./main
line.p1.x: 5
line.p1.y: 0
line.p2.x: 5
line.p2.y: 10
num_circles: 2

circle->c.x: 5
circle->c.y: 5
circle->r: 1

circle->c.x: 20
circle->c.y: 20
circle->r: 2

The length of the curve is: 10.000000
--- End quote ---
Is that right/wrong?

mobrien_12:
Penguin, your code seems to be calculating the lines alone and ignoring all the circles.  

You could finish it... :)

piratePenguin:

--- Quote from: mobrien_12 ---Penguin, your code seems to be calculating the lines alone and ignoring all the circles.  

You could finish it... :)
--- End quote ---
Yeah, well, it doesn't do a bad job of it! :p

I looked a bit at the code, and it hurts my eyes, and unfortunetly I don't have time for that anymore :(

mobrien_12:
Ok, now that I got Worker to figure out all the problems that might arise in C for me :)

Here's the vector solution in C.. some of his code blatently ripped off :)



--- Code: ---
/*
   vectsoln.c Vector solution in C form
*/

#include
#include
#include
#define TRUE 1
#define FALSE 0
#define FILENAMELENGTH 40
int main()
{
  /* variable declarations */
 
  /* file read/write variables */
  FILE *fRead;
  FILE *fWrite;
  char infilename[FILENAMELENGTH];
  char outfilename[FILENAMELENGTH];
  /* boolean variable type defined */
  typedef int bool;
   
  /* variables declared from input */
  double x1, y1, x2, y2;
  int i, numcircles;
  double circx[15], circy[15], radius[15];
 
  /* variables of importance */
  double linelength, totalpathlength;
  int numcirclesintersected=0;
 
  /* booleans of interest */
  bool EndNotInCircle, LineInRange, LineLongEnough;

  /* variables for intermediate calculations */
  double s1,s2,p1,p2,disttoline,numerator;
   
  double halfangle, arclength, chordlength, pathdifference;
 
  /* opening the file and reading contents into variables */
  /* printf("Enter a filename for input:\n");
    scanf("%s", &infilename); */
  strncpy(infilename,"data.dat",40);
  fRead =fopen(infilename, "r");
  if (fRead==NULL)
    {
    printf("input file unavailable\n");
    return 1;
    }
  fscanf(fRead, "%lf", &x1);
  fscanf(fRead, "%lf", &y1);
  fscanf(fRead, "%lf", &x2);
  fscanf(fRead, "%lf", &y2);
  fscanf(fRead, "%d", &numcircles);
  printf("x1 %f y1 %f x2 %f y2 %f numcircles %i\n",x1,y1,x2,y2,numcircles);
   
  if (numcircles>15)
    {
    printf("too many circles, aborting\n");
    return 1;
    }
  else
    {
    printf("%i circles in file.\n",numcircles);
    for(i=0; i

Navigation

[0] Message Index

[*] Previous page

Go to full version