From be4538eab6cd1a2f7ec0588d038659d1fe79e219 Mon Sep 17 00:00:00 2001 From: brtastic Date: Fri, 4 Jun 2021 00:04:22 +0200 Subject: Perl solution to ch-1 by Bartosz Jarzyna --- challenge-115/brtastic/blog.txt | 1 + challenge-115/brtastic/perl/ch-1.pl | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 challenge-115/brtastic/blog.txt create mode 100644 challenge-115/brtastic/perl/ch-1.pl 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), 1; +is check_string_chain(qw), 0; +is check_string_chain(qw), 1; +is check_string_chain(qw), 0; +is check_string_chain(qw), 0; + +done_testing; -- cgit