TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: All
from: Peter Shimmin
date: 1996-03-28 12:06:24
subject: Student desperate for help

Hello, I'm desperate for help.
I'm a first year uni student at Swinburne studying Information Technology.
One of the subjects I do is C programming. I have never done any programming
before and found that the pace that they are going through at uni is too
much for me to fully comprehend. I'm having trouble analysing this problem
I have been given and turing it into C code. A description of the problem
is below;
***
I am to write a program to play the well-known game of Nim. The game starts
with some number of stones in a pile. The players ( 2 players A (computer)
and B (you) ) take turns removing either one or two stones at each move.
The player who takes the last stone loses.

The program should use the following optimal strategy for Nim: take the
remainder on dividing the stones left by 3; this will be 0, 1 or 2. If it
is 0, then take 2 stones; if it is 2, take 1 stone. If the remainder is 1
then the game cannot be won, assuming the opponent is also playing the 
optimal strategy; however the program should delay the inevitable and take
one more stone ( perhaps the other player will make a mistake ).

The program should start by asking the user for the number of stones to play
with, and then asks who moves first (0=program, 1=user). It then runs in a 
loop, alternating turns between the program and the user. The program chooses
one or two stones according to the above strategy, and then asks  the user
how many stones she/he wishes to take. When the number of stones reaches zero
the program annonces the winner.

The program should check for errors:
initial number of stones must be greater than 0;
"who moves first" must be 0 or 1;
number of stones removed be user at each move must be one or two, and not 
more than the number remaining.
If an error is detected, the program should output an appropiate error 
message and repeat the input request. For this exercise, I was told it is
not necessary to check for non-numeric input, bu useful.***

Please, if anybody out there is willing to help, give advice or start me
on the right track I will be ever so grateful.

Cheers, Ben.

Replies to;
message area...or
peteshim{at}melbpc.org.au
twilight{at}bud.cc.swin.edu.au

... RAM = Rarely Adequate Memory  

---
* Origin: Melbourne PC User Group +61-3-9699-6788 (3:632/309)
SEEN-BY: 50/99 78/0 620/243 623/630 632/0 107 271 304 309 328 348 360 393 525
SEEN-BY: 632/530 552 998 999 1000 633/371 634/384 388 396 635/301 502 503 544
SEEN-BY: 637/103 639/252 670/301 711/401 409 410 413 430 808 809 932 934
SEEN-BY: 712/515 713/888 714/906 800/1 7877/2809
@PATH: 632/309 998 635/503 50/99 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.