diff options
| author | David Ferrone <zapwai@gmail.com> | 2023-06-05 17:52:51 -0400 |
|---|---|---|
| committer | David Ferrone <zapwai@gmail.com> | 2023-06-05 17:52:51 -0400 |
| commit | bb08e3c1a1e3352862f9c795b60a33a9c81ec64a (patch) | |
| tree | 52f4094b2fbf09756063b69a9330817f63aa1db1 | |
| parent | 401be1861472af6d62bbdeb0fe65f6ced1ca8f31 (diff) | |
| download | perlweeklychallenge-club-bb08e3c1a1e3352862f9c795b60a33a9c81ec64a.tar.gz perlweeklychallenge-club-bb08e3c1a1e3352862f9c795b60a33a9c81ec64a.tar.bz2 perlweeklychallenge-club-bb08e3c1a1e3352862f9c795b60a33a9c81ec64a.zip | |
Week 220
| -rw-r--r-- | challenge-220/zapwai/perl/ch-1.pl | 13 | ||||
| -rw-r--r-- | challenge-220/zapwai/perl/ch-2.pl | 33 |
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-220/zapwai/perl/ch-1.pl b/challenge-220/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..737084de80 --- /dev/null +++ b/challenge-220/zapwai/perl/ch-1.pl @@ -0,0 +1,13 @@ +use v5.30.0; +no warnings; +my @words = ("Perl", "Rust", "Raku"); +say "Input: \@words = (" . join(",",@words) . ")"; +$words[$_] = lc $words[$_] for (0 .. $#words); +my @intersection = split("",$words[0]); +for my $i (1 .. $#words) { + my @letters = split("",$words[$i]); + for my $j (0 .. $#intersection) { + splice(@intersection, $j, 1) unless ($intersection[$j] ~~ @letters); + } +} +say "Output: @intersection"; diff --git a/challenge-220/zapwai/perl/ch-2.pl b/challenge-220/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..eb1e023045 --- /dev/null +++ b/challenge-220/zapwai/perl/ch-2.pl @@ -0,0 +1,33 @@ +use v5.30.0; +use Algorithm::Permute; +my @ints = (1, 17, 8); +#my @ints = (2,2,2); +say "Input: \@ints = (" . join(",",@ints) . ")"; +my $p = Algorithm::Permute->new(\@ints); +print "Output: "; +my $out; +while (my @perm = $p->next) { + my $current_print = "(" . join(",",@perm) . ")"; + next if ($out =~ m/$current_print/); + $out .= $current_print if is_squareful(@perm); +} +$out =~ s/\)\(/\), \(/; +say $out; + +sub is_squareful { + my @list = @_; + my $cnt; + foreach (0 .. $#list-1) { + my $sum = $list[$_] + $list[$_+1]; + $cnt++ if (is_square($sum)); + } + return 1 if ($cnt == $#list); + 0 +} + +sub is_square { + my $num = shift; + my $U = int (sqrt($num)); + return 1 if ($U**2 == $num); + 0 +} |
