diff options
| author | Abigail <abigail@abigail.be> | 2021-01-27 17:19:46 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-27 17:19:46 +0100 |
| commit | 05e966e5ff15df467f5bd7e354feb83894c56f8f (patch) | |
| tree | 45370fa097235f3cadc0e53cc864313d9f386f13 | |
| parent | 1cf50661eec1020927b95eeacd21c9f5ee650fc6 (diff) | |
| download | perlweeklychallenge-club-05e966e5ff15df467f5bd7e354feb83894c56f8f.tar.gz perlweeklychallenge-club-05e966e5ff15df467f5bd7e354feb83894c56f8f.tar.bz2 perlweeklychallenge-club-05e966e5ff15df467f5bd7e354feb83894c56f8f.zip | |
Make AWK solution more like the other solutions.
| -rw-r--r-- | challenge-097/abigail/awk/ch-2.awk | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/challenge-097/abigail/awk/ch-2.awk b/challenge-097/abigail/awk/ch-2.awk index f3d1ef2e89..892ca2bdc7 100644 --- a/challenge-097/abigail/awk/ch-2.awk +++ b/challenge-097/abigail/awk/ch-2.awk @@ -25,13 +25,13 @@ BEGIN { # Split the string into individual letters, use # indexing to get the ith letter of the jth section # - split ($0, letters, "") sum = 0 - l = length($0) / sections # Length of a section - for (i = 0; i < l; i ++) { + s_len = length ($0) / sections # Length of a section + for (i = 0; i < s_len; i ++) { zeros = 0; # Count the zeros on position i for (j = 0; j < sections; j ++) { - if (letters [j * l + i + 1] == "0") { + indx = j * s_len + i + 1 # Can't use 'index' as a variable + if (substr ($0, indx, 1) == "0") { zeros ++ } } |
