A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 3 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. anonymous
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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. anonymous
    • 3 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

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.