This commit is contained in:
2021-12-05 13:11:44 +01:00
parent 584ee7021b
commit c03cb5a03e
2 changed files with 69 additions and 0 deletions

36
05/01.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
points=()
while read line; do
x1=$(sed 's/,.*$//' <<< $line)
y1=$(sed 's/^.*,\(.*\) ->.*$/\1/' <<< $line)
x2=$(sed 's/^.*-> \(.*\),.*$/\1/' <<< $line)
y2=$(sed 's/^.*,.*,//' <<< $line)
if [ $x1 -ne $x2 ] && [ $y1 -ne $y2 ]; then
continue
fi
if [ $x1 -eq $x2 ]; then
x_inc=0
elif [ $x1 -gt $x2 ]; then
x_inc=-1
else
x_inc=1
fi
if [ $y1 -eq $y2 ]; then
y_inc=0
elif [ $y1 -gt $y2 ]; then
y_inc=-1
else
y_inc=1
fi
i=$x1
j=$y1
while [ $i -ne $x2 ] || [ $j -ne $y2 ]; do
points+=( "$i,$j" )
i=$((i+x_inc))
j=$((j+y_inc))
done
points+=( "$i,$j" )
done
printf '%s\n' "${points[@]}" | sort | uniq -d | wc -l