Author:  Tony [ Sat Mar 22, 2003 1:19 pm ]
Post subject:  CCC 2003 Stage1: S1J3: Snakes and Ladders

Each player throws a part of dice to determine how many squares his/her game piece will advance. If the piece lands on the bottom of a ladder, the piece moves up to the square at the top of the ladder. If the piece lands on the top of a snake, the piece "slides" down to the square at the bottom of the snake. If the piece lands on the last square, the player wins. If the piece cannon advance the number of squares indicated by the dice, the piece in not moved at all.

In order to help you play this game via a cell phone while travelling, you will write a program that simulates your moves on the board shown and, ofcourse, runs on your handheld computer. If you got a handheld computer, why are you playing in snakes&ladder via cellphone?! - Confused Tony You will repeatedly throw the dice and enter the result into the program. After each throw the program will report the number of the square wher your piece lands.

When the program starts it should assume the piece is on square 1. It should repeatedly read input from the user (a number meaning integer between 2 and 12) and report the number of the square where the peice lands. In addition, if the piece moves to the last square, the program should print "You Win!" and terminate. If the user enter 0 instead of a number between 2 and 12, the program should print "You Quit!" and terminate.

For clarity, you are to use the board pciture above and you should note that the board has 3 snakes (from 54 to 19, from 90 to 48, from 99 to 77) and 3 ladders (from 9 to 34, from 40 to 64 and from 67 to 86).

The board itself is 100 squares long, you win when you reach 100th square

Solution by JSBN
 code: var sum : int var loca : int := 1 loop     put "Enter sum of dice:"     get sum     if sum = 0 then         put "You Quit!"         quit     end if     if loca + sum > 100 then     else         loca := loca + sum     end if     if loca = 9 then         loca := 34     elsif loca = 40 then         loca := 64     elsif loca = 67 then         loca := 86     elsif loca = 99 then         loca := 77     elsif loca = 90 then         loca := 48     elsif loca = 54 then         loca := 19     end if     put "You are now on square ", loca     exit when loca = 100 end loop put "You Win!"

This is easier then both J1 and J2... what were they thinking?

 Author: Office of the Registar [ Fri Apr 25, 2003 9:08 am ] Post subject: ya that question was pretty easy

 Author: Andy [ Sat Jun 07, 2003 8:24 pm ] Post subject: i forgot to put you are on square 100 i just put you win damn, lost 1 mark, dropped me 4 places

 :