Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

AppylPye

  • 2 years ago

Exercise 2.6 – The game of Nims/Stones Here's a solution, but it departs from the "basic outline" prescribed in the 6.189 Homework 2 handout by handling both players in a single loop. When I tried to use two separate loops, it got messy because there was a lot of duplication of code, including watching for the end game condition, ready to terminate execution from either loop after all the stones had been taken. Does anyone have a solution that uses two loops without a lot of repetition of code? http://ideone.com/kLQ5Zf The solution is written for Python 3..

  • This Question is Closed
  1. cb12
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    I think that if you are going to use a loop for each player, you are going to repeat code. However, I think that it can still be easy to read (though I know I should have commented my solution). You can view my Python 2.7 solution here: http://pastebin.com/sW0SrkdL. I had another version where I used a function to handle the players' turns, but I can't find it.

  2. AppylPye
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks. If you find your other version, please post that one here as well. It would be interesting to look at the variety of solutions that people have developed.

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy