Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

exchaoordo

Is anyone interested in posting their code for Exercise 2.6, the NIMS game? I have mine working but I thought it would be nice to see others.

  • one year ago
  • one year ago

  • This Question is Closed
  1. exchaoordo
    Best Response
    You've already chosen the best response.
    Medals 0

    Of course another quirk in OS is I can't attach a file to a question, but I can to a comment, hence:

    • one year ago
    1 Attachment
  2. andrew.m.higgs
    Best Response
    You've already chosen the best response.
    Medals 2

    Yours looks more elegant than mine. :-) I also went on step further and wrap parts in functions and made it that more than two players could play. But that was just for fun.

    • one year ago
    1 Attachment
  3. exchaoordo
    Best Response
    You've already chosen the best response.
    Medals 0

    Yours is much more robust than mine. And you've used booleans and min, so kudos to you.Thanks for posting.-dan

    • one year ago
  4. andrew.m.higgs
    Best Response
    You've already chosen the best response.
    Medals 2

    Pleasure. I believe we learn the most by comparing. That is what makes open source so wonderful. I am going to study your cod because i like the way you worked through the problem.

    • one year ago
  5. exchaoordo
    Best Response
    You've already chosen the best response.
    Medals 0

    Study my cod just for the halibut ;-)

    • one year ago
  6. andrew.m.higgs
    Best Response
    You've already chosen the best response.
    Medals 2

    :-) See, peer review works...

    • one year ago
  7. Screech
    Best Response
    You've already chosen the best response.
    Medals 0

    Since there is nearly identical code handling each player, I combined them and set a variable to denote the current player.

    • one year ago
  8. andrew.m.higgs
    Best Response
    You've already chosen the best response.
    Medals 2

    What I did as an added bit of work was to create a function called make_move and made it that more then 2 players could play at once.

    • one year ago
  9. FabienToune
    Best Response
    You've already chosen the best response.
    Medals 0

    I tried it with recursion and tried to avoir any exception during game... seems to work fine

    • one year ago
    1 Attachment
  10. andrew.m.higgs
    Best Response
    You've already chosen the best response.
    Medals 2

    Hi Fabien, I like your code. Very neat indeed. Only problem is that stack can go negative which means you will never end the game, in certain circumstances. :-)

    • one year ago
  11. FabienToune
    Best Response
    You've already chosen the best response.
    Medals 0

    Made a mistake in my while test... forgot to convert choice to integer and flipped the comparator... Like, I think the problem shouldn't happen again...

    • one year ago
    1 Attachment
  12. dsabalete
    Best Response
    You've already chosen the best response.
    Medals 0

    I like the recursive solution from FabienTourne. Anyway, here is mine:

    • one year ago
    1 Attachment
  13. mmailliw
    Best Response
    You've already chosen the best response.
    Medals 0

    I'll post the function I used to make the English grammatically correct (with regards to singular vs plural): def plural(counter, word): if word == "stones": if counter == 1: return "stone" else: return "stones" elif word == "are": if counter == 1: return "is" else: return "are" elif word == "remain": if counter == 1: return "remains" else: return "remain" else: return None

    • one year ago
    • Attachments:

See more questions >>>

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...

23

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