|
@@ -28,6 +28,30 @@ func readInput(file *os.File) [][]byte {
|
|
|
return platform
|
|
|
}
|
|
|
|
|
|
+func tiltNorth(platform [][]byte) [][]byte {
|
|
|
+ newPlatform := [][]byte{platform[0]}
|
|
|
+ height := len(platform)
|
|
|
+ for i := 1; i < height; i++ {
|
|
|
+ newPlatform = append(newPlatform, platform[i])
|
|
|
+ for x := range newPlatform[i] {
|
|
|
+ if newPlatform[i][x] == 'O' {
|
|
|
+ y := i - 1
|
|
|
+ for {
|
|
|
+ if y < 0 || newPlatform[y][x] == '#' || newPlatform[y][x] == 'O' {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ newPlatform[y+1][x] = '.'
|
|
|
+ newPlatform[y][x] = 'O'
|
|
|
+ y--
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return newPlatform
|
|
|
+}
|
|
|
+
|
|
|
func main() {
|
|
|
if len(os.Args) < 2 {
|
|
|
log.Fatal("You need to specify a file!")
|
|
@@ -41,5 +65,5 @@ func main() {
|
|
|
}
|
|
|
|
|
|
platform := readInput(file)
|
|
|
- fmt.Println(platform)
|
|
|
+ fmt.Println(tiltNorth(platform))
|
|
|
}
|