diff options
| -rw-r--r-- | challenge-124/james-smith/perl/ch-1.pl | 52 | ||||
| -rw-r--r-- | challenge-124/james-smith/perl/ch-2.pl | 22 |
2 files changed, 74 insertions, 0 deletions
diff --git a/challenge-124/james-smith/perl/ch-1.pl b/challenge-124/james-smith/perl/ch-1.pl new file mode 100644 index 0000000000..98695a06ea --- /dev/null +++ b/challenge-124/james-smith/perl/ch-1.pl @@ -0,0 +1,52 @@ +#!/usr/local/bin/perl + +use strict; + +use warnings; +use feature qw(say); +use Test::More; +use Benchmark qw(cmpthese timethis); +use Data::Dumper qw(Dumper); +my $tau = 6.283185307179586476925286766559; + + +my $radius = @ARGV ? shift @ARGV : 10; +my $cross = @ARGV ? shift @ARGV : $radius; + $cross++ if $cross&1; + +### A simple one to render the cross as drawin the question... + +unless($radius) { + my @pts = qw(-1 3 4 5 5 5 5 5 4 3 -1 0 0 0 -1 0 0); + say $_ < 0 ? ' ^^^^^' + : !$_ ? ' ^' + : ' ' x (6-$_) . '^' . ' 'x($_*2-1) .'^' + foreach @pts; + exit; +} + +## We will render the relevant sized venus symbol... + +## Create the canvas.. +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 ); + substr $a[ $radius - $x ],$radius-$y,1,'^'; + substr $a[ $radius + $x ],$radius-$y,1,'^'; + substr $a[ $radius - $x ],$radius+$y,1,'^'; + substr $a[ $radius + $x ],$radius+$y,1,'^'; + substr $a[ $radius - $y ],$radius-$x,1,'^'; + substr $a[ $radius + $y ],$radius-$x,1,'^'; + substr $a[ $radius - $y ],$radius+$x,1,'^'; + substr $a[ $radius + $y ],$radius+$x,1,'^'; +} + +## And the two parts of the cross... +substr $a[2*$radius+$_],$radius,1,'^' foreach 0..$cross; +substr $a[2*$radius+$cross/2],$radius-$cross/2,$cross+1,'^'x($cross+1); + +### Finally we render the canvas... +say $_ foreach @a; + diff --git a/challenge-124/james-smith/perl/ch-2.pl b/challenge-124/james-smith/perl/ch-2.pl new file mode 100644 index 0000000000..2348c8b946 --- /dev/null +++ b/challenge-124/james-smith/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/local/bin/perl + +use strict; + +use warnings; +use feature qw(say); +use Test::More; +use Benchmark qw(cmpthese timethis); +use Data::Dumper qw(Dumper); + +my @TESTS = ( + [ 0, 1 ], +); + +is( my_function($_->[0]), $_->[1] ) foreach @TESTS; + +done_testing(); + +sub my_function { + return 1; +} + |
