File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ package main
3
3
import (
4
4
"bufio"
5
5
"fmt"
6
+ "math"
6
7
"os"
8
+ "sort"
7
9
"strconv"
8
10
"strings"
9
11
)
@@ -25,13 +27,25 @@ func main() {
25
27
line := scanner .Text ()
26
28
pair := strings .Split (line , " " )
27
29
p1 , _ := strconv .Atoi (pair [0 ])
28
- p2 , _ := strconv .Atoi (pair [1 ])
30
+ p2 , _ := strconv .Atoi (pair [3 ])
29
31
left = append (left , p1 )
30
- right = append (left , p2 )
32
+ right = append (right , p2 )
31
33
}
32
34
33
- fmt .Println (left )
34
- fmt .Println (right )
35
+ sort .Slice (left , func (i , j int ) bool { return left [i ] < left [j ] })
36
+ sort .Slice (right , func (i , j int ) bool { return right [i ] < right [j ] })
37
+
38
+ var diffs []float64
39
+ for i , val := range left {
40
+ diffs = append (diffs , math .Abs (float64 (val - right [i ])))
41
+ }
42
+
43
+ var sum float64 = 0
44
+ for _ , val := range diffs {
45
+ sum += val
46
+ }
47
+
48
+ fmt .Println (int (sum ))
35
49
36
50
if err := scanner .Err (); err != nil {
37
51
panic (err )
You can’t perform that action at this time.
0 commit comments