Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Perl, <em>95</em> <del>96</del> <del>99</del> <del>106</del> <del>109</del> <del>110</del> <del>119</del> characters:</h2> <pre><code>$t+=$;=1|2*sqrt($r**2-($u-2*$_)**2),say$"x($r-$;/2).'*'x$;for 0.. ($u=($r=&lt;&gt;)-1|1);say$t*2/$r**2 </code></pre> <p>(The newline can be removed and is only there to avoid a scrollbar)</p> <p>Yay! Circle version!</p> <pre><code> $t+=$;= 1|2*sqrt($r** 2-($u-2*$_)**2) ,say$"x($r-$;/2 ).'*'x$;for 0.. ($u=($r=&lt;&gt;)-1|1 );$pi=~say$t* 2/$r**2 </code></pre> <p>For the uninitiated, the long version:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use feature 'say'; # Read the radius from STDIN my $radius = &lt;&gt;; # Since we're only printing asterisks on lines where y is odd, # the number of lines to be printed equals the size of the radius, # or (radius + 1) if the radius is an odd number. # Note: we're always printing an even number of lines. my $maxline = ($radius - 1) | 1; my $surface = 0; # for ($_ = 0; $_ &lt;= $maxline; $_++), if you wish for (0 .. $maxline) { # First turn 0 ... N-1 into -(N/2) ... N/2 (= Y-coordinates), my $y = $maxline - 2*$_; # then use Pythagoras to see how many stars we need to print for this line. # Bitwise OR "casts" to int; and: 1 | int(2 * x) == 1 + 2 * int(x) my $stars = 1 | 2 * sqrt($radius**2-$y**2); $surface += $stars; # $" = $LIST_SEPARATOR: default is a space, # Print indentation + stars # (newline is printed automatically by say) say $" x ($radius - $stars/2) . '*' x $stars; } # Approximation of Pi based on surface area of circle: say $surface*2/$radius**2; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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