File tree Expand file tree Collapse file tree 3 files changed +1042
-0
lines changed Expand file tree Collapse file tree 3 files changed +1042
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "math"
6
+ "os"
7
+ "slices"
8
+ "strconv"
9
+ "strings"
10
+ )
11
+
12
+ func main () {
13
+ filenames := []string {"testInput" , "input" }
14
+ for _ , fileName := range filenames {
15
+ fileContents , err := os .ReadFile (fileName )
16
+ if err != nil {
17
+ panic (err )
18
+ }
19
+ fmt .Println (fileName )
20
+ lines := strings .Split (string (fileContents ), "\n " )
21
+ list1 := make ([]int , len (lines ))
22
+ list2 := make ([]int , len (lines ))
23
+ for index , line := range lines {
24
+ split := strings .Fields (line )
25
+ list1 [index ], _ = strconv .Atoi (strings .Trim (split [0 ], " " ))
26
+ list2 [index ], _ = strconv .Atoi (strings .Trim (split [1 ], " " ))
27
+ }
28
+ slices .Sort (list1 )
29
+ slices .Sort (list2 )
30
+ var difference int = 0
31
+ for index , _ := range list1 {
32
+ difference += int (math .Abs (float64 (list1 [index ] - list2 [index ])))
33
+ }
34
+ println (difference )
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments