aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrtastic <brtastic.dev@gmail.com>2021-06-04 00:04:22 +0200
committerbrtastic <brtastic.dev@gmail.com>2021-06-04 00:04:22 +0200
commitbe4538eab6cd1a2f7ec0588d038659d1fe79e219 (patch)
tree71cb4bb7b49737f7220321cad1d2f84298d66874
parent64fa9b1a16cb3b07c48a76dc509074ae1e738b0b (diff)
downloadperlweeklychallenge-club-be4538eab6cd1a2f7ec0588d038659d1fe79e219.tar.gz
perlweeklychallenge-club-be4538eab6cd1a2f7ec0588d038659d1fe79e219.tar.bz2
perlweeklychallenge-club-be4538eab6cd1a2f7ec0588d038659d1fe79e219.zip
Perl solution to ch-1 by Bartosz Jarzyna
-rw-r--r--challenge-115/brtastic/blog.txt1
-rw-r--r--challenge-115/brtastic/perl/ch-1.pl40
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-115/brtastic/blog.txt b/challenge-115/brtastic/blog.txt
new file mode 100644
index 0000000000..36d46f06e5
--- /dev/null
+++ b/challenge-115/brtastic/blog.txt
@@ -0,0 +1 @@
+https://brtastic.xyz/blog/article/zipping-arrays-in-perl
diff --git a/challenge-115/brtastic/perl/ch-1.pl b/challenge-115/brtastic/perl/ch-1.pl
new file mode 100644
index 0000000000..23375670c0
--- /dev/null
+++ b/challenge-115/brtastic/perl/ch-1.pl
@@ -0,0 +1,40 @@
+use v5.34;
+use warnings;
+
+use Algorithm::Permute;
+use List::Util qw(zip all);
+
+sub comes_after
+{
+ my ($previous, $next) = @_;
+
+ return substr($previous, -1) eq substr($next, 0, 1);
+}
+
+sub check_string_chain
+{
+ my @string_list = @_;
+
+ my $iterator = Algorithm::Permute->new(\@string_list);
+
+ while (my @case = $iterator->next) {
+ my @to_compare = @case;
+ push @to_compare, shift @to_compare;
+
+ return 1 if all {
+ comes_after $_->@*
+ } zip \@case, \@to_compare;
+ }
+
+ return 0;
+}
+
+use Test::More;
+
+is check_string_chain(qw<abc dea cd>), 1;
+is check_string_chain(qw<ade cbd fgh>), 0;
+is check_string_chain(qw<ab bc cd de ef fg gh hi ia>), 1;
+is check_string_chain(qw<ab bc cd de ef fg gh hi>), 0;
+is check_string_chain(qw<bc cd de ef fg gh hi ia>), 0;
+
+done_testing;