aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;