I can save it, I just don't know what program can view it ...
## Solution to Quirk's challenge problem## Written by M O'Brien. Copyright 2006.## Licenced to others under GPL.## Language is GNU Octave ([url]http://www.octave.org[/url])## READ DATA FILEfileid=fopen("data.dat","rt");[x1,count]=fscanf(fileid,"%f",1);[y1,count]=fscanf(fileid,"%f",1);[x2,count]=fscanf(fileid,"%f",1);[y2,count]=fscanf(fileid,"%f",1);[numcircles,count]=fscanf(fileid,"%d",1);for k=1:numcircles [circledat,count]=fscanf(fileid,"%f %f %f",3); circx(k)=circledat(1); circy(k)=circledat(2); radius(k)=circledat(3);endforfclose(fileid);## Start the interesting stufflinelength=sqrt( (x2-x1)**2 + (y2-y1)**2);totalpathlength=linelength;numcirclesintersected=0;for k=1:numcircles ##-------------------------------------------------------------------- ## calculate distance between circle center and the line. numerator=abs((x2-x1)*(y1-circy(k)) - \ (x1-circx(k))*(y2-y1) ); denominator=sqrt( (x2-x1)**2 + (y2-y1)**2 ); disttoline=numerator/denominator; ##-------------------------------------------------------------------- if (disttoline < radius(k)) ## the line is intersecting the current circle, forming a chord. ## Only use less than because if it is equal, it is a tangent line ## and will not affect the path extension at all numcirclesintersected=numcirclesintersected+1; halfangle=acos(disttoline/radius(k)); chordlength=2*radius(k)*sin(halfangle); arclength=2*halfangle*radius(k); pathdifference=arclength-chordlength; else ## Line does not interesect the circle. pathdifference=0; endif totalpathlength=totalpathlength+pathdifference;endfor## final output comes nowdisp("total number of circles intersected"),disp(numcirclesintersected);disp("length of line w/o circles factored in"), disp(linelength);disp("final path length after circles"), disp(totalpathlength);fileid=fopen("output.dat","wt");fprintf(fileid,"%f",totalpathlength);fclose(fileid);## end program
Thoughts?
After all, running Windows without a decent anti-virus is like walking through a Red Light District after eating five metric tonnes of Viagra.
octave kittens.mGNU Octave, version 2.9.8 (i686-redhat-linux-gnu).Copyright (C) 2006 John W. Eaton.This is free software; see the source code for copying conditions.There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY orFITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'.Additional information about Octave is available at http://www.octave.org.Please contribute if you find this software useful.For more information, visit http://www.octave.org/help-wanted.htmlReport bugs to (but first, please readhttp://www.octave.org/bugs.html to learn how to write a helpful report).total number of circles intersected 1length of line w/o circles factored in 12.728final path length after circles 15.999