In the following set of challenges, you will use a trace table to workout the secret code of the following six padlocks. Before attempting this challenge, you may want to find out mode about the use of trace tables when testing or predicting the output of an algorithm.
Padlock #1Padlock #2Padlock #3Padlock #4Padlock #5Padlock #6
Padlock #1:
The following code will help you work out the combination (code) to open padlock #1 (see below)
code = "" FOR i FROM 1 TO 3 digit = i * 2 code = code + STR(digit) NEXT i OUTPUT(code)
Trace Table
Line Number | i | digit | code | OUTPUT | |
---|---|---|---|---|---|
1 | “” | ||||
2 | 1 | ||||
3 | 2 | ||||
4 | “2” | ||||
2 | 2 | ||||
3 | 4 | ||||
4 | “24” | ||||
2 | 3 | ||||
3 | 6 | ||||
4 | “246” | ||||
6 | 246 |
Padlock
Input the combination on the padlock below and click on “Unlock?” to test your combination.
Padlock #2:
The following code will help you work out the combination (code) to open padlock #2 (see below)
code = "" code = code + "9" code = code + "7" code = code + "1" OUTPUT(code)
Trace Table
Complete the following trace table to work out the 3-digit padlock code:
Line Number | code | OUTPUT | |
---|---|---|---|
1 |
Padlock
Input the combination on the padlock below and click on “Unlock?” to test your combination.
Padlock #3:
The following code will help you work out the combination (code) to open padlock #3 (see below)
code = "" code = code + "7" code = "4" + code code = code + "3" OUTPUT(code)
Trace Table
Complete the following trace table to work out the 3-digit padlock code:
Line Number | code | OUTPUT | |
---|---|---|---|
1 |
Padlock
Input the combination on the padlock below and click on “Unlock?” to test your combination.
Padlock #4:
The following code will help you work out the combination (code) to open padlock #4 (see below)
code = 61 IF code MOD 2 == 0 THEN code = code * 3 ELSE code = code * 2 END IF OUTPUT(code)
Trace Table
Complete the following trace table to work out the 3-digit padlock code:
Line Number | code | code MOD 2 == 0 ? | OUTPUT | |
---|---|---|---|---|
1 |
Padlock
Input the combination on the padlock below and click on “Unlock?” to test your combination.
Padlock #5:
The following code will help you work out the combination (code) to open padlock #5 (see below)
code = 24 IF code > 20 AND code <= 10 THEN code = code * 3 ELSE IF code > 20 OR code <= 10 THEN code = code * 10 ELSE code = code * 4 END IF OUTPUT(code)
Trace Table
Complete the following trace table to work out the 3-digit padlock code:
Line Number | code | code>20 ? | code<=10 ? | OUTPUT | |
---|---|---|---|---|---|
1 |
Padlock
Input the combination on the padlock below and click on “Unlock?” to test your combination.
Padlock #6:
The following code will help you work out the combination (code) to open padlock #6 (see below)
code = 245 WHILE code < 1000 code = code + 200 END WHILE code = code - 200 OUTPUT(code)
Trace Table
Complete the following trace table to work out the 3-digit padlock code:
Line Number | code | code<1000 ? | OUTPUT | |
---|---|---|---|---|
1 |
Padlock
Input the combination on the padlock below and click on “Unlock?” to test your combination.