Day 5
This commit is contained in:
36
05/01.sh
Executable file
36
05/01.sh
Executable 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
|
||||
Reference in New Issue
Block a user