-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25.sh
51 lines (44 loc) · 1.04 KB
/
25.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
mapfile -t blocs < <(awk -v RS= '{gsub(/\n/, " "); print}')
L=()
K=()
for bl in "${blocs[@]}"; do
IFS=' ' read -ra lines <<< "$bl"
if [[ ${lines[0]} == "#####" ]]; then
L+=("$bl")
elif [[ ${lines[-1]} == "#####" ]]; then
K+=("$bl")
fi
done
getschema() {
local block=("$@")
local -a schema
local res=()
for line in "${block[@]}"; do
for (( i = 0 ; i < 6 ; i++ )); do
[[ ${line:i:1} == "#" ]] && ((schema[$i]++))
done
done
for count in "${schema[@]}"; do
res+=($(( count - 1 )))
done
echo "${res[*]}"
}
res=0
for k in "${K[@]}"; do
IFS=' ' read -ra arrk <<< "$k"
schemak=($(getschema "${arrk[@]}"))
for l in "${L[@]}"; do
IFS=' ' read -ra arrl <<< "$l"
schemal=($(getschema "${arrl[@]}"))
ok=1
for (( i = 0 ; i < 5 ; i++ )); do
if (( schemak[i] + schemal[i] > 5 )); then
ok=0
break
fi
done
(( res += ok ))
done
done
echo "res/ $res"