diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-08-02 16:53:24 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-08-02 16:53:24 +0100 |
| commit | c792fb0054e306729043275fef778d4d229b5d1b (patch) | |
| tree | cac26a8c835632724f6fdd1bdefa054764d53e3f | |
| parent | 2ffcc28bd08b0b5623a4ccd087c217b3b26918a9 (diff) | |
| download | perlweeklychallenge-club-c792fb0054e306729043275fef778d4d229b5d1b.tar.gz perlweeklychallenge-club-c792fb0054e306729043275fef778d4d229b5d1b.tar.bz2 perlweeklychallenge-club-c792fb0054e306729043275fef778d4d229b5d1b.zip | |
add tweak to avoid too many duplicate points by only doing roughly 1/8 of the circle! - and use a radius of r-1/2 to get a better set of points {due to rounding...}
| -rw-r--r-- | challenge-124/james-smith/perl/ch-1.pl | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/challenge-124/james-smith/perl/ch-1.pl b/challenge-124/james-smith/perl/ch-1.pl index 98695a06ea..34cdf2cd64 100644 --- a/challenge-124/james-smith/perl/ch-1.pl +++ b/challenge-124/james-smith/perl/ch-1.pl @@ -7,6 +7,7 @@ use feature qw(say); use Test::More; use Benchmark qw(cmpthese timethis); use Data::Dumper qw(Dumper); +use POSIX qw(ceil); my $tau = 6.283185307179586476925286766559; @@ -31,8 +32,8 @@ unless($radius) { my @a = map { ' ' x ($radius*2+1) } 0..$radius*2+$cross; ## Now we draw the circle... -foreach my $x (0..$radius) { - my $y = int sqrt( $radius**2 - $x**2 ); +foreach my $x (0 .. ceil($radius*0.71)) { + my $y = int sqrt( ($radius-.5)**2 - $x**2 ); substr $a[ $radius - $x ],$radius-$y,1,'^'; substr $a[ $radius + $x ],$radius-$y,1,'^'; substr $a[ $radius - $x ],$radius+$y,1,'^'; |
