aboutsummaryrefslogtreecommitdiff
path: root/challenge-097/abigail/bash
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-30 17:01:45 +0100
committerAbigail <abigail@abigail.be>2021-01-30 17:51:27 +0100
commit7de0601266583815c0bfb3f00cb71672997b19c3 (patch)
tree46c1abc7925da4426abd93df53ae01feca60d531 /challenge-097/abigail/bash
parent19e332207808276edd1ed1bebd3e907136acc438 (diff)
downloadperlweeklychallenge-club-7de0601266583815c0bfb3f00cb71672997b19c3.tar.gz
perlweeklychallenge-club-7de0601266583815c0bfb3f00cb71672997b19c3.tar.bz2
perlweeklychallenge-club-7de0601266583815c0bfb3f00cb71672997b19c3.zip
Swap the role of sections and section length (size).
We initially implemented the algorithm where the number of sections is passed in as a parameter. However, it's not the number of sections, it's the length of each section. This was an easy fix, as the algorithm is pretty symmetric.
Diffstat (limited to 'challenge-097/abigail/bash')
-rw-r--r--challenge-097/abigail/bash/ch-2.sh10
1 files changed, 5 insertions, 5 deletions
diff --git a/challenge-097/abigail/bash/ch-2.sh b/challenge-097/abigail/bash/ch-2.sh
index ad82b5ecab..4ea37b5911 100644
--- a/challenge-097/abigail/bash/ch-2.sh
+++ b/challenge-097/abigail/bash/ch-2.sh
@@ -5,7 +5,7 @@
#
#
-# Run as: bash ch-2.sh -s SECTIONS < input-file
+# Run as: bash ch-2.sh -s SIZE < input-file
#
#
@@ -18,7 +18,7 @@ set -f
#
while getopts "s:" name
do if [ "$name" = "s" ]
- then sections=$OPTARG
+ then size=$OPTARG
fi
done
@@ -28,12 +28,12 @@ done
# and calculate the number of 1s. Sum the minimum of those numbers.
#
while read line
-do s_len=$((${#line} / $sections))
+do sections=$((${#line} / $size))
sum=0
- for ((i = 0; i < s_len; i ++))
+ for ((i = 0; i < size; i ++))
do zeros=0
for ((j = 0; j < sections; j ++))
- do index=$(($j * $s_len + $i))
+ do index=$(($j * $size + $i))
if [ "${line:$index:1}" == "0" ]
then zeros=$(($zeros + 1))
fi