aboutsummaryrefslogtreecommitdiff
path: root/challenge-211
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2023-04-06 22:51:27 +0100
committerGitHub <noreply@github.com>2023-04-06 22:51:27 +0100
commit57ef36f9f13d807c25ced6c193f8a16e8f391645 (patch)
treeaee9d8fc8361bb8b366fc787b91d23a41c2e2792 /challenge-211
parentd263ad04ff4f3c9face18e740d3faf076371ced8 (diff)
downloadperlweeklychallenge-club-57ef36f9f13d807c25ced6c193f8a16e8f391645.tar.gz
perlweeklychallenge-club-57ef36f9f13d807c25ced6c193f8a16e8f391645.tar.bz2
perlweeklychallenge-club-57ef36f9f13d807c25ced6c193f8a16e8f391645.zip
Create ch-1.pl
Diffstat (limited to 'challenge-211')
-rw-r--r--challenge-211/james-smith/perl/ch-1.pl22
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-211/james-smith/perl/ch-1.pl b/challenge-211/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..c62df391d1
--- /dev/null
+++ b/challenge-211/james-smith/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use Test::More;
+
+my @TESTS = (
+ [ [[4,3,2,1],[5,4,3,2],[6,5,4,3]], 1 ],
+ [ [[1,2,3],[3,2,1]], 0 ],
+);
+
+sub toeplitz {
+ return if @_ > @{$_[0]}; ## unclear but no diagonals..
+ my @st = @{$_[0]}[ 0 .. @{$_[0]} - @_ ];
+ for my $r ( 1 .. $#_ ) {
+ $st[$_] == $_[$r][$r+$_] || return 0 for 0 .. $#st;
+ }
+ 1
+}
+
+is( toeplitz( @{$_->[0]} ), $_->[1] ) for @TESTS;