diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-06-12 03:46:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-12 03:46:57 +0100 |
| commit | 48beedcdca7ecb7448cc274053b8171b6412627d (patch) | |
| tree | 9c273eb3b7fc01be48ca99868a372a8492b52ac9 | |
| parent | 4937c049b2bb49e2ee473ec68433cca9997c2343 (diff) | |
| parent | cc909bd14aeda7f762256e7c8d35cccde7cdbc6c (diff) | |
| download | perlweeklychallenge-club-48beedcdca7ecb7448cc274053b8171b6412627d.tar.gz perlweeklychallenge-club-48beedcdca7ecb7448cc274053b8171b6412627d.tar.bz2 perlweeklychallenge-club-48beedcdca7ecb7448cc274053b8171b6412627d.zip | |
Merge pull request #8195 from deadmarshal/TWC220
TWC220
| -rw-r--r-- | challenge-220/deadmarshal/perl/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-220/deadmarshal/perl/ch-2.pl | 34 |
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-220/deadmarshal/perl/ch-1.pl b/challenge-220/deadmarshal/perl/ch-1.pl new file mode 100644 index 0000000000..505ecbcb8f --- /dev/null +++ b/challenge-220/deadmarshal/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::MoreUtils qw(uniq); + +sub common_characters{ + my %count; + map{$count{$_}++ foreach uniq split '',CORE::fc} @{$_[0]}; + sort grep{$count{$_} == @{$_[0]}} keys %count; +} + +printf "%s\n", join ' ', common_characters(["Perl","Rust","Raku"]); +printf "%s\n", join ' ', common_characters(["love","live","leave"]); + diff --git a/challenge-220/deadmarshal/perl/ch-2.pl b/challenge-220/deadmarshal/perl/ch-2.pl new file mode 100644 index 0000000000..3de51a3fcf --- /dev/null +++ b/challenge-220/deadmarshal/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Algorithm::Combinatorics qw(permutations); +use List::MoreUtils qw(slide all); +use Data::Show; + +sub is_perfect_square{ + do{ + my $sqrt = sqrt($_[0]); + return ($sqrt * $sqrt) == $_[0]; + }if($_[0] >= 0); + 0 +} + +sub squareful{ + my %hash; + map{$hash{$_}++} @{$_[0]}; + return @{$_[0]} if keys %hash == 1; + my @ret; + my $iter = permutations($_[0]); + while(my $p = $iter->next) + { + if(all{$_ == 1} slide{is_perfect_square($a+$b)} @$p) + { + push @ret,$p; + } + } + @ret; +} + +print show squareful([1,17,8]); +print show squareful([2,2,2]); + |
