Selaa lähdekoodia

Added sorting

Piotr Czajkowski 1 vuosi sitten
vanhempi
commit
0368a2487f
1 muutettua tiedostoa jossa 9 lisäystä ja 0 poistoa
  1. 9 0
      18/code.go

+ 9 - 0
18/code.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"log"
 	"os"
+	"sort"
 	"strings"
 )
 
@@ -76,6 +77,14 @@ func plot(plan []Dig) []Point {
 		result = append(result, current.getPoints(plan[i])...)
 	}
 
+	sort.Slice(result, func(i, j int) bool {
+		if result[i].y == result[j].y {
+			return result[i].x < result[j].x
+		}
+
+		return result[i].y < result[j].y
+	})
+
 	return result
 }