Skip to content

Commit 7d0c52c

Browse files
committed
Shellcheck fixes and minor cleanup
Avoid sed when tr can do the job Ignore folders for previous years
1 parent 82ad1a7 commit 7d0c52c

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.txt*
1+
./*.txt*
2+
201*/

02.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ IFS=$'-:\ \n'
44
while read -r m M b c; do x=${c//[^$b]}; (( ${#x} >= m && ${#x} <= M && ++ans)); done < "${1:-2.txt}"
55
echo "2A: $ans"
66
ans=0
7-
while read m M b c; do x=${c:m-1:1}; y=${c:M-1:1}; [[ $x != $y ]] && [[ $b == $x || $b == $y ]] && ((++ans)); done < ${1:-2.txt}
7+
while read -r m M b c; do x=${c:m-1:1}; y=${c:M-1:1}; [[ $x != "$y" ]] && [[ $b == "$x" || $b == "$y" ]] && ((++ans)); done < "${1:-2.txt}"
88
echo "2B: $ans"

06.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#! /usr/bin/env bash
22
X=abcdefghijklmnopqrstuvwxyz; x=$X; a=0
3-
A=($(sed s/^$/X/ "${1:-6.txt}"))
4-
A+=(X)
3+
A=($(sed s/^$/X/ "${1:-6.txt}") X)
54
while read -r -n1 i; do
65
[ "$i" = X ] && { ((a+=26-${#x})); x=$X; }
76
x=${x/$i}

11.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ while [ ${#I} != 0 ]; do
1818
C[i]=.$l.; l=
1919
done
2020
B=("${C[@]}")
21-
I=${!CHANGE[@]}
21+
I=${!CHANGE[*]}
2222
((++round==1)) && B=("${C[@]//X/x}")
2323
#((round%10)) || echo "$round: ${#CHANGE[@]}"
2424
done
@@ -30,9 +30,9 @@ B=(L${A//?/L}L); for i in "${A[@]}"; do B+=(L${i}L); done; B+=($B)
3030
J=$(seq ${#A}); I=$(seq ${#A[@]}); change=1; round=0
3131
while [ ${#change} != 0 ]; do
3232
change=""; C=($B); l=""
33-
for i in $I; do # shellcheck disable=SC2034
33+
for i in $I; do
3434
for j in $J; do
35-
x=${B[i]:j:1}
35+
x=${B[i]:$j:1}
3636
[[ "$x" != "L" && "$x" != "X" ]] && l+=$x && continue
3737
r=${B[i]:j+1}; r=${r//.}; R=${B[i]:0:j}; R=${R//.}
3838
s=${R: -1}${r:0:1}

13.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env bash
22
IFS=$',\n'
33
input=${1:-13.txt}
4-
A=($(sed s/x,//g "$input"))
4+
A=($(tr -ds 'x' ',' < "$input"))
55
time=$A; min=($A 0)
66
for i in "${A[@]:1}"; do
77
w=$((i-time%i))

21.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ IFS=$' \n' input=${1:-21.txt}
33
A=($(grep -o "contains.*" "$input" | grep -o "[a-z]*" | grep -v contains| sort | uniq -c))
44
i=0;
55
while read -r a b; do
6-
C[i++]=$(grep -w "$b" "$input" | grep -o ".*(" | grep -o "[a-z]*" | sort | uniq -c | grep -w "$a" | sed "s/[0-9 ]*//" | tr '\n' ' ')
6+
C[i++]=$(grep -w "$b" "$input" | grep -o ".*(" | grep -o "[a-z]*" | sort | uniq -c | grep -w "$a" | tr -ds '0-9\n' ' ')
77
done < <(printf "%s %s\n" "${A[@]}")
88

99
space="^[[:space:]]+$"

0 commit comments

Comments
 (0)