Note that there are some explanatory texts on larger screens.

plurals
  1. POCode Golf - π day
    text
    copied!<h2>The Challenge</h2> <p><a href="https://meta.stackexchange.com/questions/24242">Guidelines for code-golf on SO</a></p> <p>The shortest code by character count to display a representation of a circle of radius <em><code>R</code></em> using the <code>*</code>character, followed by an approximation of π.</p> <p>Input is a single number, <em><code>R</code></em>.</p> <p>Since most computers seem to have almost 2:1 ratio you should only output lines where <em><code>y</code></em> is odd. This means that when <em><code>R</code></em> is odd you should print <em><code>R-1</code></em> lines. There is a new testcase for <em><code>R=13</code></em> to clarify.</p> <p>eg.</p> <pre><code>Input 5 Output Correct Incorrect 3 ******* 4 ******* 1 ********* 2 ********* -1 ********* 0 *********** -3 ******* -2 ********* 2.56 -4 ******* 3.44 </code></pre> <p><strong>Edit:</strong> Due to widespread confusion caused by odd values of <em><code>R</code></em>, any solutions that pass the 4 test cases given below will be accepted</p> <p>The approximation of π is given by dividing twice the number of <code>*</code> characters by <em><code>R²</code></em>.<br> The approximation should be correct to at least 6 significant digits.<br> Leading or trailing zeros are permitted, so for example any of <code>3</code>, <code>3.000000</code>, <code>003</code> is accepted for the inputs of <code>2</code> and <code>4</code>.</p> <p>Code count includes input/output (i.e., full program).</p> <h2>Test Cases</h2> <pre><code>Input 2 Output *** *** 3.0 Input 4 Output ***** ******* ******* ***** 3.0 Input 8 Output ******* ************* *************** *************** *************** *************** ************* ******* 3.125 Input 10 Output ********* *************** ***************** ******************* ******************* ******************* ******************* ***************** *************** ********* 3.16 </code></pre> <h2>Bonus Test Case</h2> <pre><code>Input 13 Output ************* ******************* ********************* *********************** ************************* ************************* ************************* ************************* *********************** ********************* ******************* ************* 2.98224852071 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload