assign1soln

# assign1soln - ensure switch is still set A1 ‐ A3 move...

This preview shows pages 1–2. Sign up to view the full content.

ECOR 1606 Winter 2010 Assignment #1 Sample Solution Question 1 while there are cars in the siding that need to join the train do if engine attached to main train then decouple engine from train ensure switch is set A1 A2 move engine past switch set switch A1 A3 reverse engine into siding and connect to siding cars endif decouple the “siding train” after the last car that is to join the train ensure switch is still set A1 A3 move engine forward until entire “siding train” past switch set switch A1 A2 reverse “siding train” until it joins the rest of the train if there are cars in the train that are not joining the train then decouple the train before the last car that is not joining the train ensure switch is still set A1 A2 move engine and new “siding train” forward past switch set switch A1 A3 reverse “siding train” into siding endif endwhile if engine still in siding then decouple engine from “siding train”

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ensure switch is still set A1 ‐ A3 move engine forward past switch set switch A1 ‐ A2 reverse engine back to join train endif Question 2 answer gets 1 if N < 0 then negative gets 1 N gets ‐ N else negative gets 0 endif while N>0 do answer gets answer * 2 N gets N ‐ 1 endwhile if negative=1 then answer = 1/answer endif answer contains 2 N Question 3 Assume a table top where CD's can be temporarily placed. while the box is not empty do if the CD at the top of the box is a bargain CD then move CD from top of box to bargain bin else move CD from top of box to table top while table top is not empty do if the leftmost slot is empty then move CD from table top to leftmost slot e l s e if the CD to the left of the leftmost empty slot > CD on table top then m o v e C D t o t h e l e f t o f t h e leftmost empty slot one slot right e l s e move CD on table top to the leftmost empty slot e n d i f e n d i f endwhile endif endwhile...
View Full Document

## This note was uploaded on 02/28/2011 for the course MATH 101 taught by Professor Duke during the Spring '11 term at University of Ottawa.

### Page1 / 2

assign1soln - ensure switch is still set A1 ‐ A3 move...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online