diff options
| -rwxr-xr-x | challenge-006/maxim-kolodyazhny/perl5/ch-1.pl | 11 | ||||
| -rw-r--r-- | challenge-006/maxim-kolodyazhny/perl5/ch-1.t | 32 | ||||
| -rwxr-xr-x | challenge-006/maxim-kolodyazhny/perl5/ch-2.pl | 4 |
3 files changed, 38 insertions, 9 deletions
diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl b/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl index 0a87aa1371..c34849037f 100755 --- a/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl @@ -6,13 +6,14 @@ use 5.028.1; use List::Util qw(sum); s{ - ( \b \d+ ) - ( ,? \d+ , )+ - ( \d+ \b ) + ( \b \d+ ) + ( ,? \d+ , )+ + ( \d++ ) (??{ # this block is treated as a pattern - # != will return '' (always match) or 1 (fail because of previous \b) - ( $3 - $1 + 1 ) * ( $1 + $3 ) / 2 != sum split ',', $&; + # != will return '' (match) or 1 (fail, because \d++ will swallow all) + # sum( eval $& ) will work too (; + ( $3 - $1 + 1 ) * ( $1 + $3 ) / 2 != ( sum( split ',', $& ) || -1 ); }) } {$1-$3}xg; diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-1.t b/challenge-006/maxim-kolodyazhny/perl5/ch-1.t new file mode 100644 index 0000000000..6f75f83286 --- /dev/null +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-1.t @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use v5.028.1; + +use Test::More tests => 11; + +my %tests = ( + '0,0,0' => '0,0,0', + '0,9999999999' => '0,9999999999', + '1' => 1, + '1,1,1,2,3,4' => '1,1,1-4', + '1,2' => '1,2', + '1,2,3,4' => '1-4', + '10,2,3,4' => '10,2-4', + '100,101,102' => '100-102', + '3,2,1,0' => '3,2,1,0', + '4,3,2' => '4,3,2', + '100,1,2,3' => '100,1-3', +); + +while ( my ( $i, $o ) = each %tests ) { + + my $r = `echo $i | perl ./ch-1.pl`; + chomp $r; + + is( $r, $o ); +} + +done_testing 11; diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl b/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl index ff3bc8aa53..668d797feb 100755 --- a/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl @@ -1,10 +1,6 @@ #!/usr/bin/env perl -use strict; -use warnings; - use v5.028.1; - use bigrat qw(bexp PI); say bexp( PI * sqrt(163), 80 ); |
