From 82bfe670984001f60cd499a76d3249bbe8f43605 Mon Sep 17 00:00:00 2001 From: James Smith Date: Tue, 29 Nov 2022 12:43:03 +0000 Subject: Update ch-2.pl --- challenge-193/james-smith/perl/ch-2.pl | 9 +++------ 1 file 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 @_ -- cgit