diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-01-29 10:55:39 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-29 10:55:39 +0000 |
| commit | 31ff6fb6860e19d6c79f85122e2a191b93f798ae (patch) | |
| tree | 9856d7379845400ca6137a75dfddb82be7847e74 | |
| parent | f0be3d65cf7449a780ecbbac950f152d47dd23d1 (diff) | |
| parent | f6cf359ce4aa1bac1dd3aa8bb0913dcaf63f7000 (diff) | |
| download | perlweeklychallenge-club-31ff6fb6860e19d6c79f85122e2a191b93f798ae.tar.gz perlweeklychallenge-club-31ff6fb6860e19d6c79f85122e2a191b93f798ae.tar.bz2 perlweeklychallenge-club-31ff6fb6860e19d6c79f85122e2a191b93f798ae.zip | |
Merge pull request #7469 from zapwai/branch-for-201
Week 201
| -rw-r--r-- | challenge-201/zapwai/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-201/zapwai/perl/ch-1.pl | 10 | ||||
| -rw-r--r-- | challenge-201/zapwai/perl/ch-2.pl | 44 |
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-201/zapwai/blog.txt b/challenge-201/zapwai/blog.txt new file mode 100644 index 0000000000..366429dbdf --- /dev/null +++ b/challenge-201/zapwai/blog.txt @@ -0,0 +1 @@ +https://dev.to/zapwai/weekly-challenge-201-1ibc diff --git a/challenge-201/zapwai/perl/ch-1.pl b/challenge-201/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..09fb875c85 --- /dev/null +++ b/challenge-201/zapwai/perl/ch-1.pl @@ -0,0 +1,10 @@ +use v5.30.0; +no warnings "experimental"; +my @array = (0,1,3); +my @list; +say "Input: (" . join(",",@array).")"; +print "Output: "; +for (0..scalar @array) { + push @list, $_ unless ($_ ~~ @array); +} +say join(",", @list); diff --git a/challenge-201/zapwai/perl/ch-2.pl b/challenge-201/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..8880cc7d15 --- /dev/null +++ b/challenge-201/zapwai/perl/ch-2.pl @@ -0,0 +1,44 @@ +use v5.30.0; +no warnings "experimental"; +my $n = $ARGV[0] || 5; +say "Input: \$n = $n"; +print "Output: " ; +my @set = (join(" ",(1) x $n)); +my $i=-1; +do { + $i++; + rout($set[$i]); + @set = grep { defined($_) } @set; +} until (length $set[$i] <= 3); +my $length = @set; +do { + rout($set[$i]); + $i++; +} while ($i < $length); +push @set, $n; +say scalar @set; +say foreach @set; +sub rout { + my $s = shift; + my @a = split(" ", $s); + return "no" if (@a <= 2); + if ($a[$#a] != 1) { + for (1 .. @a - 2) { + my $str = chonk($_, @a); + push @set, $str unless ($str ~~ @set); + } + } + my $str = chonk(0, @a); + push @set, $str unless ($str ~~ @set); +} +sub chonk { #add two elems, given offset. + my ($offset, @a) = @_; + my $num = $a[$#a - $offset] + $a[$#a - $offset - 1]; + splice @a, $#a - $offset - 1, 2, $num; + my $bad_cnt; + for (1.. $#a) { + $bad_cnt++ if ($a[$_ - 1] > $a[$_]); + } + return if ($bad_cnt); + return join(" ",@a); +} |
