|
@@ -48,6 +48,33 @@ func readFile(file *os.File) [2][]int {
|
|
return decks
|
|
return decks
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func play(decks [2][]int) []int {
|
|
|
|
+ for {
|
|
|
|
+ if len(decks[0]) == 0 || len(decks[1]) == 0 {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ player1Hand := decks[0][0]
|
|
|
|
+ decks[0] = decks[0][1:len(decks[0])]
|
|
|
|
+
|
|
|
|
+ player2Hand := decks[1][0]
|
|
|
|
+ decks[1] = decks[1][1:len(decks[1])]
|
|
|
|
+
|
|
|
|
+ if player1Hand > player2Hand {
|
|
|
|
+ decks[0] = append(decks[0], player1Hand)
|
|
|
|
+ decks[0] = append(decks[0], player2Hand)
|
|
|
|
+ } else {
|
|
|
|
+ decks[1] = append(decks[1], player2Hand)
|
|
|
|
+ decks[1] = append(decks[1], player1Hand)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(decks[0]) == 0 {
|
|
|
|
+ return decks[1]
|
|
|
|
+ }
|
|
|
|
+ return decks[0]
|
|
|
|
+}
|
|
|
|
+
|
|
func main() {
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
if len(os.Args) < 2 {
|
|
log.Fatal("You need to specify a file!")
|
|
log.Fatal("You need to specify a file!")
|
|
@@ -65,5 +92,5 @@ func main() {
|
|
log.Fatalf("Failed to close file: %s", err)
|
|
log.Fatalf("Failed to close file: %s", err)
|
|
}
|
|
}
|
|
|
|
|
|
- fmt.Println(decks)
|
|
|
|
|
|
+ fmt.Println(play(decks))
|
|
}
|
|
}
|