From 0dda5fed4a18458b4ecb73f1bda960a3b6476d94 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 7 Feb 2022 21:11:25 +0000 Subject: pushed some more tests --- challenge-151/james-smith/perl/ch-1.pl | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 challenge-151/james-smith/perl/ch-1.pl 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; +} + -- cgit