2003 Canadian Computing Competition, Stage 1

Problem J3/S1: Snakes and Ladders

Here (see illustration) is a game board for the game Snakes and Ladders. Each player throws a pair 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 cannot advance the number of squares indicated by the dice, the piece is 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, of course, runs on your handheld computer. 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 where 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 between 2 and 12) and report the number of the square where the piece lands. In addition, if the piece moves to the last square, the program should print "You Win!" and terminate. If the user enters 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 pictured above and you should note that the board has 3 snakes (from 54 to 19, from 90 to 48 and from 99 to 77) and 3 ladders (from 9 to 34, from 40 to 64 and from 67 to 86).

Sample Input


Sample Output

You are now on square 10
You are now on square 21
You are now on square 33
You are now on square 64
You are now on square 86
You are now on square 91
You are now on square 91
You are now on square 100
You Win!

All Submissions
Best Solutions

Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 27, 2008

Problem Types: [Show]

Languages Allowed:

Comments (Search)

If the number goes past the last square, what do we do?

it says in the problem statement, please read carefully.

Can anyone tell me what I'm doing wrong. Thanks.

Write some test cases by hand, figure out where it should be, and go from there.

what's wrong with my code.

I am getting a runtime error using Python 2.

On my machine, the code runs perfectly. I have verified that all the ladders/snakes work as expected, and all the conditions are met. Could anyone have a look?

For some reason beyond my comprehension, the judge doesn't support the .format() method, even though it was introduced in 2.6...

2.6 introduced format using field names and positional specifiers, e.g. "abc {0} 123".

Changed in version 2.7: The positional argument specifiers can be omitted, so '{} {}' is equivalent to '{0} {1}'.

Getting WA for first test case. Can someone please check my code?


Your code fails on the sample input.

I will personally not respond to any future help requests if I determine you haven't done sufficient testing on your own. (This doesn't mean to just run it on the sample; it also means to write your own test cases with input and expected output, and check that your code works properly.)

Ohh overlooked that statement. Such a silly mistake.
Sorry for the trouble jargon.
Will be more careful.


It cannot because you can only move to 100.

"If the piece cannot advance the number of squares indicated by the dice, the piece is not moved at all."

Why am I getting the second test case wrong???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

Your error is actually just a typo. Look through your code again carefully. Try crafting a few small test cases. In particular, you should test that your program works for each ladder and snake.