diff options
| author | E. Choroba <choroba@matfyz.cz> | 2019-10-09 00:41:51 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2019-10-09 00:43:31 +0200 |
| commit | 130cd83b310c0957df6fe98ffc2600be5cc79fb1 (patch) | |
| tree | c537a76f5c4d4f8fff70bd2e22ae011ae8a8fc39 | |
| parent | faacebb2733b93df829e62e92f7873ef2a602fce (diff) | |
| download | perlweeklychallenge-club-130cd83b310c0957df6fe98ffc2600be5cc79fb1.tar.gz perlweeklychallenge-club-130cd83b310c0957df6fe98ffc2600be5cc79fb1.tar.bz2 perlweeklychallenge-club-130cd83b310c0957df6fe98ffc2600be5cc79fb1.zip | |
Add solutions to 029 (Brace expansion and C fucntion) by E. Choroba
| -rwxr-xr-x | challenge-029/e-choroba/perl5/ch-1.pl | 39 | ||||
| -rwxr-xr-x | challenge-029/e-choroba/perl5/ch-2.pl | 23 |
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-029/e-choroba/perl5/ch-1.pl b/challenge-029/e-choroba/perl5/ch-1.pl new file mode 100755 index 0000000000..c7de003078 --- /dev/null +++ b/challenge-029/e-choroba/perl5/ch-1.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +use warnings; +use strict; +use feature qw{ say }; + +sub expand { + my ($string) = @_; + grep length, glob $string =~ s/(\s)/\\$1/gr +} + +use Test::More tests => 5; +use Test::Deep; + +cmp_deeply [expand('Perl {Daily,Weekly,Monthly,Yearly} Challenge')], + bag('Perl Daily Challenge', + 'Perl Weekly Challenge', + 'Perl Monthly Challenge', + 'Perl Yearly Challenge'), + 'Original example'; + +cmp_deeply [expand('{a,,}')], + bag(qw( a )), + 'Empty results excluded'; + +cmp_deeply [expand('a{b,c}{d,e}f{g,h,i}')], + bag('abdfg', 'abdfh', 'abdfi', + 'abefg', 'abefh', 'abefi', + 'acdfg', 'acdfh', 'acdfi', + 'acefg', 'acefh', 'acefi'), + 'Multiple brackets'; + +cmp_deeply [expand('{{a,b}c,d}e')], + bag(qw( ace bce de )), + 'Nested brackets'; + +cmp_deeply [expand('{{a,b}c,d}{g,}')], + bag(qw( acg ac bcg bc dg d )), + 'Everything combined'; + diff --git a/challenge-029/e-choroba/perl5/ch-2.pl b/challenge-029/e-choroba/perl5/ch-2.pl new file mode 100755 index 0000000000..ed756c8f2d --- /dev/null +++ b/challenge-029/e-choroba/perl5/ch-2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Inline 'C'; + +use Test::More tests => 2; + +is factorial(20), 2432902008176640000; +is greet('world'), 'Hello world!'; + +__END__ +__C__ + +long factorial (long n) { + long r = 1; + for (long i = 2; i <= n; i++) r *= i; + return r; +} + +SV *greet (SV* name) { + return(newSVpvf("Hello %s!", SvPV(name, PL_na))); +} |
