From 92d41f92a59d5ebad74d12edec19e86ad1d53aed Mon Sep 17 00:00:00 2001 From: Alexander Pankoff Date: Tue, 8 Dec 2020 14:11:00 +0100 Subject: add verbose mode --- challenge-090/alexander-pankoff/perl/ch-2.pl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/challenge-090/alexander-pankoff/perl/ch-2.pl b/challenge-090/alexander-pankoff/perl/ch-2.pl index eb588779f8..a66c4feea7 100755 --- a/challenge-090/alexander-pankoff/perl/ch-2.pl +++ b/challenge-090/alexander-pankoff/perl/ch-2.pl @@ -10,6 +10,8 @@ use List::Util qw(sum0); use Test::Simple tests => 20; +use constant VERBOSE => $ENV{VERBOSE} // 0; + { for ( 0 .. 19 ) { my ( $a, $b ) = map { int( rand( 1000 ) ) + 1 } 0 .. 1; @@ -19,7 +21,16 @@ use Test::Simple tests => 20; } sub ethopian_mul ( $a, $b ) { - return sum0( map { $_->[1] } grep { odd( $_->[0] ) } ethopian_mul_chain( $a, $b ) ); + my @chain = ethopian_mul_chain( $a, $b ); + verbose( "halving $a, doubling $b, till $a becomes 1" ); + verbose( $_->[0] . ' & ' . $_->[1] ) for @chain; + + my @filtered = map { $_->[1] } grep { odd( $_->[0] ) } @chain; + verbose( "taking right values where left value is odd" ); + verbose( $_ ) for @filtered; + my $product = sum0( @filtered ); + verbose( "product is $product" ); + return $product; } sub ethopian_mul_chain ( $a, $b ) { -- cgit