PPAU3LBGISEACFGJHQDYQXZUFFLMMQSPYWBG6MTR6WPUKS4L6SWQC package mainimport ("testing""github.com/stretchr/testify/assert")func TestHorseDual(t *testing.T) {cases := []struct {horses intpower []intexpected int}{{3, []int{5, 8, 9}, 1},{10, []int{5, 15, 17, 3, 8, 11, 28, 6, 55, 7}, 1},}for _, tc := range cases {t.Run("", func(t *testing.T) {assert.Equal(t, tc.expected, HorseDuals(tc.horses, tc.power))})}}
package mainimport ("fmt")func main() {var horses intfmt.Println("How many horse are in the race?")fmt.Scan(&horses)power := make([]int, horses)for i := 0; i < horses; i++ {fmt.Printf("Horse[%d] power: ", i)fmt.Scan(&power[i])}fmt.Println(HorseDuals(horses, power))}func HorseDuals(lovak int, loero []int) (szoros int) {szoros = Abs(loero[0] - loero[1])for key, value := range loero {for i := key + 1; i < lovak; i++ {if Abs(value-loero[i]) < szoros {szoros = Abs(value - loero[i])}}}return}func Abs(x int) int {if x < 0 {return -x}return x}
# Horse-racing DualsCasablanca’s hippodrome is organizing a new type of horse racing:duals. During a dual, only two horses will participate in the race. Inorder for the race to be interesting, it is necessary to try to selecttwo horses with similar strength.Write a program which, using a given number of strengths, identifies thetwo closest strengths and shows their difference with an integer (≥ 0).## InputLine 1: Number N of horsesThe N following lines: the strength P[i] of each horse. P[i] is an integer.##OutputThe difference D between the two closest strengths. D is an integer greater than or equal to 0.##Constraints1 < N < 1000000 < P[i] ≤ 10000000