Logic Problem Set 2

Part 1 - Raptor Programs

Logic.4 Caught Speeding

You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an no ticket=0, small ticket=1, big ticket=2. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday -- on that day, your speed can be 5 higher in all cases.

your raptor program should take the speed input and birthday input (0 - Not Birthday, 1 - Birthday), compute based on the rules given above and display the output as "No Ticket", "Small Ticket" or "Big Ticket". Add 5 more test cases that will test your program.

Test Case
Speed Input
Birthday Input
Program Output
1 60 0 No ticket
2 65 0 Small ticket
3 65 1 No ticket

Solutions:

python

raptor

Logic.5 Sort a Sum

Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20. sortaSum(3, 4) . 7 sortaSum(9, 4) . 20 sortaSum(10, 11) . 21. Add 5 more test cases.

Test Case
Int 1
Int 2
Program Output
1 3 4 7
2 9 4 20
3 10 11 21

Solutions:

python

raptor

Logic.6 Alarm Clock

Given a day of the week, with Sun=0, Mon=1, Tue=2, ...Sat=6, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off". alarmClock(1, false) . "7:00" alarmClock(5, false) . "7:00" alarmClock(0, false) . "10:00". Add 5 more test cases.

Test Case
Day of Week
Vacation
Program Output
1 1 0 7:00
2 5 0 7:00
3 0 0 10:00

Solutions:

python

raptor