-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13-2.p
217 lines (183 loc) · 5.2 KB
/
day13-2.p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
--- Part Two ---
Now, you need to pass through the firewall without being caught - easier said than done.
You can't control the speed of the packet, but you can delay it any number of picoseconds. For each picosecond you delay the packet before beginning your trip, all security scanners move one step. You're not in the firewall during this time; you don't enter layer 0 until you stop delaying the packet.
In the example above, if you delay 10 picoseconds (picoseconds 0 - 9), you won't get caught:
State after delaying:
0 1 2 3 4 5 6
[ ] [S] ... ... [ ] ... [ ]
[ ] [ ] [ ] [ ]
[S] [S] [S]
[ ] [ ]
Picosecond 10:
0 1 2 3 4 5 6
( ) [S] ... ... [ ] ... [ ]
[ ] [ ] [ ] [ ]
[S] [S] [S]
[ ] [ ]
0 1 2 3 4 5 6
( ) [ ] ... ... [ ] ... [ ]
[S] [S] [S] [S]
[ ] [ ] [ ]
[ ] [ ]
Picosecond 11:
0 1 2 3 4 5 6
[ ] ( ) ... ... [ ] ... [ ]
[S] [S] [S] [S]
[ ] [ ] [ ]
[ ] [ ]
0 1 2 3 4 5 6
[S] (S) ... ... [S] ... [S]
[ ] [ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ]
Picosecond 12:
0 1 2 3 4 5 6
[S] [S] (.) ... [S] ... [S]
[ ] [ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ]
0 1 2 3 4 5 6
[ ] [ ] (.) ... [ ] ... [ ]
[S] [S] [S] [S]
[ ] [ ] [ ]
[ ] [ ]
Picosecond 13:
0 1 2 3 4 5 6
[ ] [ ] ... (.) [ ] ... [ ]
[S] [S] [S] [S]
[ ] [ ] [ ]
[ ] [ ]
0 1 2 3 4 5 6
[ ] [S] ... (.) [ ] ... [ ]
[ ] [ ] [ ] [ ]
[S] [S] [S]
[ ] [ ]
Picosecond 14:
0 1 2 3 4 5 6
[ ] [S] ... ... ( ) ... [ ]
[ ] [ ] [ ] [ ]
[S] [S] [S]
[ ] [ ]
0 1 2 3 4 5 6
[ ] [ ] ... ... ( ) ... [ ]
[S] [S] [ ] [ ]
[ ] [ ] [ ]
[S] [S]
Picosecond 15:
0 1 2 3 4 5 6
[ ] [ ] ... ... [ ] (.) [ ]
[S] [S] [ ] [ ]
[ ] [ ] [ ]
[S] [S]
0 1 2 3 4 5 6
[S] [S] ... ... [ ] (.) [ ]
[ ] [ ] [ ] [ ]
[ ] [S] [S]
[ ] [ ]
Picosecond 16:
0 1 2 3 4 5 6
[S] [S] ... ... [ ] ... ( )
[ ] [ ] [ ] [ ]
[ ] [S] [S]
[ ] [ ]
0 1 2 3 4 5 6
[ ] [ ] ... ... [ ] ... ( )
[S] [S] [S] [S]
[ ] [ ] [ ]
[ ] [ ]
Because all smaller delays would get you caught, the fewest number of picoseconds you would need to delay to get through safely is 10.
What is the fewest number of picoseconds that you need to delay the packet to pass through the firewall without being caught?
*/
DEFINE VARIABLE cInput AS CHARACTER INITIAL "0: 5~n
1: 2~n
2: 3~n
4: 4~n
6: 6~n
8: 4~n
10: 8~n
12: 6~n
14: 6~n
16: 14~n
18: 6~n
20: 8~n
22: 8~n
24: 10~n
26: 8~n
28: 8~n
30: 10~n
32: 8~n
34: 12~n
36: 9~n
38: 20~n
40: 12~n
42: 12~n
44: 12~n
46: 12~n
48: 12~n
50: 12~n
52: 12~n
54: 12~n
56: 14~n
58: 14~n
60: 14~n
62: 20~n
64: 14~n
66: 14~n
70: 14~n
72: 14~n
74: 14~n
76: 14~n
78: 14~n
80: 12~n
90: 30~n
92: 17~n
94: 18" NO-UNDO.
/*
DEFINE VARIABLE cInput AS CHARACTER INITIAL "0: 3~n
1: 2~n
4: 4~n
6: 4" NO-UNDO.
*/
DEFINE TEMP-TABLE ttLayer
FIELD iLayer AS INTEGER
FIELD iDepth AS INTEGER
FIELD iScanPos AS INTEGER INITIAL 1
FIELD iDir AS INTEGER
INDEX ix IS PRIMARY iLayer.
DEFINE VARIABLE iPos AS INTEGER NO-UNDO.
DEFINE VARIABLE iLayer AS INTEGER NO-UNDO.
DEFINE VARIABLE cLayer AS CHARACTER NO-UNDO.
DEFINE VARIABLE iMax AS INTEGER INITIAL ? NO-UNDO.
DEFINE VARIABLE iSev AS INTEGER NO-UNDO.
DEFINE VARIABLE iDelay AS INTEGER NO-UNDO.
DEFINE VARIABLE lCaught AS LOGICAL INITIAL YES NO-UNDO.
DO iLayer = 1 TO NUM-ENTRIES(cInput, "~n"):
cLayer = ENTRY(iLayer, cInput, "~n").
CREATE ttLayer.
ASSIGN
ttLayer.iLayer = INTEGER(ENTRY(1, cLayer, ":"))
ttLayer.iDepth = INTEGER(ENTRY(2, cLayer, ":")).
IF iMax < ttLayer.iLayer OR iMax = ? THEN
iMax = ttLayer.iLayer.
END.
/* tells if a given scanner is at the top -> we are caught */
FUNCTION isAtTop RETURNS LOGICAL (piLayer AS INTEGER, piDepth AS INTEGER, piDelay AS INTEGER):
RETURN (piDelay + piLayer) MODULO (2 * (piDepth - 1)) = 1.
END FUNCTION.
ETIME(TRUE).
blkDelay:
DO WHILE lCaught:
lCaught = NO.
iDelay = iDelay + 1.
/* IF iDelay MOD 1000 = 0 THEN DISP iDelay. */
blkLayers:
FOR EACH ttLayer:
/*lCaught = isAtTop(ttLayer.iLayer, ttLayer.iDepth, iDelay).*/
lCaught = (iDelay + ttLayer.iLayer) MODULO (2 * (ttLayer.iDepth - 1)) = 1.
/* DISP iDelay ttLayer.iLayer lCaught. */
IF lCaught THEN NEXT blkDelay.
END.
END.
MESSAGE iDelay - 1 SKIP ETIME / 1000
VIEW-AS ALERT-BOX INFO BUTTONS OK.