Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- read N
- touch list # create file named list
- for (( i=0; i<N; i++ )); do
- read Pi # store in Pi
- echo $Pi >> list # append to file list
- done
- sort -n list > sorted # sort file list and create file sorted
- minimum=99999999
- distance=0
- previous=0
- first=$(head -n 1 sorted) # first horse from sorted
- for i in $(cat sorted); do # iterate through lines from sorted
- if [ $i != $first ]; then
- let "distance=i-previous" # calculate distance
- # Since list is sorted i know that distance is always >= 0
- if [ $distance -lt $minimum ]; then
- let "minimum=distance" # store minimal distance
- fi
- let "previous=i" # current i horse becomes previous
- else
- let "previous=i" # first horse becomes previous
- fi
- done
- echo "$minimum" # print minimum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement