Revision a5279e64-0266-4601-ae4c-19552cde63c0 - Stack Overflow

<h1>Javascript: <strike>213</strike> 163</h1>


----------

Updated

 r=10;m=Math;a=Array;t=0;l=document;for(i=-r;i<r;i+=2){w=m.floor(m.sqrt(r*r-i*i)*2);t+=w*2;l.writeln(a(m.round(r-w/2)).join(' ')+a(w).join('*'));}l.writeln(t/(r*r))

Nobody said it had to render correctly in the browser - just the output. As such I've removed the pre tags and optimised it further. To view the output you need to view generated source or set your stylesheet accordingly. Pi is less accurate this way, but it's now to spec.

----------


 r=10;m=Math;a=Array;t=0;s='';for(i=-r;i<r;i++){w=m.floor((m.sqrt(m.pow(r,2)-m.pow(i,2)))*2);t+=w;if(i%2){z=a(m.round(r-w/2)).join(' ')+a(w).join('*');s+=z+'\n';}}document.write('<pre>'+(s+(t/m.pow(r,2)))+'</pre>')

Unminified:

 r=10;
 m=Math;
 a=Array;
 t=0;
 s='';
 for(i=-r;i<r;i++){
 	w=m.floor((m.sqrt(m.pow(r,2)-m.pow(i,2)))*2);
 	t+=w;
 	if(i%2){
 	z=a(m.round(r-w/2)).join(' ')+a(w).join('*');
 	s+=z+'\n';
 	}
 }
 document.write('<pre>'+(s+(t/m.pow(r,2)))+'</pre>');

AltStyle によって変換されたページ (->オリジナル) /