turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Play Chutes and Ladders with me

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-30-2011 01:02 PM

Chutes and Ladders is a board game during which one or more players, moving alternately, move their tokens along the numbered spaces on the board according to the roll of a single six-sided die; the tokens are initially off-the-board at what is effectively space zero. Landing on a space with the bottom of a ladder promotes the token to the space at the top of said ladder. Landing on a space at the top of a chute demotes the token to the space at the bottom of the chute. The goal is to reach space 100, exactly; if the roll of the die would take the token past space 100, the token remains where it is and play passes to the next player.

1. What is the minimum number of rolls required to reach space 100?

2. For a single player, what is the average number of rolls required to reach space 100?

3. For *n* players, what is the average number of rolls until one of the players reaches space 100 and ends the game?

You can also do this for the predecessor of the chutes and ladder game called Vaikuntapaali or Paramapada Sopanam from India in the 16th century. It has the same basic rules however the total number of spaces and locations of the chutes/snakes and ladders are different.

SPOILER: Below is my obscured answer.... Don't cheat

%let games=10000; *number of gamesto play;

%let players=1; *number of playersplaying;

**data** transitions;

input from to @@;

cards;

1 38 4 14 9 31

16 6

21 42 28 84

36 44

47 26 49 11

51 67 56 53

62 19 64 60

71 91 80 100

87 24

93 73 95 75 98 78

;

**run**;

**data** _null_;

length from to game ps rolls roll tot avg **8**;

declare hash ha(dataset:'transitions');

ha.definekey('from');

ha.definedata(all:'y');

ha.definedone();

declare hash ga(ordered:'a');

ga.definekey('rolls','game');

ga.definedata('game','rolls');

ga.definedone();

do game=**1** to &games*&players;

ps=**0**; *present space;

rolls=**0**;

do until(ps=**100**);

roll=rand('table',**1**/**6**,**1**/**6**,**1**/**6**,**1**/**6**,**1**/**6**,**1**/**6**);

if ps+roll<=**100** then

do;

ps+roll;

if ha.find(keys)=**0** then ps=to;

end;

rolls+**1**;

end;

ga.add();

end;

declare hiter iter('ga');

tot=**0**;

iter.first();

put 'Shortest game:' game= rolls=;

do while(iter.next()=**0**);

tot+rolls;

end;

avg=tot/(&games*&players);

put 'Longest game:' game= rolls=;

put 'Average length:' avg=;

**run**;

I do not properly induce logic for calculating the results of games with multiple players, but logically it is not difficult to desern that generally as the number of players increases, the chance to beat the average game length increases and so the average length for more players should decrease relative to the average for a single player...

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to FriedEgg

12-02-2011 09:11 PM

I think your solution is missing something. When I execute it in 9.3, I get the following in my log:

NOTE: Variable from is uninitialized.

NOTE: Variable to is uninitialized.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to gfarkas

12-02-2011 09:42 PM

This is not a real issue. It is more of a by-product of how I chose to initialize my scalar elements for the hash object. It you wanted to remove these notes you could do either of the following:

data _null_;

length from to game ps rolls roll tot avg 8;

declare hash ha(dataset:'transitions');

ha.definekey('from');

ha.definedata(all:'y');

ha.definedone();

call missing(from,to); *this will inititaze the variables;

*now the rest of the original code;

data _null_;

if 0 the

do;

length from to game ps rolls roll tot avg 8;

set transitions; *this will initialize the variables;

end;

declare hash ha(dataset:'transitions');

ha.definekey('from');

ha.definedata(all:'y');

ha.definedone();

*now the rest of the original code;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to FriedEgg

12-05-2011 12:23 PM

Thanks for the reply. I'm definitely a novice when it comes to using the hash object, but what you wrote makes sense in general.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to gfarkas

12-05-2011 01:02 PM

No problem, it is why we are all here.