aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-11-29 12:43:03 +0000
committerGitHub <noreply@github.com>2022-11-29 12:43:03 +0000
commit82bfe670984001f60cd499a76d3249bbe8f43605 (patch)
treef6cd132f77747ba60d2ac480452ea9144227605d
parentc1f05931f4a6438627eb4794ed852ec66af243c2 (diff)
downloadperlweeklychallenge-club-82bfe670984001f60cd499a76d3249bbe8f43605.tar.gz
perlweeklychallenge-club-82bfe670984001f60cd499a76d3249bbe8f43605.tar.bz2
perlweeklychallenge-club-82bfe670984001f60cd499a76d3249bbe8f43605.zip
Update ch-2.pl
-rw-r--r--challenge-193/james-smith/perl/ch-2.pl9
1 files changed, 3 insertions, 6 deletions
diff --git a/challenge-193/james-smith/perl/ch-2.pl b/challenge-193/james-smith/perl/ch-2.pl
index 35391469fa..e4877da7b9 100644
--- a/challenge-193/james-smith/perl/ch-2.pl
+++ b/challenge-193/james-smith/perl/ch-2.pl
@@ -9,7 +9,9 @@ my $SIZE = 100;
my %map2 = map { my $a=$_; map { ("$a$_" => ord($a)-ord($_)) } 'a'..'z' } 'a'..'z';
my %map3 = map { my $b = $_; map { my $a=$_; map { ("$a$b$_" => ord($a)*99-ord($b)*100+ord($_)) } 'a'..'z' } 'a'..'z' } 'a'..'z';
+
my @list = map { chr(97+rand(26)) x 3 } 1..$SIZE;
+
my @TESTS = (
[ [qw(adc wzy abc)], 'abc' ],
[ [qw(bob bbb ccc ddd)], 'bob' ],
@@ -19,9 +21,6 @@ my @TESTS = (
## Put "bob" in every position within the list...
map { my $t = [ @list ]; $t->[$_]='bob'; [ $t, 'bob' ] } 0..$SIZE-1
);
-my @TESTS =
- @lists,
-);
is( odd_string_array( @{$_->[0]} ), $_->[1] ) for @TESTS;
is( odd_string_ord( @{$_->[0]} ), $_->[1] ) for @TESTS;
@@ -40,9 +39,7 @@ sub odd_string {
}
sub odd_string_ord {
- my($x1,$x2) = (
- ord($_[0]) - ord(substr$_[0],1), ord($_[0]) - ord(substr$_[0],2),
- );
+ my($x1,$x2) = ( ord($_[0]) - ord(substr$_[0],1), ord($_[0]) - ord(substr$_[0],2) );
## The first two characters are different - so we need to check the first against the third
## If it is the same then the character we want is the second character o/w the first
## Note the comparison returns 1 if true & 0 if false so can use that as the index to @_