+ day 4, part 1

master
Dominika Liberda 2021-12-07 16:54:16 +01:00
parent 5ba8af548c
commit a8fe132730
1 changed files with 49 additions and 0 deletions

49
4_1.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
function check() {
input="$(sed -E 's/[0-9][0-9]*/N/g;s/ //g' <<< "$1")"
if [[ "$input" == *"XXXXX"* ]]; then
echo 'bingo'
return
fi
for i in {1..5}; do
if [[ -z "$(cut -c $i <<< "$input" | grep -v X)" ]]; then
echo 'bingo'
return
fi
done
}
function frok() {
local owo=$j
local x=0
for ((i=0; i<${#uwu[@]}; i++)); do
arr[$owo]=$(sed -E 's/ '"${uwu[$i]}"' / X /g;' <<< "${arr[$owo]}")
if [[ "$(check "${arr[$owo]}")" == "bingo" ]]; then
echo "[$owo] bingo! at $i"
for g in $(sed -E 's/X//g' <<< "${arr[$owo]}"); do
x=$((x+g))
done
echo "[$owo] x*: $((x*${uwu[$i]}))"
break
fi
done
}
arr=()
yarr=()
IFS=',' read -a uwu
read dummy # empty line
while read line; do
read line2
read line3
read line4
read line5
read dummy
arr+=(" ${line} "$'\n'" ${line2} "$'\n'" ${line3} "$'\n'" ${line4} "$'\n'" ${line5} "$'\n')
done
for ((j=0; j<${#arr[@]}; j++)); do
frok &
done
wait