aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/james-smith
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-02-07 21:11:25 +0000
committerdrbaggy <js5@sanger.ac.uk>2022-02-07 21:11:25 +0000
commit0dda5fed4a18458b4ecb73f1bda960a3b6476d94 (patch)
tree7badc6c4ed3643877cce2d0fae8c748e914c84e3 /challenge-151/james-smith
parent3a155754f659bc83e1b8e907e70b210b087e4632 (diff)
downloadperlweeklychallenge-club-0dda5fed4a18458b4ecb73f1bda960a3b6476d94.tar.gz
perlweeklychallenge-club-0dda5fed4a18458b4ecb73f1bda960a3b6476d94.tar.bz2
perlweeklychallenge-club-0dda5fed4a18458b4ecb73f1bda960a3b6476d94.zip
pushed some more tests
Diffstat (limited to 'challenge-151/james-smith')
-rw-r--r--challenge-151/james-smith/perl/ch-1.pl48
1 files changed, 48 insertions, 0 deletions
diff --git a/challenge-151/james-smith/perl/ch-1.pl b/challenge-151/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..d34b5ad219
--- /dev/null
+++ b/challenge-151/james-smith/perl/ch-1.pl
@@ -0,0 +1,48 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+my @TESTS = (
+ [ '1', 1 ],
+ [ '1 | 2 3 ', 2 ],
+ [ '1 | 2 3 |', 2 ],
+ [ '1 | 2 3 | * *', 2 ],
+ [ '1 | 2 3 | 4 5', 2 ],
+ [ '1 | 2 3 | 4 5 *', 2 ],
+ [ '1 | 2 3 | 4 * * 5 | * 6', 3 ],
+ [ '1 | 2 3 | 4 * 5 | 6 * 7 * 8 * 9 | 10 * * 11 12 * * 13 14 * * 15 16 * * 17 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49', 6 ],
+ [ '1 | 2 3 | 4 * 5 | 6 * 7 * 8 * 9 | 10 * * 11 12 * * 13 14 * * 15 16 * * 17 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48', 6 ],
+ [ '1 | 2 3 | 4 * 5 | 6 * 7 * 8 * 9 | 10 * * 11 12 * * 13 14 * * 15 16 * * 17 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47', 5 ],
+ [ '1 | 2 3 | 4 * 5 | 6 * 7 * 8 * 9 | 10 * * 11 12 * * 13 14 * * 15 16 * * 17 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 * * 47', 6 ],
+ [ '1 | 2 3 | 4 * 5 | 6 * 7 * 8 * 9 | 10 * * 11 12 * * 13 14 * * 15 16 * * 17 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 * * 46 47', 5 ],
+ [ '1 | 2 3 | 4 * 5 | 6 * 7 * 8 * 9 | 10 * * 11 12 * * 13 14 * * 15 16 * * 17', 5 ],
+ [ '1 | 2 3 | 4 * 5 | 6 * 7 * 8 * 9 | 10 * * 11 12 13 * * 14 * * 15 16 * * 17', 4 ],
+ [ '1 | 2 3 | * * 4 5', 2 ],
+ [ '1 | 2 3 | 4 5 | 6 7 8 9', 2 ],
+);
+
+is( depth($_->[0]), $_->[1] ) foreach @TESTS;
+done_testing();
+
+sub depth {
+ ## Split into individual rows....
+ ## For each row if
+ ## there are less than 2**$d - 1 entries in the row...
+ ## OR there is * * in one of the pairs
+ ## OR there is a single * in the last pair.
+
+ my $d = 0;
+ for ( split m{\s*\|\s*}, $_[0] ) {
+ last if scalar @{[m{\S+}g]} < 2**$d - 1
+ || m{^\s*(?:\S+\s+\S+\s+)*?(\*\s+\*|\*\s*$)};
+ $d++;
+ }
+ $d;
+}
+