diff options
| author | Ysmael Ebreo <Ysmael.Ebreo@latticesemi.com> | 2020-08-30 23:40:35 +0800 |
|---|---|---|
| committer | Ysmael Ebreo <Ysmael.Ebreo@latticesemi.com> | 2020-08-30 23:40:35 +0800 |
| commit | 1526588a66a2b61619ea647c6b975907f13588f5 (patch) | |
| tree | 8acce50464a17a1469f5e9d7cffc765ba8df8a34 | |
| parent | 8d980bf1f93ace9b804a64dd60fba27a7b25c72f (diff) | |
| download | perlweeklychallenge-club-1526588a66a2b61619ea647c6b975907f13588f5.tar.gz perlweeklychallenge-club-1526588a66a2b61619ea647c6b975907f13588f5.tar.bz2 perlweeklychallenge-club-1526588a66a2b61619ea647c6b975907f13588f5.zip | |
perl solution for ch#75
| -rw-r--r-- | challenge-075/yet-ebreo/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-075/yet-ebreo/perl/ch-2.pl | 46 |
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-075/yet-ebreo/perl/ch-1.pl b/challenge-075/yet-ebreo/perl/ch-1.pl new file mode 100644 index 0000000000..21db363590 --- /dev/null +++ b/challenge-075/yet-ebreo/perl/ch-1.pl @@ -0,0 +1,18 @@ +#! /usr/bin/perl +use strict; +use warnings; +use feature 'say'; +use Algorithm::Combinatorics 'combinations_with_repetition'; +use List::Util 'sum'; + +my @C = sort {$a-$b} (1, 2, 4); +my $S = 6; + +my $max = 0 | $S / $C[0]; + + +for my $k (1+$S/$C[-1] .. $max) { + for my $v ( combinations_with_repetition(\@C, $k) ) { + ($S == sum @$v) && say "@$v" + } +}
\ No newline at end of file diff --git a/challenge-075/yet-ebreo/perl/ch-2.pl b/challenge-075/yet-ebreo/perl/ch-2.pl new file mode 100644 index 0000000000..ed2baf0412 --- /dev/null +++ b/challenge-075/yet-ebreo/perl/ch-2.pl @@ -0,0 +1,46 @@ +#! /usr/bin/perl +use strict; +use warnings; +use feature 'say'; +use List::Util 'max'; + +my @R = (2, 1, 4, 5, 3, 7); + +# 7 # +# 6 # +# 5 # # +# 4 # # # +# 3 # # # # +# 2 # # # # # +# 1 # # # # # # +# _ _ _ _ _ _ _ +# 2 1 4 5 3 7 + +# Result : 12 +my @res; +for my $f (@R) { + my $s = 0; + for my $e (@R) { + if ($e >= $f) { + $s++ + } else { + push @res, $s * $f; + $s = 0; + } + } + push @res, $s * $f; +} + +#Will work nicely on values < 10 +for my $t (-(max @R) .. -1) { + print -$t; + say map { $_ >= -$t ? " #" : " " } @R +} +say "- " x (@R+1); +say " @R\n"; + +say max @res + + + + |
