Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>In dc: 88 and 93 <strike>93 94 96 102 105 129 138 141</strike> chars</h2> <p>Just in case, I am using OpenBSD and some supposedly non-portable extensions at this point.</p> <p>93 chars. This is based on same formula as FORTRAN solution (slightly different results than test cases). Calculates X^2=R^2-Y^2 for every Y</p> <pre><code>[rdPr1-d0&lt;p]sp1?dsMdd*sRd2%-- [dd*lRr-vddlMr-32rlpxRR42r2*lpxRRAP4*2+lN+sN2+dlM&gt;y] dsyx5klNlR/p </code></pre> <p>88 chars. Iterative solution. Matches test cases. For every X and Y checks if X^2+Y^2&lt;=R^2</p> <pre><code>1?dsMdd*sRd2%--sY[0lM-[dd*lYd*+lRr(2*d5*32+PlN+sN1+dlM!&lt;x]dsxxAPlY2+dsYlM&gt;y] dsyx5klNlR/p </code></pre> <p>To run <code>dc pi.dc</code>.</p> <p>Here is an older annotated version:</p> <pre><code># Routines to print '*' or ' '. If '*', increase the counter by 2 [lN2+sN42P]s1 [32P]s2 # do 1 row # keeping I in the stack [ # X in the stack # Calculate X^2+Y^2 (leave a copy of X) dd*lYd*+ #Calculate X^2+Y^2-R^2... lR-d # .. if &lt;0, execute routine 1 (print '*') 0&gt;1 # .. else execute routine 2 (print ' ') 0!&gt;2 # increment X.. 1+ # and check if done with line (if not done, recurse) d lM!&lt;x ]sx # Routine to cycle for the columns # Y is on the stack [ # push -X 0lM- # Do row lxx # Print EOL 10P # Increment Y and save it, leaving 2 copies lY 2+ dsY # Check for stop condition lM &gt;y ]sy # main loop # Push Input value [Input:]n? # Initialize registers # M=rows d sM # Y=1-(M-(M%2)) dd2%-1r-sY # R=M^2 d*sR # N=0 0sN [Output:]p # Main routine lyx # Print value of PI, N/R 5klNlR/p </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