diff options
| author | Bob Lied <boblied+github@gmail.com> | 2024-08-18 19:44:15 -0500 |
|---|---|---|
| committer | Bob Lied <boblied+github@gmail.com> | 2024-08-18 19:44:15 -0500 |
| commit | 2a7cc0992db22905fe9ea6def8bbd7514b089612 (patch) | |
| tree | 82572961c2e774f1400bc32039a4fe0e4e159ed1 | |
| parent | b9b4cdcddba3c0414e96407d360a4ce8aeda2b48 (diff) | |
| download | perlweeklychallenge-club-2a7cc0992db22905fe9ea6def8bbd7514b089612.tar.gz perlweeklychallenge-club-2a7cc0992db22905fe9ea6def8bbd7514b089612.tar.bz2 perlweeklychallenge-club-2a7cc0992db22905fe9ea6def8bbd7514b089612.zip | |
Week 282 solutions complete
| -rw-r--r-- | challenge-282/bob-lied/perl/ch-1.pl | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/challenge-282/bob-lied/perl/ch-1.pl b/challenge-282/bob-lied/perl/ch-1.pl index 5f3fb2cea0..325aeefc8b 100644 --- a/challenge-282/bob-lied/perl/ch-1.pl +++ b/challenge-282/bob-lied/perl/ch-1.pl @@ -42,6 +42,11 @@ sub goodInt($int) return -1; } +sub gi2($int) +{ + ( grep {length($_) == 3 } $int =~ m/((.)\2\2+)/g )[0] // -1 ; +} + sub runTest { use Test2::V0; @@ -53,14 +58,23 @@ sub runTest is( goodInt(12345666), "666", "At end"); is( goodInt(17775666), "777", "Two possibilities"); + is( gi2(12344456), "444", "gi2 Example 1"); + is( gi2(1233334), -1, "gi2 Example 2"); + is( gi2(10020003), "000", "gi2 Example 3"); + is( gi2(66612345), "666", "gi2 At front"); + is( gi2(12345666), "666", "gi2 At end"); + is( gi2(17775666), "777", "gi2 Two possibilities"); + done_testing; } sub runBenchmark($repeat) { use Benchmark qw/cmpthese/; + my @input = ( 12344456, 1233334, 10020003, 66612345, 12345666, 17775666 ); cmpthese($repeat, { - label => sub { }, + gi_while => sub { goodInt($_) for @input }, + gi_re => sub { gi2($_) for @input }, }); } |
