aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2021-03-30 07:38:34 +0000
committerNiels van Dijke <perlboy@cpan.org>2021-03-30 07:38:34 +0000
commitdbf779fa4833385f8ce465e1570a3af453978efe (patch)
tree8777f2b8918240b90b1373553ca6b753d30ff0f4
parentcc1ad499d4475bcdaada9bd86bf641ba3ff9e633 (diff)
downloadperlweeklychallenge-club-dbf779fa4833385f8ce465e1570a3af453978efe.tar.gz
perlweeklychallenge-club-dbf779fa4833385f8ce465e1570a3af453978efe.tar.bz2
perlweeklychallenge-club-dbf779fa4833385f8ce465e1570a3af453978efe.zip
Update to task 2. Small bugfix and removal of dead code
-rwxr-xr-xchallenge-106/perlboy1967/perl/ch-2.pl14
1 files changed, 7 insertions, 7 deletions
diff --git a/challenge-106/perlboy1967/perl/ch-2.pl b/challenge-106/perlboy1967/perl/ch-2.pl
index b8f71d2a6c..45a9fc8c50 100755
--- a/challenge-106/perlboy1967/perl/ch-2.pl
+++ b/challenge-106/perlboy1967/perl/ch-2.pl
@@ -22,7 +22,7 @@ die "\$N must be smaller than \$D ($D, $N)"
unless ($N < $D);
printf "Input: \$N = %d, \$D = %d\n", $N, $D;
-printf "Output: %s\n", decimalString($N, $D);
+printf "Output: %d/%d = %s\n", $N, $D, decimalString($N, $D);
sub decimalString {
@@ -40,15 +40,15 @@ sub decimalString {
do {
$n = $r;
- while ($n < $d and int($n/$d) < 1) {
+ while ($n < $d) {
$n .= '0';
- $result .= '0' if (int($n/$d) < 1);
+ $result .= '0' if ($n < $d);
}
push(@{$rSeen{$n}}, length($result));
$result .= int($n/$d)
- unless (scalar(@{$rSeen{$n}}) > 1);
+ if (scalar(@{$rSeen{$n}}) < 2);
$r = $n % $d;
@@ -57,9 +57,9 @@ sub decimalString {
# Non repetitative division?
return "0.$result" if ($r == 0);
- if ($result =~ m#0$#) {
- $rSeen{$n}[0]--;
- $rSeen{$n}[1]--;
+ if ($result =~ m#([0]+)$#) {
+ $rSeen{$n}[0] -= length($1);
+ $rSeen{$n}[1] -= length($1);
}
return sprintf('0.%s(%s)',