Files
advent-of-code-2022/day05/ex2/main.go
2022-12-05 10:36:49 +01:00

28 lines
521 B
Go

package main
import (
"bufio"
"fmt"
"os"
"aoc2022/day05/common"
)
func main() {
stacks, movements := common.Parse(*bufio.NewScanner(os.Stdin))
for _, movement := range(movements) {
top := []byte{}
for i := 0; i < movement.GetN(); i++ {
top = append(top, stacks[movement.GetStart() - 1].Pop())
}
for i := len(top) - 1; i >= 0; i-- {
stacks[movement.GetEnd() - 1].Push(top[i])
}
}
for _, stack := range(stacks) {
fmt.Print(string(stack.Peek()))
}
fmt.Println()
}