Code Golf - PI day
Posted
by gnibbler
on Stack Overflow
See other posts from Stack Overflow
or by gnibbler
Published on 2010-03-13T22:38:07Z
Indexed on
2010/03/13
22:45 UTC
Read the original article
Hit count: 649
The Challenge
The shortest code by character count to display a representation of a circle of radius R
using the *
character. Followed by an approximation of pi
Input is a single number, R
Since most computers seem to have almost 2:1 ratio you should only output lines where y
is odd.
The approximation of pi is given by dividing the twice the number of *
characters by R
squared. The approximation should be correct to at least 6 significant digits. Leading or trailing zeros are permitted, so for example any of 3
,3.000000
,003
is accepted for the inputs of 2
and 4
Code count includes input/output (i.e full program).
Test Cases
Input
2
Output
***
***
3.0
Input
4
Output
*****
*******
*******
*****
3.0
Input
8
Output
*******
*************
***************
***************
***************
***************
*************
*******
3.125
Input
10
Output
*********
***************
*****************
*******************
*******************
*******************
*******************
*****************
***************
*********
3.16
© Stack Overflow or respective owner