# Writing a Nim game in ruby

**URL:** <https://www.ruby-forum.com/t/writing-a-nim-game-in-ruby/196048>\
**Category:** Ruby\
**Created:** [October 6, 2010, 12:11am UTC](https://www.ruby-forum.com/t/writing-a-nim-game-in-ruby/196048 "2010-10-06T00:11:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingkuan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kingkuan](https://www.ruby-forum.com/u/kingkuan)\
**Post date:** [October 6, 2010, 12:11am UTC](https://www.ruby-forum.com/t/writing-a-nim-game-in-ruby/196048/1 "2010-10-06T00:11:23Z")

</div>

wondering does anyone know how to help with this problem

n and t should be constants in your program, but give them better names  
like INITIAL\_NUM\_MATCHES and MAX\_ALLOWED\_TO\_TAKE. You may assume that  
the user plays first and the computer second, and so on.

When n=k\*(t+1)+1, for some constant k, your program should always win.  
When this is not the case, your program should take a random number of  
matches from the pile. If the user makes an error on their turn, your  
program should play correctly and win the game.

Your program should have a class called Nim that manages the game  
itself. Your main program can manage user input, or you can put this  
into another class if you wish.

A good approach to this assignment is to assume that the initial number  
of matches is 21 (n=21) and that the maximum number of matches that may  
be taken on a turn is 4 (t=4). When you have this problem solved and you  
are satisfied your program is correct, extend your program to handle the  
more general case where n and t can have other values.

---

<div class="post-metadata">

**Author:** ![kingkuan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kingkuan](https://www.ruby-forum.com/u/kingkuan)\
**Post date:** [October 6, 2010, 12:20am UTC](https://www.ruby-forum.com/t/writing-a-nim-game-in-ruby/196048/2 "2010-10-06T00:20:06Z")

</div>

Uhh, what kind of help are you looking for? Or did you just want  
someone to do your homework for you?

Sorry for the snark, but it’s true - you’re not going to learn Ruby if  
you just ask other people to do it for you.

---

<div class="post-metadata">

**Author:** ![kingkuan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@kingkuan](https://www.ruby-forum.com/u/kingkuan)\
**Post date:** [October 6, 2010, 9:49am UTC](https://www.ruby-forum.com/t/writing-a-nim-game-in-ruby/196048/3 "2010-10-06T09:49:33Z")

</div>

Very true sir but I was short on time and if someone had already done it  
would have saved me the effort. Hence it would have helped me.
