
CMSI 182
IN T R O D U C T I O N T O CO M P U T E R SC I E N C E
Fall 2007
Assignment 1108
Alright, time to get our hands dirty with specifying algorithms.
Not for Submission
Read Chapter 5 in the Brookshear book.
For Submission
Specify the following algorithms using pseudocode:
1. The algorithm for converting any number from
0 to 255 into 8-bit binary. This algorithm can
be thought of as:
convertTo8Bit(number)
…where number is the number to be converted,
and the result is that number’s corresponding
8-bit binary representation.
Make sure that the algorithm detects whether
number is within range in the first place (i.e.,
number should range from 0 to 255).
2. An algorithm for “simulating” the three-door
puzzle discussed in class today. The algorithm
can be thought of in this way:
simulateDoorGame(trialCount, switchDoors)
…where trialCount is the number of times that
the game is to be played, and switchDoors indi-
cates whether or not this simulation should
switch doors or not. The result of the algo-
rithm is the number of times that the “player”
chose the winning door.
Submit the pseudocode on hardcopy. Make sure to
format your pseudocode with the right indents so
that structures such as conditionals and repetitions
are easy to see.
Extra Credit
You will receive extra credit if you do next week’s
assignment in advance: convert your pseudocode
into a JavaScript function that can be run using the
JavaScript scratch page on the course Web site.