diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-11-01 04:20:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-01 04:20:50 +0000 |
| commit | 85baf0312cde33873bb3cde82fda8dcdfbaf9c93 (patch) | |
| tree | 8642a65c1b12b4b815ac0e735f1ca0ce36c7b13d | |
| parent | 3e5f9a174a282ba8dd79f05257f59c53b6410cc4 (diff) | |
| parent | 91cf947a399bb8691f170bffb6e2b6004c144d66 (diff) | |
| download | perlweeklychallenge-club-85baf0312cde33873bb3cde82fda8dcdfbaf9c93.tar.gz perlweeklychallenge-club-85baf0312cde33873bb3cde82fda8dcdfbaf9c93.tar.bz2 perlweeklychallenge-club-85baf0312cde33873bb3cde82fda8dcdfbaf9c93.zip | |
Merge pull request #2670 from jeongoon/master
[ch-084/jeongoon] ch-1.pl bug fixed again; ch-2.pl tidy a bit
| -rw-r--r-- | challenge-084/jeongoon/perl/ch-1.pl | 26 | ||||
| -rw-r--r-- | challenge-084/jeongoon/perl/ch-2.pl | 21 |
2 files changed, 27 insertions, 20 deletions
diff --git a/challenge-084/jeongoon/perl/ch-1.pl b/challenge-084/jeongoon/perl/ch-1.pl index 90d0d765d2..f8b69239ac 100644 --- a/challenge-084/jeongoon/perl/ch-1.pl +++ b/challenge-084/jeongoon/perl/ch-1.pl @@ -18,18 +18,25 @@ sub filter32Bit ($$;$) { $lim_abs ||= limitAbs( $s, $n ); my $n_with_sigin = $s . $n; - ( (bless \$n_with_sigin, (($n le $lim_abs) ? Ok : Invalid )), # 0 # eq - (bless \$n_with_sigin, Invalid), # 1 # gt - (bless \$n_with_sigin, Ok), # -1 # lt - )[ (length $n) <=> (length $lim_abs) ] + map { + if ( $_ == 0 ) { # eq + bless \$n_with_sigin, (($n le $lim_abs) ? Ok : Invalid) + } + elsif ( $_ == 1 ) { # gt + bless \$n_with_sigin, Invalid + } + else { # lt + bless \$n_with_sigin, Ok + } + } ((length $n) <=> (length $lim_abs)); } sub limitAbs ($$;$) { # $bit is optional my ( $s, $n, $bit ) = @_; $bit ||= 31; - abs # abs() for sure because if using 32bit variable, - (1 << $bit) # that calculation is overflowed already - - ( $s ne '-' ) + abs( -abs # ensure negative value because if variable size is limited, + (1 << $bit) # -> this calculation is overflowed already + + ($s ne '-') ) # make (-) value andthen convert it into (+) } sub reverseIntStr ($) { @@ -53,13 +60,14 @@ say "Sign: (@{[(($sign) ||= '+')]})"; # like: Sign: (+) say "Value: ".$number; my $lim_abs = limitAbs( $sign, $number ); -my $result = filter32Bit( $sign, $number ); +say "Limt: ".$lim_abs; +my ($result) = filter32Bit( $sign, $number, $lim_abs ); if ((ref $result) eq Ok) { say "Reversed: " . $$result; } else { say "Reversed: " . $$result; - say "However limit value: " . ($sign < 0 ? '-' : ' ').$lim_abs; + say "However limit value: " . ($sign eq '-' ? '-' : ' ').$lim_abs; say "Therefore: " . (ref $result); } diff --git a/challenge-084/jeongoon/perl/ch-2.pl b/challenge-084/jeongoon/perl/ch-2.pl index 393094710a..6cfead0dc3 100644 --- a/challenge-084/jeongoon/perl/ch-2.pl +++ b/challenge-084/jeongoon/perl/ch-2.pl @@ -69,9 +69,9 @@ sub showSomethingInGroup ($$$) { } sub showPoints ($) { - @_ = ( $_[0], ShowDetails - ->new( name => 'points', - attrs => [qw(row col)] ), + @_ = ( $_[0], # data (ArrayRef) + ShowDetails->new( name => 'points', + attrs => [qw(row col)] ), 1 # flattening? yes ); goto &showSomethingInGroup @@ -91,9 +91,9 @@ sub getHorizLinesFromPoints ($) { } sub showHorizLines ($) { - @_ = ( $_[0], ShowDetails - ->new( name => 'horiz lines', - attrs => [qw(row begin end)] ), + @_ = ( $_[0], + ShowDetails->new( name => 'horiz lines', + attrs => [qw(row begin end)] ), 1 # flattening? yes ); goto &showSomethingInGroup @@ -134,14 +134,13 @@ sub getSquaresFromHlines ($) { } } 0 .. $#{$hls_r2} } 0 .. $#{$hls_r1} - } combiIndex2( scalar @hls_at_all_rows ) ] + } combiIndex2( scalar @hls_at_all_rows ) ] # return as ArrayRef } sub showSquares ($) { - @_ = ( $_[0], ShowDetails - ->new( name => 'square', - attrs => - [ qw(row_NW col_NW row_SE col_SE) ] ), + @_ = ( $_[0], + ShowDetails->new( name => 'square', + attrs => [ qw(row_NW col_NW row_SE col_SE) ] ), 0 # flattening? no ); goto &showSomethingInGroup |
