34 lines
628 B
Bash
Executable File
34 lines
628 B
Bash
Executable File
#!/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 -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
|